-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·141 lines (114 loc) · 4.67 KB
/
Copy pathmain.js
File metadata and controls
executable file
·141 lines (114 loc) · 4.67 KB
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
#!/usr/bin/env node
'use strict';
const request = require('request');
require('dotenv').config()
const fs = require('fs');
const apiRequest = require('./apiRequest');
if (process.argv[2] === 'init') {
if (!process.argv[3]) {
console.log('Bad argumentes. i.e. >liff init _LINE_ACCESS_TOKEN_) ');
return;
}
const LINE_ACCESS_TOKEN = process.argv[3];
fs.appendFile('.env', `LINE_ACCESS_TOKEN="${LINE_ACCESS_TOKEN}"`, (err) => {
if (err) { throw err; }
});
console.log(`write ${LINE_ACCESS_TOKEN} in .env file`);
return
}
if (!process.env.LINE_ACCESS_TOKEN || process.env.LINE_ACCESS_TOKEN == '') {
if (process.platform === "win32") {
console.log('Error: set environment variable following command. \n$ liff init {LINE_ACCESS_TOKEN}');
}
else {
console.log('Error: set environment variable following command. \n$ liff init {LINE_ACCESS_TOKEN}');
}
return;
}
if (process.argv[2] === 'list') {
apiRequest.listLiff().then((jsonResult) => {
jsonResult.apps.forEach((l, i) => {
console.log('---------------------------------------------------');
console.log(`No.${i + 1}`);
console.log(`[LIFF ID] ${l.liffId}`);
console.log(`[LIFF App URL] https://liff.line.me/${l.liffId}`);
console.log(`[Type] ${l.view.type}`);
console.log(`[Web URL] ${l.view.url}`);
})
}).catch((reason) => console.log(reason));;
}
else if (process.argv[2] === 'delete') {
if (!process.argv[3]) {
console.log('Bad argumentes. i.e. >liff delete 1555709429-rWDWpjjE) ');
return;
}
let liffId = process.argv[3];
apiRequest.deleteLiff(liffId).then((result) => { console.log(result) }).catch((reason) => { console.log(reason) });
}
else if (process.argv[2] === 'deleteAll') {
apiRequest.listLiff().then((jsonResult) => {
jsonResult.apps.forEach((l, i) => {
apiRequest.deleteLiff(l.liffId).then((result) => { console.log(result) }).catch((reason) => { console.log(reason) });
})
}).catch((reason) => console.log(reason));
}
else if (process.argv[2] === 'add') {
if (process.argv.length != 5) {
console.log('Bad argumentes. i.e. >liff add https://developers.line.me/en/docs/liff/overview/ tall');
return;
}
let app_url = process.argv[3];
let type = process.argv[4];
if (type !== "full" && type !== "tall" && type !== "compact") {
console.log('Supported types are full, tall or compact.');
return;
}
let view = { "view": { "type": type, "url": app_url } };
apiRequest.addLiff(view).then((result) => { console.log(result) }).catch((reason) => { console.log(reason) });
}
else if (process.argv[2] === 'update') {
if (process.argv.length != 6) {
console.log('Bad argumentes. i.e. >liff update 1555709429-7aZa9EEq https://developers.line.me/en/docs/liff/overview/ tall');
return;
}
let liffId = process.argv[3];
let app_url = process.argv[4];
let type = process.argv[5];
if (type !== "full" && type !== "tall" && type !== "compact") {
console.log('Supported types are full, tall or compact.');
return;
}
let view = { "type": type, "url": app_url };
apiRequest.updateLiff(liffId, view).then((result) => { console.log(result) }).catch((reason) => { console.log(reason) });
}
else if (process.argv[2] === 'send') {
if (process.argv.length != 5) {
console.log('Bad argumentes. i.e. >liff send 1555709429-7aZa9EEq Ue52d11061890315xxxxxxxxxxx');
return;
}
let liffId = process.argv[3];
let userId = process.argv[4];
apiRequest.sendLiff(liffId, userId).then((result) => { console.log(result) }).catch((reason) => { console.log(reason) });
}
else {
let help = `welcome to liff tool.
[usage]
init: set liff commands.
list: list all registered liff applications.
add <url> <type:full|tall|compact>: create new liff application.
update <liffId> <url> <type:full|tall|compact>: update the liff application.
delete <liffId>: delete specified liff
deleteAll: delete all liff applications.
send: send liff application URL to sepecified LINE user.
[example]
liff init {LINE_ACCESS_TOKEN}
liff list
liff add https://developers.line.me/en/docs/liff/overview/ tall
liff add https://developers.line.me/en/docs/liff/overview/ compact
liff update 1555709429-5zJQmooA https://developers.line.me/en/docs/liff/overview/ tall
liff delete 1555709429-5zJQmooA
liff deleteAll
liff send 1555709429-5zJQmooA Ue52d11061890315xxxxxxxxxxx
`;
console.log(help);
}