質問編集履歴

1

コードの修正をしました。

2019/11/14 07:14

投稿

KPS
KPS

スコア8

test CHANGED
File without changes
test CHANGED
@@ -10,142 +10,92 @@
10
10
 
11
11
 
12
12
 
13
- var LINETOKEN ="ライントークン";
13
+ ```
14
14
 
15
+ var LINETOKEN ="ライントークン";
15
16
 
17
+ function doPost(e) {
16
18
 
17
- function doPost(e) {
19
+ const prop = PropertiesService.getScriptProperties().getProperties();
18
20
 
19
-
21
+ const responseLine = e.postData.getDataAsString();
20
22
 
21
- const prop = PropertiesService.getScriptProperties().getProperties();
23
+ const responseLineJson = JSON.parse(responseLine).events[0];
22
24
 
23
-
25
+ const replyToken = responseLineJson.replyToken;
24
26
 
25
- const responseLine = e.postData.getDataAsString();
27
+ if (responseLineJson.type == 'message') {
26
28
 
27
-
28
-
29
- const responseLineJson = JSON.parse(responseLine).events[0];
30
-
31
-
32
-
33
- const replyToken = responseLineJson.replyToken;
34
-
35
-
36
-
37
-
38
-
39
- if (responseLineJson.type == 'message') {
40
-
41
- messageController(prop, responseLineJson, replyToken);
29
+ messageController(prop, responseLineJson, replyToken);
42
-
43
- }
44
30
 
45
31
  }
46
32
 
33
+ }
47
34
 
35
+ function messageController(prop, events, replyToken) {
48
36
 
49
- function messageController(prop, events, replyToken) {
37
+ const message = events.message;
50
38
 
51
-
39
+ const text = message.text;
52
40
 
53
- const message = events.message;
41
+ if (text.indexOf('就業時間') > -1) {
54
42
 
55
-
43
+ var postMessage = "";
56
44
 
57
- const text = message.text;
45
+ const sheet = SpreadsheetApp.openById("スプレッドシートID","就業時間!A1:B6");
58
46
 
59
-
47
+ const sheetData = sheet.getDataRange().getValues();
60
48
 
61
-
49
+ for (var row in sheetData) {
62
50
 
63
- if (text.indexOf('就業時間') > -1) {
51
+ postMessage = postMessage + sheetData[row][0] + '\n';
64
52
 
65
-
53
+ }
66
54
 
67
- var postMessage = "";
55
+ var LineMessageObject = [{
68
56
 
69
- const sheet = SpreadsheetApp.openById("スプレッドシートID","就業時間!A1:B6");
57
+ 'type': 'text',
70
58
 
71
-
59
+ 'text': postMessage
72
60
 
73
- const sheetData = sheet.getDataRange().getValues();
61
+ }];
74
62
 
75
-
76
-
77
-
78
-
79
- for (var row in sheetData) {
80
-
81
- postMessage = postMessage + sheetData[row][0] + '\n';
82
-
83
- }
84
-
85
-
86
-
87
-
88
-
89
- var LineMessageObject = [{
90
-
91
- 'type': 'text',
92
-
93
- 'text': postMessage
94
-
95
- }];
96
-
97
-
98
-
99
-
100
-
101
- replyLine(prop, LineMessageObject, replyToken);
63
+ replyLine(prop, LineMessageObject, replyToken);
102
-
103
- }
104
64
 
105
65
  }
106
66
 
107
-
67
+ }
108
-
109
-
110
-
111
-
112
-
113
-
114
68
 
115
69
  function replyLine(prop, LineMessageObject, replyToken) {
116
70
 
117
- const replyHeaders = {
71
+ const replyHeaders = {
118
72
 
119
- 'Content-Type': 'application/json',
73
+ 'Content-Type': 'application/json',
120
74
 
121
- 'Authorization': 'Bearer ' + prop.LINE_TOKEN
75
+ 'Authorization': 'Bearer ' + prop.LINE_TOKEN
122
76
 
123
- };
77
+ };
124
78
 
125
-
79
+ const replyBody = {
126
80
 
127
- const replyBody = {
81
+ 'replyToken': replyToken,
128
82
 
129
- 'replyToken': replyToken,
83
+ 'messages': LineMessageObject
130
84
 
131
- 'messages': LineMessageObject
85
+ };
132
86
 
133
- };
87
+ const replyOptions = {
134
88
 
135
-
89
+ 'method': 'POST',
136
90
 
137
- const replyOptions = {
91
+ 'headers': replyHeaders,
138
92
 
139
- 'method': 'POST',
93
+ 'payload': JSON.stringify(replyBody)
140
94
 
141
- 'headers': replyHeaders,
95
+ };
142
96
 
143
- 'payload': JSON.stringify(replyBody)
144
-
145
- };
146
-
147
-
148
-
149
- UrlFetchApp.fetch('https://api.line.me/v2/bot/message/reply', replyOptions);
97
+ UrlFetchApp.fetch('https://api.line.me/v2/bot/message/reply', replyOptions);
150
98
 
151
99
  }
100
+
101
+ ```