訊息的傳送方式都是向 API 提交 POST 要求,同時在網址查詢字串上附加<ACCESS_TOKEN>
HTTP 要求的主體會以 JSON 格式傳送,並須具有兩個屬性:
{
"recipient":{
"id":"<SENDER_ID>"
},
"message":{
"type":"text",
"text":"你都知道了,柚子要失業了,嗚"
}
}
get data~~
or
錯誤訊息
節點
資料型態
說明
message.type
字串
內容為 "text" 表示為文字種類訊息
message.text
字串
顯示給使用者的文字內容
{
"recipient":{
"id":"<SENDER_ID>"
},
"message":{
"type":"sticker",
"sticker_group":"<STICKER_GROUP>",
"sticker_id":"<STICKER_ID>"
}
}
get data~~
or
錯誤訊息
節點
資料型態
說明
message.type
字串
內容為 "sticker" 表示為貼圖種類訊息
{
"recipient":{
"id":"<SENDER_ID>"
},
"message":{
"type":"img",
"id":"<IMAGE_ID>",
"ext":"<IMAGE_EXT>",
"width":"<IMAGE_WIDTH>",
"height":"<IMAGE_HEIGHT>"
}
}
get data~~
or
錯誤訊息
節點
資料型態
說明
message.type
字串
內容為 "img" 表示為圖片種類訊息
{
"recipient":{
"id":"<SENDER_ID>"
},
"message":{
"type":"botStart",
"start_img":"<IMAGE_ID>.<IMAGE_EXT>",
"init":{
"image":"<IMAGE_ID>.<IMAGE_EXT>",
"hp":{
"max":100,
"current":0,
"color":"#000000"
},
"text":{
"message":"柚子已經在等你了!遇到不會的問題可以試著去廣場發問求救喔!準備好就請按下開始吧!",
"color":"#7A929B"
},
"button":{
"style":2,
"setting":[
{
"disabled":false,
"order":1,
"text":"開始打柚子(誤) 開始答題!",
"command":"/news fight"
}
]
}
}
}
}
<EVENT_ID>
or
錯誤訊息
節點
資料型態
說明
message.type
字串
內容為 "botStart" 表示為特殊介面種類訊息
message.start_img
字串
圖片的 id 與副檔名,此圖片會出現在使用者一般的聊天訊息框中作為啟動特殊介面的入口
message.init.image
字串
圖片的 id 與副檔名,此圖片會出現在使用者特殊介面中
message.init.hp.max
數字
特殊介面的血條的最大值
message.init.hp.current
數字
特殊介面的血條的當前值
message.init.hp.color
字串
特殊介面的血條的顏色 格式為 #FFFFFF
message.init.text.message
字串
特殊介面的顯示文字
message.init.text.color
字串
特殊介面的顯示文字顏色 格式為 #FFFFFF
message.init.button.style
數字
特殊介面的按鈕型態,1為橫式 ,2為直式
message.init.button.setting.0.disable
布林值
特殊介面的按鈕鎖定,true為鎖定按鈕,false為不鎖定按鈕
message.init.button.setting.0.order
數字
特殊介面的按鈕排序,數字越小越前面
message.init.button.setting.0.text
字串
特殊介面的按鈕文字
message.init.button.setting.0.command
字串
特殊介面的按鈕點擊指令
{
"recipient":{
"id":"<SENDER_ID>"
},
"message":{
"type":"botEvent",
"event_id":<EVENT_ID>,
"image":"<IMAGE_ID>.<IMAGE_EXT>",
"hp":{
"max":100,
"current":100,
"color":"#EB698B"
},
"text":{
"message":"Q1. 遊戲 [ 隻狼 ] 身上有十文錢,挑戰長手百足麒,死了十次,還剩多少錢?",
"color":"#7A929B"
},
"button":{
"style":2,
"setting":[
{
"disabled":false,
"order":1,
"text":"壹文錢",
"command":"/news answer 1 1"
},
{
"disabled":false,
"order":2,
"text":"兩文錢",
"command":"/news answer 1 2"
},
{
"disabled":false,
"order":3,
"text":"五文錢",
"command":"/news answer 1 3"
},
{
"disabled":false,
"order":5,
"text":"十文錢",
"command":"/news answer 1 4"
}
]
}
}
}
or
隱藏特殊介面物件
{
"recipient":{
"id":"<SENDER_ID>"
},
"message":{
"type":"botEvent",
"event_id":<EVENT_ID>,
"image":{
"hidden":true
},
"hp":{
"hidden":true
},
"text":{
"hidden":true
},
"button":{
"hidden":true
}
}
}
event adding
or
錯誤訊息
節點
資料型態
說明
message.type
字串
內容為 "botEvent" 表示為特殊介面事件種類訊息
message.image
字串
圖片的 id 與副檔名,此圖片會出現在使用者特殊介面中
message.hp.max
數字
特殊介面的血條的最大值
message.hp.current
數字
特殊介面的血條的當前值
message.hp.color
字串
特殊介面的血條的顏色 格式為 #FFFFFF
message.text.message
字串
特殊介面的顯示文字
message.text.color
字串
特殊介面的顯示文字顏色 格式為 #FFFFFF
message.button.style
數字
特殊介面的按鈕型態,1為橫式 ,2為直式
message.button.setting.0.disable
布林值
特殊介面的按鈕鎖定,true為鎖定按鈕,false為不鎖定按鈕
message.button.setting.0.order
數字
特殊介面的按鈕排序,數字越小越前面
message.button.setting.0.text
字串
特殊介面的按鈕文字
message.button.setting.0.command
字串
特殊介面的按鈕點擊指令
message.image.hidden
布林值
true 為隱藏圖片物件
message.hp.hidden
布林值
true 為隱藏血條物件
message.text.hidden
布林值
true 為隱藏文字物件
message.button.hidden
布林值
true 為隱藏按鈕物件
curl -H "Content-Type: application/json" \
-d '<主體內容>' \
https://us-central1-hahamut-8888.cloudfunctions.net/messagePush?access_token=<ACCESS_TOKEN>
$data = '<主體內容>';
$url = 'https://us-central1-hahamut-8888.cloudfunctions.net/messagePush?access_token='.<ACCESS_TOKEN>;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$rdata = curl_exec($ch);
curl_close($ch);