用戶訊息
本教學將說明如何透過 API 來取得一個機器人下的用戶訊息紀錄。
get
https://api.botbonnie.com
/v1/api/message/history
Get Message history

Response body

Name
Type
Description
res
Object
status
Number
HTTP Status

Res 物件

Name
Type
Description
messages
Array[Message]
用戶訊息資料,見 Message 物件
desc
Boolean
是否為降冪排序

Message 物件

Name
Type
Description
category
String
紀錄分類
type
String
紀錄類型
data
Object
訊息內容, Data 物件
timestamp
Integer
紀錄發生時間,13 碼 timestamp
operatorId
Number
回覆的操作者 ID,只有在後台即時訊息單獨回覆使用者時才會存在
senderId
Number
使用者 ID

Data 物件

Name
Type
Description
type
String
訊息類型
text
String
訊息文字
payload
String
訊息內容
quickReplies
Array[quickReply]
快速回復按鈕, QuickReply 物件
buttons
Array[button]
按鈕列表,Button 物件
link
String
url
cards
Array[card]
輪播卡片, Card 物件

QuickReply 物件

Name
Type
Description
title
String
按鈕文字
type
String
按鈕類型

Button 物件

Name
Type
Description
title
String
按鈕文字
type
String
按鈕類型

Card 物件

Name
Type
Description
title
String
標題
subtitle
String
描述文字
imageUrl
String
圖片網址
imageClickShortUrl
String
圖片點擊的縮址 url
imageClickOrignUrl
String
圖片點擊設定的 url
buttons
Array[button]
按鈕列表, Button 物件

範例 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

為使用者點擊按鈕時產生的事件紀錄
1
{
2
"category": "conversation",
3
"type": "click",
4
"timestamp": 1623046482461,
5
"senderId": "xxxxxxx",
6
"data": {
7
"type": "click",
8
"title": "被點擊的按鈕文字"
9
}
10
}
Copied!

text Type

使用者發送文字訊息時的事件紀錄
1
{
2
"category": "conversation",
3
"type": "text",
4
"timestamp": 1623907684961,
5
"senderId": "xxxxxxx",
6
"data": {
7
"type": "text",
8
"payload": "使用者輸入的文字"
9
}
10
}
Copied!

image/video/audio/file Type

使用者傳送圖片影片音訊檔案的類型的訊息時的事件紀錄
1
{
2
"category": "conversation",
3
"type": "audio/video/image/file",
4
"timestamp": 1623907089811,
5
"senderId": "xxxxxx",
6
"data": {
7
"type": "audio/video/image/file",
8
"payload": "xxxxxx" // content message id
9
},
10
"mid": "14239393100682"
11
}
Copied!

sticker Type

使用者傳送貼圖訊息時的事件紀錄
1
{
2
"category": "conversation",
3
"type": "sticker",
4
"timestamp": 1615965080838,
5
"senderId": "xxxxxx",
6
"data": {
7
"type": "sticker",
8
"payload": {
9
"packageId": "xxxx",
10
"stickerId": "xxxxxx"
11
}
12
}
13
}
Copied!

follow/unfollow Type

使用者追蹤官方帳號或封鎖時的事件紀錄
1
{
2
"category": "system",
3
"type": "follow/unfollow",
4
"timestamp": 1622626402433
5
}
Copied!

open_url Type

使用者開啟 url 時的事件紀錄
1
{
2
"category": "system",
3
"type": "open_url",
4
"timestamp": 1620206520431,
5
"data": {
6
"type": "open_url",
7
"link": "https://www.botbonnie.com"
8
}
9
}
Copied!

Reply/Push Type with data of text type

回覆文字訊息的紀錄
1
{
2
"category": "conversation",
3
"type": "reply/push",
4
"data": {
5
"quickReplies": [
6
{
7
"title": "快速回覆",
8
"type": "text",
9
"payload": "{\"fm\":\"module-xxxxxx\",\"to\":\"module-xxxxx\",\"id\":\"qr_0\",\"bid\":\"bot-xxxxxxx\",\"bv\":\"PROD\",\"ti\":\"快速回覆\"}"
10
}
11
],
12
"type": "text",
13
"text": "文字訊息內容"
14
},
15
"timestamp": 1622198735278,
16
"mid": "0_0_92d674b9-cdd0-4357-a8de-dd6b58d9b021",
17
"operatorId": "xxxxxxx"
18
}
Copied!

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

回覆影像/影片/音訊的訊息紀錄
1
{
2
"category": "conversation",
3
"type": "reply",
4
"data": {
5
"type": "video",
6
"videoUrl": "https://xxxxxxx", // exist in video
7
"imageUrl": "https://xxxxxxx", // exist in image
8
"audioUrl": "https://xxxxxxx" // exist in audio
9
},
10
"timestamp": 1623907690653,
11
"mid": "3_3_857803a6-de80-4def-a2e3-56134db79b1f"
12
}
Copied!

Reply/Push Type with data of imagemap type

回覆圖文訊息的紀錄
1
{
2
"category": "conversation",
3
"type": "reply",
4
"data": {
5
"baseUrl": "https://xxxxx", //image
6
"quickReplies": [],
7
"buttons": [
8
{
9
"area": {
10
"x": 0,
11
"width": 1040,
12
"y": 0,
13
"height": 1040
14
},
15
"type": "web_url",
16
"value": "https://xxxxxx",
17
"shortUrl": "https://xxxxxxxxxxx",
18
"originUrl": "https://xxxxxxxx"
19
}
20
],
21
"size": {
22
"width": 1040,
23
"height": 1040
24
},
25
"text": "圖文訊息",
26
"type": "imagemap"
27
},
28
"timestamp": 1623915747419,
29
"mid": "4_4_00a3323f-4a1e-4d3a-a8ec-593969091c4a"
30
}
Copied!
回覆輪播訊息的紀錄
1
{
2
"category": "conversation",
3
"type": "reply",
4
"data": {
5
"cards": [
6
{
7
"imageClickShortUrl": "https://xxxxxx",
8
"buttons": [],
9
"imageClickUrl": "https://xxxxxx",
10
"subtitle": "描述",
11
"imageUrl": "https://xxxxx",
12
"title": "卡片 1 標題",
13
"imageClickOriginUrl": "https://xxxxxx"
14
},
15
{
16
"imageClickShortUrl": "https://xxxxxx",
17
"buttons": [],
18
"imageClickUrl": "https://xxxxxx",
19
"subtitle": "描述",
20
"imageUrl": "https://xxxxx",
21
"title": "卡片 2 標題",
22
"imageClickOriginUrl": "https://xxxxxx"
23
}
24
],
25
"type": "gallery",
26
"imageStyle": "horizontal"
27
},
28
"timestamp": 1623907690652,
29
"mid": "2_2_857803a6-de80-4def-a2e3-56134db79b1f"
30
}
Copied!