Created
April 2, 2019 06:27
-
-
Save jirawatee/be0f0a51ae794fbb3680d49d1c110f34 to your computer and use it in GitHub Desktop.
Flex Message in LINE Messaging API
This file contains 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: "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