An Interest In:
Web News this Week
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
August 19, 2022 03:46 pm GMT
Original Link: https://dev.to/soom/gmail-to-discord-channel-webhook-tutorial-mnm
GMAIL to Discord Channel Webhook Tutorial
Abstract
Slack
, Microsoft Teams
, Discord
.
, Discord
.
Discord
.
Discord DOCs : https://discord.com/developers/applications
Prerequisite
- Discord
Getting Started
Integrations
Webhooks
Integrations
New Webhook
Webhook
(Bot Name
, Channel
) Noti-Bot
Discord
Webhook
:
https://www.google.com/script/start/
Note
webhooks
Discord
Webhook URL
Webhook
channel
Discord
searchQuery
. ( )
Gmail
Gmail
Discord
2000 2000 .
code.gs
function postDiscord(postMessage) { const webhooks = 'https://discord.com/api/webhooks/webhooks/{webhook.id}/{webhook.token}'; const channel = '{channel name}'; const parse = 'full'; const method = 'post'; const payload = { channel: channel, content: postMessage, parse: parse, }; const params = { method: method, payload: payload, muteHttpExceptions: true, }; response = UrlFetchApp.fetch(webhooks, params);}function sendMailsToDiscord() { const searchQuery = '{gmail query}'; const date = new Date(); const checkSpan = 30; date.setMinutes(date.getMinutes() - checkSpan); const threads = GmailApp.search(searchQuery); const msgs = GmailApp.getMessagesForThreads(threads); for (let i = 0; i < msgs.length; i++) { const lastMsgDate = threads[i].getLastMessageDate(); if (lastMsgDate.getTime() < date.getTime()) break; for (let j = 0; j < msgs[i].length; j++) { const msgDate = msgs[i][j].getDate(); const msgBody = msgs[i][j].getPlainBody(); const subject = msgs[i][j].getSubject(); const postMessage = 'From mailing list' + '
' + Utilities.formatDate(msgDate, 'America/New_York', 'MM/DD/yyyy hh:mm:ss') + '
' + 'Title:' + subject + '
' + '[hr]' + msgBody; // 2000 Characters limits if (postMessage.length > 2000) { const stopPos = 1900; // const msg = '"Exceeded 2000 character limit."'; postMessage = postMessage.substring(0, stopPos) + '
' + msg; } postDiscord(postMessage); } }}
trigger
.
Note
- :
sendMailsToDiscord
- :
Head
- :
- :
- :
30
- :
trigger
Conclusion
GMAIL
Discord
webhook
Google App Script
Set up .
Discord
. GMAIL
Webhook
.
Method Google App Script
Link: https://developers.google.com/apps-script/reference/document
Original Link: https://dev.to/soom/gmail-to-discord-channel-webhook-tutorial-mnm
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To