-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCódigo.js
39 lines (31 loc) · 1013 Bytes
/
Código.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function read() {
const label = GmailApp.getUserLabelByName("Blog Drafts");
const threads = label.getThreads();
threads.map(thread => {
const message = thread.getMessages()[0];
const subject = message.getSubject();
const body = message.getPlainBody();
const response = _launchAction(subject, body);
if (response === 200 || response === 204) {
thread.removeLabel(label);
}
});
}
function _launchAction(subject, body) {
const secrets = _getSecrets();
const options = {
headers: {
Method: 'POST',
ContentType: 'application/vnd.github.v3+json',
Authorization: 'token ' + secrets.key,
},
muteHttpExceptions: true,
payload: JSON.stringify({ "ref": "main", "inputs": { "title": subject, "body": body } })
};
return UrlFetchApp.fetch(secrets.url, options);
}
function _getSecrets() {
const files = DriveApp.getFilesByName('Secrets.json');
const content = files.next().getBlob().getDataAsString();
return JSON.parse(content);
}