Last active
November 13, 2019 05:32
-
-
Save PamornT/69e225967daff142add1a648d647482e to your computer and use it in GitHub Desktop.
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
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