Skip to content

Instantly share code, notes, and snippets.

@Asuforce
Created September 11, 2018 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Asuforce/cb40aa684f5b8a1610faffdadcbeb86d to your computer and use it in GitHub Desktop.
Save Asuforce/cb40aa684f5b8a1610faffdadcbeb86d to your computer and use it in GitHub Desktop.
LIFF-handson
window.onload = function (e) {
liff.init(function (data) {
initializeApp(data);
});
};
function initializeApp(data) {
liff.getProfile().then(function (profile) {
var name = profile.displayName;
document.getElementById('name').textContent = name;
}).catch(function (error) {
window.alert("Error getting profile: " + error);
})
document.getElementById('omakase').addEventListener('click', function () {
var foods = { rice: "302", sushi: "303", pizza: "304", noodle: "305", chicken: "306", cake: "307" };
var keys = Object.keys(foods);
var foodName = keys[Math.floor(Math.random() * keys.length)];
var text = "Today is " + foodName;
// Send text message to the talk screen where the LIFF application is opne.
liff.sendMessages([{
type: "text",
text: text
}]).then(function () {
window.alert("Message sent");
}).catch(function (error) {
window.alert("Error sending message: " + error);
})
// Send sticler
liff.sendMessages([{
type: "sticker",
packageId: "4",
stickerId: foods[foodName]
}]).then(function () {
window.alert("Message sent");
}).catch(function (error) {
window.alert("Error sending message: " + error);
})
// Close this window
liff.closeWindow()
})
}
# Register app
curl -X POST https://api.line.me/liff/v1/apps \
-H "Authorization: Bearer {channel access token}" \
-H "Content-Type: application/json" \
-d '{
"view":{
"type":"full",
"url":"https://example.com/myservice"
}
}'
# Response
{
"liffId":"{liff-id}"
}
# This is your LIFF url
line://app/{liff-id}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment