Skip to content

Instantly share code, notes, and snippets.

@PamornT
Last active November 13, 2019 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PamornT/69e225967daff142add1a648d647482e to your computer and use it in GitHub Desktop.
Save PamornT/69e225967daff142add1a648d647482e to your computer and use it in GitHub Desktop.
const REGION = 'asia-northeast1';
const functions = require('firebase-functions');
const request = require('request-promise');
const LINE_MESSAGING_API = 'https://api.line.me/v2/bot/message';
const LINE_HEADER = {
'Content-Type': 'application/json',
'Authorization': `Bearer xxxxx`
};
exports.yyyyyLineBot = functions.region(REGION).https.onRequest((req, res) => {
if ( typeof(req.body.events) == 'undefined') {
res.status(200).send("Hello!! Cloud Functions for Firebase!!!").end();
}
console.log('Request Body', JSON.stringify(req.body) );
reply(req.body);
console.log('Echo bot Complete');
});
const reply = (bodyResponse) => {
return request({
method: `POST`,
uri: `${LINE_MESSAGING_API}/reply`,
headers: LINE_HEADER,
body: JSON.stringify({
replyToken: bodyResponse.events[0].replyToken,
messages: [
{
type: `text`,
text: bodyResponse.events[0].message.text
}
]
})
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment