質問編集履歴
2
文言変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -29,410 +29,6 @@
|
|
29
29
|
### 該当のソースコード
|
30
30
|
|
31
31
|
|
32
|
-
|
33
|
-
```var CHANNEL_ACCESS_TOKEN = "自分用";
|
34
|
-
|
35
|
-
var ERROR_SHEET_ID = ""自分用"";
|
36
|
-
|
37
|
-
var CALENDER_ID = ""自分用"";
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
//日付、時刻のフォーマット設定
|
42
|
-
|
43
|
-
var dateExp = /(\d{2})/(\d{2})\s(\d{2}):(\d{2})/;
|
44
|
-
|
45
|
-
var dayExp = /(\d+)[/月](\d+)/;
|
46
|
-
|
47
|
-
var hourMinExp = /(\d+)[:時](\d+)*/;
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
function doPost(e) {
|
54
|
-
|
55
|
-
try {
|
56
|
-
|
57
|
-
handleMessage(e);
|
58
|
-
|
59
|
-
} catch(error) {
|
60
|
-
|
61
|
-
logging("ToCalendarFromLineBot");
|
62
|
-
|
63
|
-
logging(JSON.stringify(e));
|
64
|
-
|
65
|
-
logging(JSON.stringify(error));
|
66
|
-
|
67
|
-
var replyToken = JSON.parse(e.postData.contents).events[0].replyToken;
|
68
|
-
|
69
|
-
reply(replyToken, error.message);
|
70
|
-
|
71
|
-
}
|
72
|
-
|
73
|
-
}
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
function logging(str) {
|
80
|
-
|
81
|
-
var sheet = SpreadsheetApp.openById(""自分用"").getActiveSheet();
|
82
|
-
|
83
|
-
var ts = new Date().toLocaleString("japanese", {timeZone: "Asia/Osaka"});
|
84
|
-
|
85
|
-
sheet.appendRow([ts, str]);
|
86
|
-
|
87
|
-
}
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
function handleMessage(e) {
|
92
|
-
|
93
|
-
var replyToken = JSON.parse(e.postData.contents).events[0].replyToken;
|
94
|
-
|
95
|
-
var lineType = JSON.parse(e.postData.contents).events[0].type
|
96
|
-
|
97
|
-
if (typeof replyToken === "undefined" || lineType === "follow") {
|
98
|
-
|
99
|
-
return;
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
var userMessage = JSON.parse(e.postData.contents).events[0].message.text;
|
104
|
-
|
105
|
-
var cache = CacheService.getScriptCache();
|
106
|
-
|
107
|
-
var type = cache.get("type");
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
if (type === null) {
|
116
|
-
|
117
|
-
if (userMessage === "予定追加") {
|
118
|
-
|
119
|
-
cache.put("type", 1);
|
120
|
-
|
121
|
-
reply(replyToken, "予定日を教えてください!\n「06/17, 6月17日」などの形式なら大丈夫です!");
|
122
|
-
|
123
|
-
} else if (userMessage === "一週間の予定確認") {
|
124
|
-
|
125
|
-
reply(replyToken, getEventss());
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
else {
|
130
|
-
|
131
|
-
reply(replyToken, "メニューの『予定追加』で予定追加を、『一週間の予定確認』で一週間の予定参照ができるので気軽に話しかけてくださいね!");
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
} else {
|
136
|
-
|
137
|
-
if (userMessage === "キャンセル") {
|
138
|
-
|
139
|
-
cache.remove("type");
|
140
|
-
|
141
|
-
reply(replyToken, "キャンセルしました!");
|
142
|
-
|
143
|
-
return;
|
144
|
-
|
145
|
-
}
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
switch(type) {
|
150
|
-
|
151
|
-
case "1":
|
152
|
-
|
153
|
-
// 予定日
|
154
|
-
|
155
|
-
var [matched, month, day] = userMessage.match(dayExp); //dayexpの型に合う文字列を取り出す。
|
156
|
-
|
157
|
-
cache.put("type", 2);
|
158
|
-
|
159
|
-
cache.put("month", month);
|
160
|
-
|
161
|
-
cache.put("day", day);
|
162
|
-
|
163
|
-
reply(replyToken, month + "/" + day + "ですね! 次に開始時刻を教えてください。「13:00, 13時, 13:20, 13時20分」などの形式なら大丈夫です!");
|
164
|
-
|
165
|
-
break;
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
case "2":
|
170
|
-
|
171
|
-
// 開始時刻
|
172
|
-
|
173
|
-
var [matched, startHour, startMin] = userMessage.match(hourMinExp);
|
174
|
-
|
175
|
-
cache.put("type", 3);
|
176
|
-
|
177
|
-
cache.put("start_hour", startHour);
|
178
|
-
|
179
|
-
if (startMin == null) startMin = "00";
|
180
|
-
|
181
|
-
cache.put("start_min", startMin);
|
182
|
-
|
183
|
-
reply(replyToken, startHour + ":" + startMin + "ですね! 次に終了時刻を教えてください。");
|
184
|
-
|
185
|
-
break;
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
case "3":
|
190
|
-
|
191
|
-
// 終了時刻
|
192
|
-
|
193
|
-
var [matched, endHour, endMin] = userMessage.match(hourMinExp);
|
194
|
-
|
195
|
-
cache.put("type", 4);
|
196
|
-
|
197
|
-
cache.put("end_hour", endHour);
|
198
|
-
|
199
|
-
if (endMin == null) endMin = "00";
|
200
|
-
|
201
|
-
cache.put("end_min", endMin);
|
202
|
-
|
203
|
-
reply(replyToken, endHour + ":" + endMin + "ですね! 最後に予定名を教えてください!");
|
204
|
-
|
205
|
-
break;
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
case "4":
|
210
|
-
|
211
|
-
// 予定名
|
212
|
-
|
213
|
-
cache.put("type", 5);
|
214
|
-
|
215
|
-
cache.put("title", userMessage);
|
216
|
-
|
217
|
-
var [title, startDate, endDate] = createEventData(cache);
|
218
|
-
|
219
|
-
reply(replyToken, toEventFormat(title, startDate, endDate) + "\nで間違いないでしょうか? \nよろしければ「はい」を\nやり直す場合は「いいえ」をお願いいたします!");
|
220
|
-
|
221
|
-
break;
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
case "5":
|
226
|
-
|
227
|
-
// 確認の回答がはい or いいえ
|
228
|
-
|
229
|
-
cache.remove("type");
|
230
|
-
|
231
|
-
if (userMessage === "はい") {
|
232
|
-
|
233
|
-
var [title, startDate, endDate] = createEventData(cache);
|
234
|
-
|
235
|
-
CalendarApp.getDefaultCalendar().createEvent(title, startDate, endDate);
|
236
|
-
|
237
|
-
reply(replyToken, "追加しました!\nお疲れ様でした!");
|
238
|
-
|
239
|
-
} else {
|
240
|
-
|
241
|
-
reply(replyToken, "お手数ですがもう一度お願いいたします!");
|
242
|
-
|
243
|
-
}
|
244
|
-
|
245
|
-
break;
|
246
|
-
|
247
|
-
default:
|
248
|
-
|
249
|
-
reply(replyToken, "申し訳ありません。\n形式に誤りがないか確認してみて、なければ「キャンセル」で予定入力をキャンセルすることができるので、そちらを試していただけますか?");
|
250
|
-
|
251
|
-
break;
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
}
|
256
|
-
|
257
|
-
}
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
function createEventData(cache) {
|
262
|
-
|
263
|
-
var year = new Date().getFullYear();
|
264
|
-
|
265
|
-
var title = cache.get("title");
|
266
|
-
|
267
|
-
var startDate = new Date(year, cache.get("month") - 1, cache.get("day"), cache.get("start_hour"), cache.get("start_min"));
|
268
|
-
|
269
|
-
var endDate = new Date(year, cache.get("month") - 1, cache.get("day"), cache.get("end_hour"), cache.get("end_min"));
|
270
|
-
|
271
|
-
return [title, startDate, endDate];
|
272
|
-
|
273
|
-
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
function toEventFormat(title, startDate, endDate) {
|
278
|
-
|
279
|
-
var start = Utilities.formatDate(startDate, "JST", "MM/dd HH:mm");
|
280
|
-
|
281
|
-
var end = Utilities.formatDate(endDate, "JST", "MM/dd HH:mm");
|
282
|
-
|
283
|
-
var str = title + ": " + start + " ~ " + end;
|
284
|
-
|
285
|
-
return str;
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
function reply(replyToken, message) {
|
292
|
-
|
293
|
-
var url = "https://api.line.me/v2/bot/message/reply";
|
294
|
-
|
295
|
-
UrlFetchApp.fetch(url, {
|
296
|
-
|
297
|
-
"headers": {
|
298
|
-
|
299
|
-
"Content-Type": "application/json; charset=UTF-8",
|
300
|
-
|
301
|
-
"Authorization": "Bearer " + CHANNEL_ACCESS_TOKEN,
|
302
|
-
|
303
|
-
},
|
304
|
-
|
305
|
-
"method": "post",
|
306
|
-
|
307
|
-
"payload": JSON.stringify({
|
308
|
-
|
309
|
-
"replyToken": replyToken,
|
310
|
-
|
311
|
-
"messages": [{
|
312
|
-
|
313
|
-
"type": "text",
|
314
|
-
|
315
|
-
"text": message,
|
316
|
-
|
317
|
-
}],
|
318
|
-
|
319
|
-
}),
|
320
|
-
|
321
|
-
});
|
322
|
-
|
323
|
-
return ContentService.createTextOutput(JSON.stringify({"content": "post ok"})).setMimeType(ContentService.MimeType.JSON);
|
324
|
-
|
325
|
-
}
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
function get_Calendar() {
|
338
|
-
|
339
|
-
var arrCals=[];
|
340
|
-
|
341
|
-
arrCals.push(CalendarApp.getCalendarById('"自分用"'));
|
342
|
-
|
343
|
-
return arrCals;
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
//1週間の予定を取得するメインの関数
|
350
|
-
|
351
|
-
function get_Week_Schedule(){
|
352
|
-
|
353
|
-
var arrCals = get_Calendar();
|
354
|
-
|
355
|
-
var dateNow = new Date();
|
356
|
-
|
357
|
-
var date = new Date();
|
358
|
-
|
359
|
-
var strBody ='';
|
360
|
-
|
361
|
-
var tmpBody ='';
|
362
|
-
|
363
|
-
var strIntro = "おはようございます!☀️\n1週間の予定です。\n" ;
|
364
|
-
|
365
|
-
for (var j = 1; j < 7 ; j++ ){
|
366
|
-
|
367
|
-
date.setDate(dateNow.getDate()+j);
|
368
|
-
|
369
|
-
for (var i = 0 ; i < arrCals.length ; i++){
|
370
|
-
|
371
|
-
tmpBody = tmpBody + getEvents(arrCals[i],date);
|
372
|
-
|
373
|
-
}
|
374
|
-
|
375
|
-
if (tmpBody){
|
376
|
-
|
377
|
-
strBody = strBody + date.getDate() + '日\n' + tmpBody;
|
378
|
-
|
379
|
-
}
|
380
|
-
|
381
|
-
tmpBody = '';
|
382
|
-
|
383
|
-
}
|
384
|
-
|
385
|
-
return (strIntro + strBody);
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
}
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
//予定を取得する関数
|
396
|
-
|
397
|
-
function getEvents(Cals,getDate){
|
398
|
-
|
399
|
-
var arrEvents = Cals.getEventsForDay(getDate);//カレンダーの予定取得
|
400
|
-
|
401
|
-
var strEvents ='';
|
402
|
-
|
403
|
-
for (var i=0; i<arrEvents.length; i++){
|
404
|
-
|
405
|
-
var strTitle = arrEvents[i].getTitle();
|
406
|
-
|
407
|
-
var strStart = _HHmm(arrEvents[i].getStartTime());
|
408
|
-
|
409
|
-
var strEnd = _HHmm(arrEvents[i].getEndTime());
|
410
|
-
|
411
|
-
if (strStart == strEnd){
|
412
|
-
|
413
|
-
strEvents = strEvents + '終日:' + strTitle + '\n';
|
414
|
-
|
415
|
-
}else{
|
416
|
-
|
417
|
-
strEvents = strEvents + strStart + '~' + strEnd+ ':' + strTitle + '\n';
|
418
|
-
|
419
|
-
}
|
420
|
-
|
421
|
-
}
|
422
|
-
|
423
|
-
return strEvents;
|
424
|
-
|
425
|
-
}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
//予定確認時の関数
|
430
|
-
|
431
|
-
function getEventss() {
|
432
|
-
|
433
|
-
var events = CalendarApp.getDefaultCalendar().getEventsForDay(new Date());
|
434
|
-
|
435
|
-
var body;
|
436
32
|
|
437
33
|
|
438
34
|
|
1
タイトル修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
【
|
1
|
+
【GAS】LINE BOTに決まった時間に通知するトリガーを設定したい
|
test
CHANGED
File without changes
|