({
webhookUrl,
message,
}: {
webhookUrl: string;
message: string;
})
| 1 | // Cred to (@OpenStatusHQ) https://github.com/openstatusHQ/openstatus/blob/main/packages/notifications/discord/src/index.ts |
| 2 | |
| 3 | export function sendDiscordNotification({ |
| 4 | webhookUrl, |
| 5 | message, |
| 6 | }: { |
| 7 | webhookUrl: string; |
| 8 | message: string; |
| 9 | }) { |
| 10 | return fetch(webhookUrl, { |
| 11 | method: 'POST', |
| 12 | headers: { |
| 13 | 'Content-Type': 'application/json', |
| 14 | }, |
| 15 | body: JSON.stringify({ |
| 16 | content: message, |
| 17 | avatar_url: 'https://openpanel.dev/logo.jpg', |
| 18 | username: 'OpenPanel Notifications', |
| 19 | }), |
| 20 | }).catch((err) => { |
| 21 | return { |
| 22 | ok: false, |
| 23 | json: () => Promise.resolve({}), |
| 24 | }; |
| 25 | }); |
| 26 | } |
| 27 | |
| 28 | export function sendTestDiscordNotification(webhookUrl: string) { |
| 29 | return sendDiscordNotification({ |
no test coverage detected