Last active
March 21, 2019 08:06
-
-
Save jirawatee/bb03d4a79f14ee1bc7265284f9593207 to your computer and use it in GitHub Desktop.
Buttions template message in LINE Messaging API
This file contains hidden or 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 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 buttons template", | |
template: { | |
type: "buttons", | |
thumbnailImageUrl: "https://www.nylon.com.sg/wp-content/uploads/2017/07/LINE-Friends.jpg", | |
imageAspectRatio: "rectangle", | |
imageSize: "cover", | |
imageBackgroundColor: "#FFFFFF", | |
title: "Menu", | |
text: "Please select", | |
defaultAction: { | |
type: "uri", | |
label: "View detail", | |
uri: "https://developers.line.biz" | |
}, | |
actions: [ | |
{ | |
type: "postback", | |
label: "Buy", | |
data: "action=buy&itemid=123" | |
}, | |
{ | |
type: "uri", | |
label: "View detail", | |
uri: "https://line.me" | |
} | |
] | |
} | |
} | |
] | |
}) | |
}).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