質問編集履歴
1
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,49 +26,143 @@
|
|
26
26
|
|
27
27
|
```GAS
|
28
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
|
-
const t
|
58
|
-
|
59
|
-
const s
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
29
|
+
//送付エラーのタイムスタンプ/件名/本文/メールIDをスプレッドシートに吐き出す
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
function getGmailToSS() {
|
34
|
+
|
35
|
+
const ss = SpreadsheetApp.getActiveSpreadsheet();
|
36
|
+
|
37
|
+
const sheet = ss.getSheetByName('errordata_gmail');
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
const searchlabel = '"送付エラー"';
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
const threads = GmailApp.search('label:(' + searchlabel + ') -label:処理済み');
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
const msgIdArray = sheet.getRange("D:D").getValues().filter(String).flat();
|
50
|
+
|
51
|
+
let lastRow = msgIdArray.length + 1;
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
for(const n in threads){
|
56
|
+
|
57
|
+
const thread = threads[n];
|
58
|
+
|
59
|
+
const msgs = thread.getMessages();
|
60
|
+
|
61
|
+
msgs
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
for(m in msgs){
|
66
|
+
|
67
|
+
const msg = msgs[m];
|
68
|
+
|
69
|
+
const id = msg.getId();
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
if(msgIdArray.includes(id)) continue; //IDがD列に既に存在する場合はスルー
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
const msgData = [[msg.getDate(),msg.getSubject(),msg.getPlainBody(),id]];
|
80
|
+
|
81
|
+
sheet.getRange(lastRow,1,1,4).setValues(msgData); //まとめて書き込み
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
lastRow++
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
const label = GmailApp.getUserLabelByName('処理済み');
|
94
|
+
|
95
|
+
thread.addLabel(label);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
// スプレッドシートから必要なデータを読み取り、スラックに投稿する。
|
104
|
+
|
105
|
+
const staffErrorEmail = sh.getRange(writeRow, 5).getValue(); //5=E列(送付エラーアドレス)
|
106
|
+
|
107
|
+
const staffName = sh.getRange(writeRow, 6).getValue(); //6=F列(スタッフ名)
|
108
|
+
|
109
|
+
const temphireId = sh.getRange(writeRow, 7).getValue(); //7=G列(ID)
|
110
|
+
|
111
|
+
const slackId = sh.getRange(writeRow, 9).getValue(); //9=I列(SlackID)
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
const message = slackId + '\n' + staffName + '\n' + staffErrorEmail + temphireId;
|
116
|
+
|
117
|
+
postToSlack(message);
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
function postToSlack(message){
|
128
|
+
|
129
|
+
const postToMDS = "通知先のWebhooksURL"; //
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
const jsonData =
|
134
|
+
|
135
|
+
{
|
136
|
+
|
137
|
+
"text" : message,
|
138
|
+
|
139
|
+
};
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
const payload = JSON.stringify(jsonData);
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
const options =
|
148
|
+
|
149
|
+
{
|
150
|
+
|
151
|
+
"method" : "post",
|
152
|
+
|
153
|
+
"contentType" : "application/json",
|
154
|
+
|
155
|
+
"payload" : payload,
|
156
|
+
|
157
|
+
};
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
// リクエスト
|
162
|
+
|
163
|
+
UrlFetchApp.fetch(postToMDS, options);
|
164
|
+
|
165
|
+
}
|
72
166
|
|
73
167
|
|
74
168
|
|
@@ -76,58 +170,6 @@
|
|
76
170
|
|
77
171
|
|
78
172
|
|
79
|
-
```GAS
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
function postToSlack(message){
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
const postToMDS = "通知先のWebhooksURL";
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
const jsonData =
|
92
|
-
|
93
|
-
{
|
94
|
-
|
95
|
-
"text" : message,
|
96
|
-
|
97
|
-
};
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
const payload = JSON.stringify(jsonData);
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
const options =
|
106
|
-
|
107
|
-
{
|
108
|
-
|
109
|
-
"method" : "post",
|
110
|
-
|
111
|
-
"contentType" : "application/json",
|
112
|
-
|
113
|
-
"payload" : payload,
|
114
|
-
|
115
|
-
};
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
// リクエスト
|
120
|
-
|
121
|
-
UrlFetchApp.fetch(postToMDS, options);
|
122
|
-
|
123
|
-
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
```
|
128
|
-
|
129
|
-
|
130
|
-
|
131
173
|
### 補足情報
|
132
174
|
|
133
175
|
|