function doPost(e) {
//認證身份,重新輸入line@ channel_access_token
var CHANNEL_ACCESS_TOKEN = 'EMR3Bx5HkgU8Q9SJ+n7LH39vl7M7Ry7H1xlNmmcasn4SSAB9MtiGB4qGj0F5IAWcU/J1tZdMrsqF623je5mg8ProZ1JZtUBKQLQaAOybUXvAV9Q1RKNrhICwgbcqXVDcVlFfz/dxgQOGrylhryIBPwdB04t89/1O/w1cDnyilFU=';
var msg= JSON.parse(e.postData.contents);
//除錯用
Logger.log(msg);
console.log(msg);
//從接收到的訊息中取出 replyToken 和發送的訊息文字
var replyToken = msg.events[0].replyToken;
var userMessage = msg.events[0].message.text;
if (typeof replyToken === 'undefined') {
return;
};
//定義回傳訊息
var reply_message=[{
'type': 'text',
'text': '我是中編Bot'
}];
//回傳訊息給line 並傳送給使用者
var url = 'https://api.line.me/v2/bot/message/reply';
UrlFetchApp.fetch(url, {
'headers': {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN,
},
'method': 'post',
'payload': JSON.stringify({
'replyToken': replyToken,
'messages': reply_message,
}),
});
}