行動應用企劃人員養成班
發送回覆訊息
- 參考:https://developers.line.biz/en/reference/messaging-api/#send-reply-message
- 格式化程式碼:shift + alt + F
- 架構:
/*============================================
Line Bot 回覆
============================================*/
function lineReplyMessage(replyToken, replyMessage) {
//-----------------------------------回傳訊息給line 並傳送給使用者
let url = 'https://api.line.me/v2/bot/message/reply';
try {
UrlFetchApp.fetch(url, {
'headers': {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN,
},
'method': 'post',
'payload': JSON.stringify({
'replyToken': replyToken,
'messages': replyMessage
}),
});
} catch (e) {
//---------------------------------- 記錄Line Bot 回覆 錯誤訊息
let formData = {
sn: '',
timestamp: '',
type: 'Line Bot 回覆 錯誤訊息',
code: e
}
insert_sheet_record(formData);
//---------------------------------- 記錄Line Bot 回覆 錯誤訊息 end
}
//---------------------------------------回傳訊息給line 並傳送給使用者 end
}
- 請比對 replayMessage
陣列 包 物件(最多5組) [ { "type":"text", "text":"Hello, user" }, { "type":"text", "text":"May I help you?" } ]
- 訊息類型
- 文字
- 圖片 { "type": "image", "originalContentUrl": "https://example.com/original.jpg",//實際圖片網址 "previewImageUrl": "https://example.com/preview.jpg"//縮圖網址 } link to https://developers.line.biz/en/reference/messaging-api/#image-message \
- flex [ { "type": "flex", "altText": "This is a Flex Message", "contents": { "type": "bubble", "body": { "type": "box", "layout": "horizontal", "contents": [ { "type": "text", "text": "Hello," }, { "type": "text", "text": "World!" } ] } } } ] link to https://developers.line.biz/en/docs/messaging-api/using-flex-messages/#sending-messages-with-the-messaging-api \
- flex樣版網站
- 從Showcase,找一個輪播樣版(Local Search)
- uri { "type": "button", "style": "primary", "color": "#905c44", "margin": "xxl", "action": { "type": "uri", "label": "action", "uri": "http://linecorp.com/" } }
- message { "type": "button", "style": "primary", "color": "#905c44", "margin": "xxl", "action": { "type": "message", "label": "action", "text": "hello" } }