From 458cde0e9b605dab9ece5dcad77d3d49085ac2c2 Mon Sep 17 00:00:00 2001 From: dcrespo Date: Tue, 19 Apr 2022 12:00:23 +0200 Subject: [PATCH] feat: using webhooks --- README.md | 3 +-- src/lib/sendChangelogMsg.ts | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6c5f95f..589a191 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,7 @@ You must use the changelog style generated by [Lerna](https://github.com/lerna/l | Property | Default | Description | | ------------- | :------------: | ------------------------------------ | | CHANGELOGPATH | `CHANGELOG.md` | Changelog path. | -| CHANNELID | - | Discord channel id. | -| TOKEN | - | Discord bot token. | +| WEBHOOK | - | Discord webhook. | | PROJECT | - | Project name. Used in message title. | ## Usage example diff --git a/src/lib/sendChangelogMsg.ts b/src/lib/sendChangelogMsg.ts index f8a5baf..67d403b 100644 --- a/src/lib/sendChangelogMsg.ts +++ b/src/lib/sendChangelogMsg.ts @@ -3,11 +3,11 @@ import { RequestOptions } from "https"; import { changelogData } from "../types"; -const CHANNELID = process.env.CHANNELID; -const TOKEN = process.env.TOKEN; +const WEBHOOK = process.env.WEBHOOK || ""; const PROJECT = process.env.PROJECT || ""; export function sendChangelogToChannel(changelog: changelogData) { + if (!WEBHOOK) throw new Error("WEBHOOK is not defined"); const msg = generateMsg(changelog); sendMessage(msg); } @@ -56,15 +56,15 @@ function getEmojiSection(section: string) { function sendMessage(message: string) { const post_data = JSON.stringify({ content: message, + username: "Git up to date", }); const post_options = { - host: "discordapp.com", + host: "discord.com", port: 443, - path: `/api/channels/${CHANNELID}/messages`, + path: WEBHOOK.replace("https://discord.com", ""), method: "POST", headers: { - Authorization: `Bot ${TOKEN}`, "Content-Type": "application/json", "Content-Length": Buffer.byteLength(post_data), },