var LINE_TOKEN = "トークン";
var LINE_URL = 'https://api.line.me/v2/bot/message/reply';
function doPost(e) {
// Jsonにパース
var json = JSON.parse(e.postData.contents);
// 応答用Tokenを取得
var replyToken = json.events[0].replyToken;
//返答用メッセージを作成
var reply = null;
// メッセージを取得
if(json.events[0].message.type == 'text'){
var userMessage = json.events[0].message.text;
}
if(userMessage == "指定した文字"){
var babbleMsgs = []; for(var i=0 ; i<3 ; i++){ var babbleMsg = { "type": "bubble", "hero": { "type": "image", "url": "画像のURL", "size": "full", "aspectRatio": "4:3", "aspectMode" : "cover", "backgroundColor" : "#f0f0f0" }, "body": { "type": "box", "layout": "vertical", "contents": [ { "type": "text", "text": "a", }, { "type": "text", "text": "b", } ] }, babbleMsgs.push(babbleMsg); } var reply = { "type" : "flex", "altText" : "this is a carousel message", "contents" : { "type" : "carousel", "contents" : babbleMsgs } }; someMessage(reply,replyToken);
}
}
}
function someMessage(text,place) {
var headers = {
'Content-Type': 'application/json; charset=UTF-8' ,
'Authorization': 'Bearer ' +LINE_TOKEN
};
var payload = JSON.stringify({ 'replyToken': place , 'messages': text }) var options = { 'headers' : headers , 'method' : 'post' , 'payload' : payload }; // メッセージを応答 UrlFetchApp.fetch(LINE_URL ,options)
}
回答1件
あなたの回答
tips
プレビュー