GMAIL에서 Discord 채널 Webhook 자습서로
추상적인
프로젝트를 진행하는 동안
Slack , Microsoft Teams , Discord 등 통신 공작은 원활한 프로젝트 진행을 위해 벽 요소 중에 하나입니다.특히, 게임 주요 도구로 문제
Discord의 경우 실행에 지속되어 사용자를 만족시키는 강력한 커뮤니케이션 기능을 가지고 있다 보니 프로젝트 메인 커뮤니케이션으로 사용되는 경우도 점차 증가하고 있다.이번 포스팅에서는 팀 메일이나 공식 메일이 올때마다 메일을 확인하는 것이 아닌
Discord 의 하나의 채널에서 알림이 올수 있도록 웹훅 설정을 하는 과정을 소개하고자 합니다.Discord DOC 링크: https://discord.com/developers/applications
전제 조건
후크 웹 권한 설정

시작하기
Integrations 메뉴에서 Webhooks 생성을 클릭통합 메뉴

New Webhook 을 선택해서 새로운 Webhook 을 생성한 뒤 필요한 정보( Bot Name , Channel )를 입력해서 Noti-Bot 을 생성Discord 세팅은 여기까지 완료되었습니다웹훅 생성

Google 앱 접속 페이지 접속:
https://www.google.com/script/start/
새 프로젝트 생성
구글 앱 메인 화면

메인 대쉬보드

새로운 프로젝트에 다음과 함께 글을 작성하세요
메모
webhooks 의학에는 Discord 의 Webhook URL 을 입력 웹훅 생성 화면

channel 의학에는 채널 이름을 등록Discord 채널명

searchQuery에는 Google 메일에서 검색 쿼리를 쓰는 것을 사용한다. (하기 이미지 참조) 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' +
                '\n' +
                Utilities.formatDate(msgDate, 'America/New_York', 'MM/DD/yyyy hh:mm:ss') +
                '\n' +
                'Title:' +
                subject +
                '\n' +
                '[hr]' +
                msgBody;
            // 2000 Characters limits
            if (postMessage.length > 2000) {
                const stopPos = 1900; //
                const msg = '"Exceeded 2000 character limit."';
                postMessage = postMessage.substring(0, stopPos) + '\n' + msg;
            }
            postDiscord(postMessage);
        }
    }
}
trigger를 설정이후에 새로운 메일이 올 경우에는 채널에 새로운 메시지가 게시될 것입니다.
메모
sendMailsToDiscord Head 시간 기반 분 단위 타이머 30분마다 즉시 알림 트리거 화면

결론
본 포스팅에서는
GMAIL 에서 Discord 채널에 새로운 메일이 올때마다 푸시하는 webhook 을 Google App Script 를 통해 Set up해 보았다.Discord는 퍼포먼스에 돋보이게 게이머를 만족시킬 수 있을 정도의 수준의 서비스를 제공하고 있으며 앞으로의 여러 프로젝트에서도 많은 작업을 할 것입니다. 거기에 전 세계 기록의 표준 똑딱이 있는GMAIL 을 꺾는 것은 가장 많이 사용하는Webhook 중 하나가 되는 것을 본 모습이 그런 부분에 많은 도움이 되도록 하는 바램이다.본 논문에 쓰인 방법이 궁금하다면 하기의
Google App Script 링크에서 자세한 내용을 참고링크: https://developers.google.com/apps-script/reference/document
Reference
이 문제에 관하여(GMAIL에서 Discord 채널 Webhook 자습서로), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/soom/gmail-to-discord-channel-webhook-tutorial-mnm텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)