-
Notifications
You must be signed in to change notification settings - Fork 0
/
liff.js
226 lines (193 loc) · 7.54 KB
/
liff.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
window.onload = function() {
const useNodeJS = false;
const defaultLiffId = "1653716067-3Glwdagk"; //change to your liff id in your line developer
let myLiffId = "";
myLiffId = defaultLiffId;
inisialisasiLiff(myLiffId);
}
function inisialisasiLiff(myLiffId) {
liff
.init({
liffId: myLiffId
})
.then(() => {
startupApp();
})
.catch((err) => {
console.log('error', err);
});
}
function startupApp(){
if (liff.isLoggedIn()) {
getUsername();
} else {
document.getElementById("event_list").style.display = "none";
document.getElementById("login").style.display = "block";
document.getElementById("navbar").style.visibility = "hidden";
cekBrowser();
}
}
function cekBrowser() {
if (liff.isInClient() == true) {
document.getElementById("infoclient").innerHTML = 'You are opening the app in the in-app browser of LINE.';
} else {
document.getElementById("infoclient").innerHTML = 'You are opening the app in an external browser.';
}
}
function externalBrowser(){
liff.openWindow({
url: 'https://eventonlineorder.herokuapp.com/',
external: true
});
}
function logout(){
liff.logout();
window.location.reload();
}
function loginUser(){
if (!liff.isLoggedIn()) {
liff.login();
}
}
function getUsername(){
liff.getProfile()
.then(profile => {
const name = profile.displayName;
document.getElementById("userbtn").innerHTML = name;
})
.catch((err) => {
console.log('error', err);
});
document.getElementById("event_list").style.display = "inline-block";
document.getElementById("login").style.display = "none";
document.getElementById("navbar").style.visibility = "visible";
}
function senddata(){
if (liff.isInClient() == false) {
alert('This button is unavailable as LIFF is currently being opened in an external browser.');
} else {
if (sessionStorage.list_event) {
list_event = JSON.parse(sessionStorage.getItem('list_event'));
if (list_event != null && list_event.length > 0) {
for (i in list_event) {
liff.sendMessages([{
'type': 'text',
'text': "Anda telah memesan tiket "+list_event[i].event+", pada tanggal "+list_event[i].date+" yang berlokasi di "+list_event[i].location+" dengan harga tiket "+list_event[i].price+""
}]).then(function() {
console.log('mengirim pesan');
}).catch(function(error) {
window.alert('Error sending message: ' + error);
});
}
}
}
}
}
function kirimPesan1(){
if (liff.isInClient() == false) {
console.log('cant send message to line bcause its run in externalBrowser');
} else {
var event = document.getElementById("event").innerHTML;
var date = document.getElementById("date").innerHTML;
var location = document.getElementById("location").innerHTML;
var price = document.getElementById("price").innerHTML;
liff.sendMessages([{
'type': 'text',
'text': "Anda telah memesan tiket "+event+", pada tanggal "+date+" yang berlokasi di "+location+" dengan harga tiket "+price+""
}]).then(function() {
console.log('mengirim pesan');
}).catch(function(error) {
window.alert('Error sending message: ' + error);
});
}
}
function kirimPesan2(){
if (liff.isInClient() == false) {
console.log('cant send message to line bcause its run in externalBrowser');
} else {
var event = document.getElementById("event2").innerHTML;
var date = document.getElementById("date2").innerHTML;
var location = document.getElementById("location2").innerHTML;
var price = document.getElementById("price2").innerHTML;
liff.sendMessages([{
'type': 'text',
'text': "Anda telah memesan tiket "+event+", pada tanggal "+date+" yang berlokasi di "+location+" dengan harga tiket "+price+""
}]).then(function() {
console.log('mengirim pesan');
}).catch(function(error) {
window.alert('Error sending message: ' + error);
});
}
}
function kirimPesan3(){
if (liff.isInClient() == false) {
console.log('cant send message to line bcause its run in externalBrowser');
} else {
var event = document.getElementById("event3").innerHTML;
var date = document.getElementById("date3").innerHTML;
var location = document.getElementById("location3").innerHTML;
var price = document.getElementById("price3").innerHTML;
liff.sendMessages([{
'type': 'text',
'text': "Anda telah memesan tiket "+event+", pada tanggal "+date+" yang berlokasi di "+location+" dengan harga tiket "+price+""
}]).then(function() {
console.log('mengirim pesan');
}).catch(function(error) {
window.alert('Error sending message: ' + error);
});
}
}
function kirimPesan4(){
if (liff.isInClient() == false) {
console.log('cant send message to line bcause its run in externalBrowser');
} else {
var event = document.getElementById("event4").innerHTML;
var date = document.getElementById("date4").innerHTML;
var location = document.getElementById("location4").innerHTML;
var price = document.getElementById("price4").innerHTML;
liff.sendMessages([{
'type': 'text',
'text': "Anda telah memesan tiket "+event+", pada tanggal "+date+" yang berlokasi di "+location+" dengan harga tiket "+price+""
}]).then(function() {
console.log('mengirim pesan');
}).catch(function(error) {
window.alert('Error sending message: ' + error);
});
}
}
function kirimPesan5(){
if (liff.isInClient() == false) {
console.log('cant send message to line bcause its run in externalBrowser');
} else {
var event = document.getElementById("event5").innerHTML;
var date = document.getElementById("date5").innerHTML;
var location = document.getElementById("location5").innerHTML;
var price = document.getElementById("price5").innerHTML;
liff.sendMessages([{
'type': 'text',
'text': "Anda telah memesan tiket "+event+", pada tanggal "+date+" yang berlokasi di "+location+" dengan harga tiket "+price+""
}]).then(function() {
console.log('mengirim pesan');
}).catch(function(error) {
window.alert('Error sending message: ' + error);
});
}
}
function kirimPesan6(){
if (liff.isInClient() == false) {
console.log('cant send message to line bcause its run in externalBrowser');
} else {
var event = document.getElementById("event6").innerHTML;
var date = document.getElementById("date6").innerHTML;
var location = document.getElementById("location6").innerHTML;
var price = document.getElementById("price6").innerHTML;
liff.sendMessages([{
'type': 'text',
'text': "Anda telah memesan tiket "+event+", pada tanggal "+date+" yang berlokasi di "+location+" dengan harga tiket "+price+""
}]).then(function() {
console.log('mengirim pesan');
}).catch(function(error) {
window.alert('Error sending message: ' + error);
});
}
}