Created
September 11, 2018 14:11
-
-
Save Asuforce/cb40aa684f5b8a1610faffdadcbeb86d to your computer and use it in GitHub Desktop.
LIFF-handson
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
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() | |
}) | |
} |
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
# 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