跳至主要内容

REFERENCE

開發者參考

認證、API、SDK、Flow Agent 處理節點與參數取值的完整參考。

Action Object - Message

Message Action 在聊天介面中替使用者發送指定的文字訊息。

  1. 基本用法​

    Message Action 讓使用者點擊按鈕時自動發送文字訊息給機器人,如同使用者手動輸入該文字一樣。支援純文字內容和 payload 資料傳遞。

  2. Action 結構​

    JSON 格式​

    {
    "type": "MESSAGE",
    "text": "我要預約餐廳",
    "payload": {
    "action": "reservation"
    }
    }

    屬性說明​

    type(必填)​

    動作類型,固定為 "MESSAGE"。

    text(必填)​

    點擊後要發送的文字訊息內容。

    payload(選填)​

    附加資料內容,可傳遞結構化資料給後續 processor 使用。

  3. 使用範例​

    要在 Push Message 中發送帶有 Message Action 的按鈕,請按照以下步驟操作:

    1. 在 Template 欄位的下拉選單中選擇 Expression。
    2. 在 Editor 編輯器中輸入以下 JavaScript 程式碼。

    基本客服選單​

    (() => {
    return {
    type: 'BUTTON',
    title: '客服服務',
    text: '請選擇您需要的服務:',
    buttons: [
    {
    label: '訂單查詢',
    action: {
    type: 'MESSAGE',
    text: '我要查詢訂單',
    },
    },
    {
    label: '我要預約',
    action: {
    type: 'MESSAGE',
    text: '我要預約餐廳',
    },
    },
    ],
    };
    })()

    搭配 payload 資料​

    (() => {
    return {
    type: 'BUTTON',
    title: '產品諮詢',
    text: '請選擇您想了解的產品:',
    buttons: [
    {
    label: '查看規格',
    action: {
    type: 'MESSAGE',
    text: '請提供詳細規格',
    payload: {
    product_id: 'laptop_001',
    inquiry_type: 'specifications',
    },
    },
    },
    {
    label: '價格諮詢',
    action: {
    type: 'MESSAGE',
    text: '請提供價格資訊',
    payload: {
    product_id: 'laptop_001',
    inquiry_type: 'pricing',
    },
    },
    },
    ],
    };
    })()

準備好開始了嗎?

想知道 Asgard 怎麼用在你的團隊?跟我們聊聊。

聯絡我們