Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active November 21, 2019 10:58
Show Gist options
  • Select an option

  • Save jirawatee/b009174c4066f1f91088d883fb95f633 to your computer and use it in GitHub Desktop.

Select an option

Save jirawatee/b009174c4066f1f91088d883fb95f633 to your computer and use it in GitHub Desktop.
Confirm template message in LINE Messaging API
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 <CHANNEL-ACCESS-TOKEN>"
};
exports.AdvanceMessage = functions.https.onRequest((req, res) => {
return request({
method: "POST",
uri: `${LINE_MESSAGING_API}/push`,
headers: LINE_HEADER,
body: JSON.stringify({
to: "<USER-ID>",
messages: [
{
type: "template",
altText: "This is a confirm template",
template: {
type: "confirm",
text: "Are you sure?",
actions: [
{
type: "message",
label: "Yes",
text: "yes"
},
{
type: "message",
label: "No",
text: "no"
}
]
}
}
]
})
}).then(() => {
return res.status(200).send("Done");
}).catch(error => {
return Promise.reject(error);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment