Created
June 16, 2021 00:25
-
-
Save yiidtw/db1548cb2b9530cee6aef215dd20423d to your computer and use it in GitHub Desktop.
Google Script for random quote Line Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doPost(e) { | |
var CHANNEL_ACCESS_TOKEN = '<your channel access token>'; | |
var msg= JSON.parse(e.postData.contents); | |
console.log(msg); | |
var replyToken = msg.events[0].replyToken; | |
var userMessage = msg.events[0].message.text; | |
if (typeof replyToken === 'undefined') { | |
return; | |
} | |
var quotes = ['quote1', | |
'quote2', | |
'quote3']; | |
var rdn = Math.floor(Math.random() * quotes.length); | |
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': [{ | |
'type': 'text', | |
'text': quotes[rdn], | |
}], | |
}), | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref: https://www.oxxostudio.tw/articles/201804/line-bot-apps-script.html