Skip to content

Instantly share code, notes, and snippets.

@yiidtw
Created June 16, 2021 00:25
Show Gist options
  • Save yiidtw/db1548cb2b9530cee6aef215dd20423d to your computer and use it in GitHub Desktop.
Save yiidtw/db1548cb2b9530cee6aef215dd20423d to your computer and use it in GitHub Desktop.
Google Script for random quote Line Bot
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],
}],
}),
});
}
@yiidtw
Copy link
Author

yiidtw commented Jun 16, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment