-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathliff.js
78 lines (70 loc) · 2.95 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
window.onload = function (e) {
// init で初期化。基本情報を取得。
// https://developers.line.me/ja/reference/liff/#initialize-liff-app
liff.init(function (data) {
getProfile();
initializeApp(data);
});
// LIFF アプリを閉じる
// https://developers.line.me/ja/reference/liff/#liffclosewindow()
document.getElementById('closewindowbutton').addEventListener('click', function () {
liff.closeWindow();
});
// ウィンドウを開く
// https://developers.line.me/ja/reference/liff/#liffopenwindow()
document.getElementById('openwindowbutton').addEventListener('click', function () {
liff.openWindow({
url: 'https://line.me'
});
});
document.getElementById('openwindowexternalbutton').addEventListener('click', function () {
liff.openWindow({
url: 'https://line.me',
external: true
});
});
// メッセージの送信
document.getElementById('sendmessagebutton').addEventListener('click', function () {
// https://developers.line.me/ja/reference/liff/#liffsendmessages()
liff.sendMessages([{
type: 'text',
text: "テキストメッセージの送信"
}, {
type: 'sticker',
packageId: '2',
stickerId: '144'
}]).then(function () {
window.alert("送信完了");
}).catch(function (error) {
window.alert("Error sending message: " + error);
});
});
};
// プロファイルの取得と表示
function getProfile(){
// https://developers.line.me/ja/reference/liff/#liffgetprofile()
liff.getProfile().then(function (profile) {
document.getElementById('useridprofilefield').textContent = profile.userId;
document.getElementById('displaynamefield').textContent = profile.displayName;
var profilePictureDiv = document.getElementById('profilepicturediv');
if (profilePictureDiv.firstElementChild) {
profilePictureDiv.removeChild(profilePictureDiv.firstElementChild);
}
var img = document.createElement('img');
img.src = profile.pictureUrl;
img.alt = "Profile Picture";
img.width = 200;
profilePictureDiv.appendChild(img);
document.getElementById('statusmessagefield').textContent = profile.statusMessage;
}).catch(function (error) {
window.alert("Error getting profile: " + error);
});
}
function initializeApp(data) {
document.getElementById('languagefield').textContent = data.language;
document.getElementById('viewtypefield').textContent = data.context.viewType;
document.getElementById('useridfield').textContent = data.context.userId;
document.getElementById('utouidfield').textContent = data.context.utouId;
document.getElementById('roomidfield').textContent = data.context.roomId;
document.getElementById('groupidfield').textContent = data.context.groupId;
}