Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active November 21, 2019 10:57
Show Gist options
  • Save jirawatee/49d33653f51841f2fa84469b546da4bd to your computer and use it in GitHub Desktop.
Save jirawatee/49d33653f51841f2fa84469b546da4bd to your computer and use it in GitHub Desktop.
Carousel 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 carousel template",
template: {
type: "carousel",
imageAspectRatio: "rectangle",
imageSize: "cover",
columns: [
{
thumbnailImageUrl: "https://www.koreaexpose.com/wp-content/uploads/2018/01/LINE-Friends-characters-min.jpg",
imageBackgroundColor: "#FFFFFF",
title: "this is menu",
text: "description",
defaultAction: {
type: "uri",
label: "LINE",
uri: "https://developers.line.biz"
},
actions: [
{
type: "postback",
label: "Buy",
data: "action=buy&itemid=111"
}
]
},
{
thumbnailImageUrl: "https://www.nylon.com.sg/wp-content/uploads/2017/07/LINE-Friends.jpg",
imageBackgroundColor: "#000000",
title: "this is menu",
text: "description",
defaultAction: {
type: "uri",
label: "LINE",
uri: "https://developers.line.biz"
},
actions: [
{
type: "uri",
label: "LINE",
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