用戶訊息

本教學將說明如何透過 API 來取得一個機器人下的用戶訊息紀錄。

Get Message history

GET https://api.botbonnie.com/v1/api/message/history

Query Parameters

Headers

{
    "res": {
        "messages": [
            {
                "category": "conversation",
                "type": "reply",
                "data": {
                    "quickReplies": [],
                    "text": "文字內容",
                    "type": "text"
                },
                "timestamp": 1623918332624,
                "mid": "0_29612160-1bd1-4358-aee7-9a0ff605cae6"
            },
            {
                "category": "conversation",
                "type": "click",
                "timestamp": 1623918331847,
                "senderId": "xxxxxx",
                "data": {
                    "type": "click",
                    "title": "快速回覆"
                }
            }
        ],
        "desc": true
    },
    "status": 200
}

Response body

Res 物件

Message 物件

Data 物件

QuickReply 物件

Button 物件

Card 物件

範例 Message object 訊息

使用者行為的紀錄類別包含 click, text, image, video, audio, file, sticker, follow, unfollow, open_url

reply 則為機器人回覆紀錄,push 為推播紀錄

reply/push 會包含的訊息種類有 text, image, video, audio, gallery (輪播訊息), imagemap (圖文訊息)

click Type

為使用者點擊按鈕時產生的事件紀錄

{
    "category": "conversation",
    "type": "click",
    "timestamp": 1623046482461,
    "senderId": "xxxxxxx",
    "data": {
        "type": "click",
        "title": "被點擊的按鈕文字"
    }
}

text Type

使用者發送文字訊息時的事件紀錄

{
    "category": "conversation",
    "type": "text",
    "timestamp": 1623907684961,
    "senderId": "xxxxxxx",
    "data": {
        "type": "text",
        "payload": "使用者輸入的文字"
    }
}

image/video/audio/file Type

使用者傳送圖片影片音訊檔案的類型的訊息時的事件紀錄

{
    "category": "conversation",
    "type": "audio/video/image/file",
    "timestamp": 1623907089811,
    "senderId": "xxxxxx",
    "data": {
        "type": "audio/video/image/file",
        "payload": "xxxxxx" // content message id
    },
    "mid": "14239393100682"
}

sticker Type

使用者傳送貼圖訊息時的事件紀錄

{
    "category": "conversation",
    "type": "sticker",
    "timestamp": 1615965080838,
    "senderId": "xxxxxx",
    "data": {
        "type": "sticker",
        "payload": {
            "packageId": "xxxx",
            "stickerId": "xxxxxx"
        }
    }
}

follow/unfollow Type

使用者追蹤官方帳號或封鎖時的事件紀錄

{
    "category": "system",
    "type": "follow/unfollow",
    "timestamp": 1622626402433
}

open_url Type

使用者開啟 url 時的事件紀錄

{
    "category": "system",
    "type": "open_url",
    "timestamp": 1620206520431,
    "data": {
        "type": "open_url",
        "link": "https://www.botbonnie.com"
    }
}

Reply/Push Type with data of text type

回覆文字訊息的紀錄

{
    "category": "conversation",
    "type": "reply/push",
    "data": {
        "quickReplies": [
            {
                "title": "快速回覆",
                "type": "text",
                "payload": "{\"fm\":\"module-xxxxxx\",\"to\":\"module-xxxxx\",\"id\":\"qr_0\",\"bid\":\"bot-xxxxxxx\",\"bv\":\"PROD\",\"ti\":\"快速回覆\"}"
            }
        ],
        "type": "text",
        "text": "文字訊息內容"
    },
    "timestamp": 1622198735278,
    "mid": "0_0_92d674b9-cdd0-4357-a8de-dd6b58d9b021",
    "operatorId": "xxxxxxx"
}

Reply/Push Type with data of image/video/audio type

回覆影像/影片/音訊的訊息紀錄

{
    "category": "conversation",
    "type": "reply",
    "data": {
        "type": "video",
        "videoUrl": "https://xxxxxxx", // exist in video
        "imageUrl": "https://xxxxxxx", // exist in image
        "audioUrl": "https://xxxxxxx"  // exist in audio
    },
    "timestamp": 1623907690653,
    "mid": "3_3_857803a6-de80-4def-a2e3-56134db79b1f"
}

Reply/Push Type with data of imagemap type

回覆圖文訊息的紀錄

{
    "category": "conversation",
    "type": "reply",
    "data": {
        "baseUrl": "https://xxxxx", //image
        "quickReplies": [],
        "buttons": [
            {
                "area": {
                    "x": 0,
                    "width": 1040,
                    "y": 0,
                    "height": 1040
                },
                "type": "web_url",
                "value": "https://xxxxxx",
                "shortUrl": "https://xxxxxxxxxxx",
                "originUrl": "https://xxxxxxxx"
            }
        ],
        "size": {
            "width": 1040,
            "height": 1040
        },
        "text": "圖文訊息",
        "type": "imagemap"
    },
    "timestamp": 1623915747419,
    "mid": "4_4_00a3323f-4a1e-4d3a-a8ec-593969091c4a"
}

回覆輪播訊息的紀錄

{
    "category": "conversation",
    "type": "reply",
    "data": {
        "cards": [
            {
                "imageClickShortUrl": "https://xxxxxx",
                "buttons": [],
                "imageClickUrl": "https://xxxxxx",
                "subtitle": "描述",
                "imageUrl": "https://xxxxx",
                "title": "卡片 1 標題",
                "imageClickOriginUrl": "https://xxxxxx"
            },
            {
                "imageClickShortUrl": "https://xxxxxx",
                "buttons": [],
                "imageClickUrl": "https://xxxxxx",
                "subtitle": "描述",
                "imageUrl": "https://xxxxx",
                "title": "卡片 2 標題",
                "imageClickOriginUrl": "https://xxxxxx"
            }
        ],
        "type": "gallery",
        "imageStyle": "horizontal"
    },
    "timestamp": 1623907690652,
    "mid": "2_2_857803a6-de80-4def-a2e3-56134db79b1f"
}

Last updated