-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.gs
67 lines (61 loc) · 2.06 KB
/
main.gs
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
function tmp() {
const USER_ID = "test";
let text = "かいけつ";
console.log(getReplyMsg(USER_ID, text));
//console.log(getStatus(USER_ID, col=16));
}
function testGetUserInfo() {
const URL = "https://api.line.me/v2/bot/profile/" + "Uab5d60c7a728c9116595ee282e027bf3"; // 末尾にユーザーIDを追加
const USER_PROFILE = JSON.parse(UrlFetchApp.fetch(URL,{
"headers": {
"Authorization": "Bearer " + ACCESS_TOKEN
}
}));
console.log(USER_PROFILE);
}
// イベントを受け取る
function doPost(e){
const EVENTS = JSON.parse(e.postData.contents).events;
for (const event of EVENTS){
execute(event);
}
}
// イベントを受け取ったら実行する
function execute(event){
const EVENT_TYPE = event.type;
const USER_ID = event.source.userId;
const REPLY_TOKEN = event.replyToken;
if(EVENT_TYPE === "follow"){
const ROW = SHEET.getLastRow()+1; // 書く行取得
SHEET.getRange(ROW,1).setValue(USER_ID); // A列目にユーザID記入
setStatus(USER_ID, 0); // ステータス0を設定
SHEET.getDataRange().removeDuplicates([1]); // ユーザIDの重複を削除
sendReplyMessage(REPLY_TOKEN, [getFlexMsg("RULE", RULE)]); // ルールを送信
}
else if(EVENT_TYPE === "message"){
if(event.message.type === "text"){
let text = event.message.text.trim(); // 先頭・末尾の空白削除
sendReplyMessage(REPLY_TOKEN, getReplyMsg(USER_ID, text));
}
}
else if(EVENT_TYPE === "postback"){
const N = parseInt(event.postback.data); // ヒントの番号
sendReplyMessage(REPLY_TOKEN, [getTextMsg(HINT_LIST[N-1])]);
}
}
// メッセージを送信
function sendReplyMessage(replyToken, messages){
const URL = "https://api.line.me/v2/bot/message/reply";
const RES = UrlFetchApp.fetch(URL, {
"headers": {
"Content-Type": "application/json; charset=UTF-8",
"Authorization": "Bearer " + ACCESS_TOKEN,
},
"method": "post",
"payload": JSON.stringify({
"replyToken": replyToken,
"messages": messages
}),
});
return RES;
}