Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active November 21, 2019 10:58
Show Gist options
  • Save jirawatee/bf04471f4270ca2e79365c9514c7a73e to your computer and use it in GitHub Desktop.
Save jirawatee/bf04471f4270ca2e79365c9514c7a73e to your computer and use it in GitHub Desktop.
Image 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 an image carousel template",
template: {
type: "image_carousel",
columns: [
{
imageUrl: "https://vignette.wikia.nocookie.net/line/images/b/bb/2015-brown.png",
action: {
type: "message",
label: "Brown",
text: "Brown was selected"
}
},
{
imageUrl: "https://vignette.wikia.nocookie.net/line/images/1/10/2015-cony.png",
action: {
type: "uri",
label: "Cony",
uri: "https://developers.line.biz"
}
}
]
}
}
]
})
}).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