質問編集履歴
2
文言修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
時間指定なしのLINEBOTをGASで作成中です????
|
test
CHANGED
@@ -36,85 +36,7 @@
|
|
36
36
|
|
37
37
|
```ここに言語名を入力
|
38
38
|
|
39
|
-
var CHANNEL_ACCESS_TOKEN = "アクセストークン";
|
40
39
|
|
41
|
-
var dateExp = /(\d+)[/月](\d+)/;
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
//doPost関数(Lineからメッセージを受け取る)
|
46
|
-
|
47
|
-
function doPost(e) {
|
48
|
-
|
49
|
-
GetMessage(e);
|
50
|
-
|
51
|
-
}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
//受け取ったメッセージの処理
|
56
|
-
|
57
|
-
function GetMessage(e) {
|
58
|
-
|
59
|
-
var replyToken = JSON.parse(e.postData.contents).events[0].replyToken;
|
60
|
-
|
61
|
-
if (typeof replyToken === 'undefined') {
|
62
|
-
|
63
|
-
return;
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
var messageText = JSON.parse(e.postData.contents).events[0].message.text;
|
68
|
-
|
69
|
-
var cache = CacheService.getScriptCache();
|
70
|
-
|
71
|
-
var type = cache.get("type");
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
if (type === null) {
|
76
|
-
|
77
|
-
//予定の追加
|
78
|
-
|
79
|
-
if (messageText === "予定の追加") {
|
80
|
-
|
81
|
-
cache.put("type", 1);
|
82
|
-
|
83
|
-
//開始日時の質問
|
84
|
-
|
85
|
-
replyPlans(replyToken, "予定日をいずれかの形式で教えてください。", "【06/18】", "【6月18日】などの形式なら大丈夫です!");
|
86
|
-
|
87
|
-
//今日、7日間の予定の取得
|
88
|
-
|
89
|
-
} else if (messageText.match("今日の予定")) {
|
90
|
-
|
91
|
-
reply(replyToken, getEvents());
|
92
|
-
|
93
|
-
} else if (messageText.match("今週の予定")) {
|
94
|
-
|
95
|
-
reply(replyToken, notifyWeekly());
|
96
|
-
|
97
|
-
} else {
|
98
|
-
|
99
|
-
//処理方法の返答
|
100
|
-
|
101
|
-
replyPlans(replyToken, "「予定の追加」で予定追加します", "「今日の予定」で今日の予定をお知らせします。", "「今週の予定」で7日間の予定をお知らせします。");
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
} else {
|
106
|
-
|
107
|
-
//キャンセル処理
|
108
|
-
|
109
|
-
if (messageText === "キャンセル") {
|
110
|
-
|
111
|
-
cache.remove("type");
|
112
|
-
|
113
|
-
reply(replyToken, "予定追加のキャンセルをしました");
|
114
|
-
|
115
|
-
return;
|
116
|
-
|
117
|
-
}
|
118
40
|
|
119
41
|
|
120
42
|
|
@@ -192,265 +114,7 @@
|
|
192
114
|
|
193
115
|
//予定追加の確認
|
194
116
|
|
195
|
-
replyPlans(replyToken, "予定名:" + title, "開始日時:\n" + EventFormat(startDate)+ "予定を追加しますか?\n 「はい」か「いいえ」で
|
117
|
+
replyPlans(replyToken, "予定名:" + title, "開始日時:\n" + EventFormat(startDate)+ "予定を追加しますか?\n 「はい」か「いいえ」で
|
196
|
-
|
197
|
-
break;
|
198
|
-
|
199
|
-
case "4":
|
200
|
-
|
201
|
-
if (messageText === "はい") {
|
202
|
-
|
203
|
-
cache.remove("type");
|
204
|
-
|
205
|
-
var [title, startDate] = createData(cache);
|
206
|
-
|
207
|
-
CalendarApp.getDefaultCalendar().createEvent(title, startDate);
|
208
|
-
|
209
|
-
reply(replyToken, "Googleカレンダーに予定を追加しました");
|
210
|
-
|
211
|
-
} else if (messageText === "いいえ") {
|
212
|
-
|
213
|
-
cache.remove("type");
|
214
|
-
|
215
|
-
reply(replyToken, "予定の追加をキャンセルしました。");
|
216
|
-
|
217
|
-
} else{
|
218
|
-
|
219
|
-
reply(replyToken, "「はい」か「いいで」でお答えください。");
|
220
|
-
|
221
|
-
break;
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
break;
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
}
|
232
|
-
|
233
|
-
}
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
function createData(cache) {
|
240
|
-
|
241
|
-
var year = new Date().getFullYear();
|
242
|
-
|
243
|
-
//var year = 2020;
|
244
|
-
|
245
|
-
var title = cache.get("title");
|
246
|
-
|
247
|
-
var startDate = new Date(year, cache.get("start_month") - 1, cache.get("start_day"));
|
248
|
-
|
249
|
-
return [title, startDate];
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
function EventFormat(Date) {
|
256
|
-
|
257
|
-
var y = Date.getFullYear();
|
258
|
-
|
259
|
-
var m = Date.getMonth() + 1;
|
260
|
-
|
261
|
-
var d = Date.getDate();
|
262
|
-
|
263
|
-
var w = Date.getDay();
|
264
|
-
|
265
|
-
var weekname = ['日', '月', '火', '水', '木', '金', '土'];
|
266
|
-
|
267
|
-
m = ('0' + m).slice(-2);
|
268
|
-
|
269
|
-
d = ('0' + d).slice(-2);
|
270
|
-
|
271
|
-
return y + '年' + m + '月' + d + '日 (' + weekname[w] + ')\n';
|
272
|
-
|
273
|
-
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
function replyPlans(replyToken, message, message2, message3) {
|
278
|
-
|
279
|
-
var url = "https://api.line.me/v2/bot/message/reply";
|
280
|
-
|
281
|
-
UrlFetchApp.fetch(url, {
|
282
|
-
|
283
|
-
"headers": {
|
284
|
-
|
285
|
-
"Content-Type": "application/json; charset=UTF-8",
|
286
|
-
|
287
|
-
"Authorization": "Bearer " + CHANNEL_ACCESS_TOKEN,
|
288
|
-
|
289
|
-
},
|
290
|
-
|
291
|
-
"method": "post",
|
292
|
-
|
293
|
-
"payload": JSON.stringify({
|
294
|
-
|
295
|
-
"replyToken": replyToken,
|
296
|
-
|
297
|
-
"messages": [{
|
298
|
-
|
299
|
-
"type": "text",
|
300
|
-
|
301
|
-
"text": message,
|
302
|
-
|
303
|
-
},{
|
304
|
-
|
305
|
-
"type": "text",
|
306
|
-
|
307
|
-
"text": message2,
|
308
|
-
|
309
|
-
},{
|
310
|
-
|
311
|
-
"type": "text",
|
312
|
-
|
313
|
-
"text": message3,
|
314
|
-
|
315
|
-
}],
|
316
|
-
|
317
|
-
}),
|
318
|
-
|
319
|
-
});
|
320
|
-
|
321
|
-
return ContentService.createTextOutput(JSON.stringify({"content": "post ok"})).setMimeType(ContentService.MimeType.JSON);
|
322
|
-
|
323
|
-
}
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
function reply(replyToken, message) {
|
328
|
-
|
329
|
-
var url = "https://api.line.me/v2/bot/message/reply";
|
330
|
-
|
331
|
-
UrlFetchApp.fetch(url, {
|
332
|
-
|
333
|
-
"headers": {
|
334
|
-
|
335
|
-
"Content-Type": "application/json; charset=UTF-8",
|
336
|
-
|
337
|
-
"Authorization": "Bearer " + CHANNEL_ACCESS_TOKEN,
|
338
|
-
|
339
|
-
},
|
340
|
-
|
341
|
-
"method": "post",
|
342
|
-
|
343
|
-
"payload": JSON.stringify({
|
344
|
-
|
345
|
-
"replyToken": replyToken,
|
346
|
-
|
347
|
-
"messages": [{
|
348
|
-
|
349
|
-
"type": "text",
|
350
|
-
|
351
|
-
"text": message,
|
352
|
-
|
353
|
-
}],
|
354
|
-
|
355
|
-
}),
|
356
|
-
|
357
|
-
});
|
358
|
-
|
359
|
-
return ContentService.createTextOutput(JSON.stringify({"content": "post ok"})).setMimeType(ContentService.MimeType.JSON);
|
360
|
-
|
361
|
-
}
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
//今日の予定
|
366
|
-
|
367
|
-
function getEvents() {
|
368
|
-
|
369
|
-
var events = CalendarApp.getDefaultCalendar().getEventsForDay(new Date());
|
370
|
-
|
371
|
-
var body = "今日の予定は";
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
if (events.length === 0) {
|
376
|
-
|
377
|
-
body += "ありません。";
|
378
|
-
|
379
|
-
return body;
|
380
|
-
|
381
|
-
}
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
body += "\n";
|
386
|
-
|
387
|
-
events.forEach(function(event) {
|
388
|
-
|
389
|
-
var title = event.getTitle();
|
390
|
-
|
391
|
-
body += "★" + title + "\n";
|
392
|
-
|
393
|
-
});
|
394
|
-
|
395
|
-
body += "です。";
|
396
|
-
|
397
|
-
return body;
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
//7日間の予定
|
404
|
-
|
405
|
-
function notifyWeekly() {
|
406
|
-
|
407
|
-
var body = "7日間の予定は\n";
|
408
|
-
|
409
|
-
var weekday = ["日", "月", "火", "水", "木", "金", "土"];
|
410
|
-
|
411
|
-
for ( var i = 0; i < 7; i++ ) {
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
var dt = new Date();
|
416
|
-
|
417
|
-
dt.setDate(dt.getDate()+i);
|
418
|
-
|
419
|
-
var events = CalendarApp.getDefaultCalendar().getEventsForDay(dt);
|
420
|
-
|
421
|
-
body += Utilities.formatDate(dt, "JST", '★ MM/dd(' + weekday[dt.getDay()] + ')') + "\n";
|
422
|
-
|
423
|
-
if (events.length === 0) {
|
424
|
-
|
425
|
-
body += "ありません。\n";
|
426
|
-
|
427
|
-
}
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
events.forEach(function(event) {
|
432
|
-
|
433
|
-
var title = event.getTitle();
|
434
|
-
|
435
|
-
body += title + "\n";
|
436
|
-
|
437
|
-
});
|
438
|
-
|
439
|
-
}
|
440
|
-
|
441
|
-
return body;
|
442
|
-
|
443
|
-
}
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
function HmFormat(date){
|
448
|
-
|
449
|
-
return Utilities.formatDate(date, "JST", "HH:mm");
|
450
|
-
|
451
|
-
}
|
452
|
-
|
453
|
-
|
454
118
|
|
455
119
|
```
|
456
120
|
|
1
文言変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,6 +14,10 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
+
具体的にご回答いただけると助かります、、、、、、、
|
18
|
+
|
19
|
+
|
20
|
+
|
17
21
|
### 発生している問題・エラーメッセージ
|
18
22
|
|
19
23
|
|