Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Created April 2, 2019 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jirawatee/be0f0a51ae794fbb3680d49d1c110f34 to your computer and use it in GitHub Desktop.
Save jirawatee/be0f0a51ae794fbb3680d49d1c110f34 to your computer and use it in GitHub Desktop.
Flex 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: "flex",
altText: "Flex Message",
contents: {
type: "bubble",
direction: "ltr",
hero: {
type: "image",
url: "https://i1.wp.com/mobileocta.com/wp-content/uploads/2019/04/index_package_pic1.jpg",
size: "full",
aspectRatio: "1.51:1",
aspectMode: "fit"
}
}
}
]
})
}).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