質問編集履歴
2
簡易化
title
CHANGED
File without changes
|
body
CHANGED
@@ -24,267 +24,8 @@
|
|
24
24
|
const clear = /(キャンセル|やめる)/;
|
25
25
|
const followExp = /(follow|unfollow)/;
|
26
26
|
|
27
|
-
//キャッシュをすべて削除する。
|
28
|
-
if (userMessage.test(clear)) {
|
29
|
-
replayChatprivate(replayToken, "キャンセルしました。");
|
30
|
-
cleardata(userID);
|
31
|
-
}
|
32
|
-
|
33
|
-
if (state === null) {
|
34
|
-
if (userMessage === '予定の追加') {
|
35
|
-
const message = '開始日付を教えてくださ';
|
36
|
-
replayChatprivate(replayToken, message);
|
37
|
-
resisterPrivate(userID, 0);
|
38
|
-
} else if (userMessage === 'グループに投稿') {
|
39
|
-
end = isValid(userID, replayToken);
|
40
|
-
} else {
|
41
|
-
replayChatprivate(replayToken, '予定の');
|
42
|
-
}
|
43
|
-
} else {
|
44
|
-
if (noExp.test(userMessage)) {
|
45
|
-
deletecache(userID);
|
46
|
-
replayChatprivate(replayToken, 'キャンセルしました');
|
47
|
-
}
|
48
|
-
|
49
|
-
switch (state) {
|
50
|
-
// 予定の日付
|
51
|
-
case '0':
|
52
|
-
const matched = userMessage.match(dateExp);
|
53
|
-
if (matched != null) {
|
54
|
-
const message = '次に開始時刻は'
|
55
|
-
replayChatprivate(replayToken, message);
|
56
|
-
const a = matched[1] - 1;
|
57
|
-
const date = a + "," + matched[2];
|
58
|
-
resisterPrivate(userID, 1);
|
59
|
-
const key1 = userID + 1;
|
60
|
-
resisterPrivate(key1, date);
|
61
|
-
} else {
|
62
|
-
differentMessages(replayToken);
|
63
|
-
}
|
64
|
-
break;
|
65
|
-
// 予定の開始時刻
|
66
|
-
case '1':
|
67
|
-
const matched1 = userMessage.match(hourMinExp);
|
68
|
-
if (matched1 != null) {
|
69
|
-
const message = '';
|
70
|
-
replayChatprivate(replayToken, message);
|
71
|
-
const date = matched1[1] + "," + matched1[2];//キャッシュ容量削減のために一つにまとめて保存。
|
72
|
-
resisterPrivate(userID, 2);
|
73
|
-
const key2 = userID + 2;
|
74
|
-
resisterPrivate(key2, date);
|
75
|
-
} else {
|
76
|
-
differentMessages(replayToken);
|
77
|
-
}
|
78
|
-
break;
|
79
|
-
// 終了日付
|
80
|
-
case '2':
|
81
|
-
const matched2 = userMessage.match(dateExp);
|
82
|
-
if (matched2 != null) {
|
83
|
-
const message = '次に終了';
|
84
|
-
replayChatprivate(replayToken, message);
|
85
|
-
const a = matched2[1] - 1; //Date()を使う為に-1をしておく。
|
86
|
-
const date = a + "," + matched2[2];//キャッシュ容量削減のために一つにまとめて保存。
|
87
|
-
resisterPrivate(userID, 3);
|
88
|
-
const key3 = userID + 3;
|
89
|
-
resisterPrivate(key3, date);
|
90
|
-
} else {
|
91
|
-
differentMessages(replayToken);
|
92
|
-
}
|
93
|
-
break;
|
94
|
-
// 予定の終了時刻
|
95
|
-
case '3':
|
96
|
-
const matched3 = userMessage.match(hourMinExp);
|
97
|
-
if (matched3 != null) {
|
98
|
-
const message = '次に予定の';
|
99
|
-
replayChatprivate(replayToken, message);
|
100
|
-
const date = matched3[1] + "," + matched3[2];
|
101
|
-
resisterPrivate(userID, 4);
|
102
|
-
const key4 = userID + 4;
|
103
|
-
resisterPrivate(key4, date);
|
104
|
-
} else {
|
105
|
-
differentMessages(replayToken);
|
106
|
-
}
|
107
|
-
break;
|
108
|
-
// 予定の名前
|
109
|
-
case '4':
|
110
|
-
const year = new Date().getFullYear();
|
111
|
-
const message = '西暦は' + year + '年でよろしいでしょうか?';
|
112
|
-
resisterPrivate(userID, 5);
|
113
|
-
const key5 = userID + 5;
|
114
|
-
resisterPrivate(key5, userMessage);
|
115
|
-
break;
|
116
|
-
// 匿名でグループに投稿する内容
|
117
|
-
case '10':
|
118
|
-
const numberExp = /[0-9]{1,2}/;
|
119
|
-
const matchmessage = userMessage.match(numberExp);
|
120
|
-
if (matchmessage == null) {
|
121
|
-
const message = "正しく入力されて";
|
122
|
-
replayChatprivate(replayToken, message);
|
123
|
-
} else {
|
124
|
-
const GroupID = chooseGroup(userID, matchmessage[0]);
|
125
|
-
replaymessage = retriveGroup(GroupID);
|
126
|
-
replayChatprivate(replayToken, replaymessage + '\nで');
|
127
|
-
resisterPrivate(userID, 11);
|
128
|
-
const key1 = userID + 1;
|
129
|
-
resisterPrivate(key1, replaymessage);//送信するルームを登録する。
|
130
|
-
}
|
131
|
-
break;
|
132
|
-
// グループに投稿する内容の確認
|
133
|
-
case '11':
|
134
|
-
if (yesExp.test(userMessage)) {
|
135
|
-
const message = "グループに"
|
136
|
-
replayChatprivate(replayToken, message);
|
137
|
-
resisterPrivate(userID, 12);
|
138
|
-
} else {
|
139
|
-
const message = "正しく入力"
|
140
|
-
replayChatprivate(replayToken, message);
|
141
|
-
deletecache()
|
142
|
-
}
|
143
|
-
break;
|
144
|
-
}
|
145
|
-
}
|
146
|
-
getUserName(userID);
|
147
|
-
if (Groupid != undefined) {
|
148
|
-
getUsersinfo(Groupid);
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
function storeCalender(userMessage, notchange, replayToken) {
|
153
|
-
const yearExp = /(19[0-9]{2}|20[0-9]{2})/;
|
154
|
-
if (yesExp.test(userMessage)) {
|
155
|
-
const targetIDExp = /xxxxx/;
|
156
|
-
if (userID.test(targetIDExp)) {
|
157
|
-
const [title, startDate, endDate] = createEventData(userID, notchange);
|
158
|
-
try {
|
159
|
-
CalendarApp.getCalendarById(CALENDER_ID).createEvent(title, startDate, endDate);
|
160
|
-
const message = "予定を追加しました";
|
161
|
-
replayChatprivate(replayToken, message);
|
162
|
-
cleardata(userID);
|
163
|
-
} catch (e) {
|
164
|
-
const message2 = "予定の追";
|
165
|
-
replayChatprivate(replayToken, message2);
|
166
|
-
cleardata(userID);
|
167
|
-
}
|
168
|
-
} else {
|
169
|
-
const [title, startDate, endDate] = createEventData(userID, notchange);
|
170
|
-
const startDATE = exchangeTIME(startDate);
|
171
|
-
const endDATE = exchangeTIME(endDate);
|
172
|
-
const url = generateURL(title, startDATE, endDATE);
|
173
|
-
replayChatprivate(replayToken, url);
|
174
|
-
cleardata(userID);
|
175
|
-
}
|
176
|
-
} else {
|
177
|
-
differentMessages(replayToken);
|
178
|
-
}
|
179
|
-
}
|
180
|
-
|
181
|
-
//userの名前を入手する為のプログラム。
|
182
|
-
function getUserName(userID) {
|
183
|
-
const line_endpoint = "https://api.line.me/v2/profile" + '/' + userID;
|
184
|
-
const options = {
|
185
|
-
"method": "get",
|
186
|
-
"headers": {
|
187
|
-
'Content-type': 'application/json; charset=UTF-8',
|
188
|
-
'Authorization': 'Bearer' + CHANNEL_ACCESS_TOKEN,
|
189
|
-
}
|
190
|
-
};
|
191
|
-
const ans = UrlFetchApp.fetch(line_endpoint, options);
|
192
|
-
const userName = JSON.parse(ans).displayName;
|
193
|
-
resisterTospreadsheet(userID, userName);
|
194
|
-
}
|
195
|
-
|
196
|
-
function differentMessages(replayToken) {
|
197
|
-
const message = '値の';
|
198
|
-
replayChatprivate(replayToken, message);
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
function cleardata(userID) {
|
203
|
-
const keys = [userID];
|
204
|
-
for (let i = 0; i < 8; i++) {
|
205
|
-
keys.push(userID + i);
|
206
|
-
}
|
207
|
-
for (let i = 0; i < keys.length; i++) {
|
208
|
-
deletecache(keys[i]);
|
209
|
-
}
|
210
|
-
}
|
211
|
-
|
212
|
-
function replayChatprivate(replayToken, message) {
|
213
|
-
const line_endpoint = 'https://api.line.me/v2/bot/message/replay';
|
214
|
-
|
215
|
-
const headers = {
|
216
|
-
'Content-type': 'application/json; charset=UTF-8',
|
217
|
-
'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN,
|
218
|
-
};
|
219
|
-
const payloadArgument = {
|
220
|
-
'replayToken': replayToken,
|
221
|
-
'messages': [{
|
222
|
-
'type': 'text',
|
223
|
-
'text': message,
|
224
|
-
}],
|
225
|
-
};
|
226
|
-
const payload = JSON.stringify(payloadArgument);
|
227
|
-
const options = {
|
228
|
-
'method': 'post',
|
229
|
-
'headers': headers,
|
230
|
-
'payload': payload,
|
231
|
-
};
|
232
|
-
const urlfetch = UrlFetchApp.fetch(line_endpoint, options);
|
233
|
-
}
|
234
|
-
|
235
|
-
//グルーブチャット用:返信
|
236
|
-
function replayChatGroup(body, GroupID) {
|
237
|
-
const line_endpoint = 'https://api.line.me/v2/bot/message/Pull';
|
238
|
-
|
239
|
-
const headers = {
|
240
|
-
'Content-type': 'application/json; charset=UTF-8',
|
241
|
-
'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN,
|
242
|
-
};
|
243
|
-
const payloadArgument = {
|
244
|
-
'to': GroupID,
|
245
|
-
'messages': [{
|
246
|
-
'type': 'text',
|
247
|
-
'text': body,
|
248
|
-
}],
|
249
|
-
};
|
250
|
-
const payload = JSON.stringify(payloadArgument);
|
251
|
-
const options = {
|
252
|
-
'method': 'post',
|
253
|
-
'headers': headers,
|
254
|
-
'payload': payload,
|
255
|
-
};
|
256
|
-
UrlFetchApp.fetch(line_endpoint, options);
|
257
|
-
}
|
258
|
-
//キャッシュに状態を保存する。
|
259
|
-
//状態;次の処理を定める
|
260
|
-
function resisterPrivate(userID, state) {
|
261
|
-
const cache = CacheService.getScriptCache();
|
262
|
-
cache.put(userID, state, 21600); //21600 seconds (6 hours)chashが保たれる
|
263
|
-
}
|
264
|
-
|
265
|
-
//今のstateの状態を返す。
|
266
|
-
function retrivePrivate(userID) {
|
267
|
-
const cache = CacheService.getScriptCache();
|
268
|
-
const state = cache.get(userID);
|
269
|
-
return state;
|
270
|
-
}
|
271
|
-
//プロパティを削除する
|
272
|
-
function deleteProperty(key) {
|
273
|
-
const scriptProperties = PropertiesService.getScriptProperties();
|
274
|
-
scriptProperties.deleteProperty(key)
|
275
|
-
}
|
276
|
-
|
277
|
-
//キャッシュを削除する。
|
278
|
-
function deletecache(key) {
|
279
|
-
const cache = CacheService.getScriptCache();
|
280
|
-
cache.remove(key);
|
281
|
-
}
|
282
27
|
```
|
283
28
|
### 試したこと
|
284
29
|
replayChatprivateを11行目に持ってきて実行したが、動作しなかった。
|
285
30
|
推測されるのが、replayChatprivate関連のミスではないか推測しているが、周辺のコードをweb上にあるコードと取り換えても全く動きませんでした。自分の中で疑わしい箇所は殆どチェックしましたが、どこがダメで動かないのか全く分かりません。
|
286
|
-
また、アクセストークンが正しいか他のプログラムで確認しアクセストークンには問題ありませんでした。
|
31
|
+
また、アクセストークンが正しいか他のプログラムで確認しアクセストークンには問題ありませんでした。
|
287
|
-
### 補足情報(FW/ツールのバージョンなど)
|
288
|
-
GASを用いて実行しています。
|
289
|
-
githubにソースを載せました。
|
290
|
-
https://github.com/asdfgh-13/gas/blob/master/%E3%82%B3%E3%83%BC%E3%83%89.gs
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -285,4 +285,6 @@
|
|
285
285
|
推測されるのが、replayChatprivate関連のミスではないか推測しているが、周辺のコードをweb上にあるコードと取り換えても全く動きませんでした。自分の中で疑わしい箇所は殆どチェックしましたが、どこがダメで動かないのか全く分かりません。
|
286
286
|
また、アクセストークンが正しいか他のプログラムで確認しアクセストークンには問題ありませんでした。
|
287
287
|
### 補足情報(FW/ツールのバージョンなど)
|
288
|
-
GASを用いて実行しています。
|
288
|
+
GASを用いて実行しています。
|
289
|
+
githubにソースを載せました。
|
290
|
+
https://github.com/asdfgh-13/gas/blob/master/%E3%82%B3%E3%83%BC%E3%83%89.gs
|