forked from Asuforce/liff-handson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (40 loc) · 1.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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()
})
}