我正在从gmail中提取电子邮件,并将其修改为通过webhooks发布到不和谐。我设置了一个1分钟的触发器来运行,并希望尝试编辑代码,因此仅在收到新电子邮件时才触发。 这是我的代码,显然我取出了weebhook url。
这是电子邮件主题。...
最后一次低于286.74时触发间谍的侦听LAST = 269.99 NEWS = N / A
这就是不和谐发布的内容
,当最后一次低于284.76时,5个间谍LAST = 270.27 VOL DIFF = 3.38%DELTA = 1.00
function postMessageToDiscord(message) {
var thread = GmailApp.getInboxThreads(0,1)[0]; // Get first thread in inbox
var message = thread.getMessages()[0]; // Get first message
Logger.log(message.getSubject()); // Log subject line
var discordUrl = 'https://discordapp.com/api/webhooks/';
var discordUrl2 = 'https://discordapp.com/api/webhooks/';
var subject = message.getSubject();
subject = subject.replace(/(.*?)(ALERT ON)(.*)/g, ",5$3");
var payload = JSON.stringify({content: subject});
var params = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
method: "POST",
payload: payload,
muteHttpExceptions: true
};
var response = UrlFetchApp.fetch(discordUrl, params);
console.log(JSON.stringify(response));
var response = UrlFetchApp.fetch(discordUrl2, params);
console.log(JSON.stringify(response));
message.moveToTrash();
}