Send Discord and Slack webhooks with a clean, typed API β no boilerplate, built-in retries, full TypeScript support.
Built on top of devcodes-http-tool.
npm install devcodes-webhookconst { sendWebhook } = require('devcodes-webhook');
await sendWebhook('https://discord.com/api/webhooks/...', {
content: 'Hello from devcodes-webhook!'
});const { DiscordWebhook } = require('devcodes-webhook');
const hook = new DiscordWebhook('https://discord.com/api/webhooks/ID/TOKEN');
await hook.sendText('Server is back online β
');await hook.sendEmbed({
title: 'π Deployment Complete',
description: 'Version **1.4.2** is now live.',
color: 0x57F287, // green
timestamp: new Date().toISOString(),
footer: { text: 'Dev Codes CI' },
});await hook.sendEmbeds([
{ title: 'Service A', description: 'β
Healthy', color: 0x57F287 },
{ title: 'Service B', description: 'β οΈ Degraded', color: 0xFEE75C },
{ title: 'Service C', description: 'β Down', color: 0xED4245 },
]);await hook.send({
content: 'Ping!',
username: 'Alert Bot',
avatar_url: 'https://example.com/avatar.png',
});await hook.sendEmbed({
author: {
name: 'azaresw',
url: 'https://github.com/azaresw',
icon_url: 'https://github.com/azaresw.png',
},
title: 'New Pull Request',
url: 'https://github.com/azaresw/repo/pull/42',
description: 'Fix memory leak in cache layer',
color: 0x5865F2,
fields: [
{ name: 'Branch', value: '`fix/cache-leak`', inline: true },
{ name: 'Status', value: 'Open', inline: true },
{ name: 'Changed', value: '3 files', inline: true },
],
thumbnail: { url: 'https://github.com/azaresw.png' },
footer: { text: 'GitHub β’ devcodes-webhook' },
timestamp: new Date().toISOString(),
});const { SlackWebhook } = require('devcodes-webhook');
const hook = new SlackWebhook('https://hooks.slack.com/services/...');
await hook.sendText('Deployment finished successfully!');await hook.sendBlocks([
{
type: 'header',
text: { type: 'plain_text', text: 'π¨ Alert' },
},
{
type: 'section',
text: { type: 'mrkdwn', text: '*Service:* API Gateway\n*Status:* Down' },
},
]);await hook.send({
text: 'Hello #dev!',
channel: '#dev',
icon_emoji: ':rocket:',
});Works with any service that accepts a JSON webhook body.
const { sendWebhook } = require('devcodes-webhook');
await sendWebhook('https://your-endpoint.com/hook', {
event: 'user.signup',
userId: '123',
});Full type support out of the box.
import { DiscordWebhook, DiscordEmbed, WebhookConfig } from 'devcodes-webhook';
const config: WebhookConfig = { timeout: 5000, retries: 3 };
const hook = new DiscordWebhook('https://discord.com/api/webhooks/...', config);
const embed: DiscordEmbed = {
title: 'Alert',
description: 'Something happened.',
color: 0xED4245,
};
await hook.sendEmbed(embed);| Method | Signature | Description |
|---|---|---|
send |
(payload: DiscordWebhookPayload) => Promise<WebhookResponse> |
Send a raw payload |
sendText |
(content: string, extras?) => Promise<WebhookResponse> |
Send a plain text message |
sendEmbed |
(embed: DiscordEmbed, extras?) => Promise<WebhookResponse> |
Send a single embed |
sendEmbeds |
(embeds: DiscordEmbed[], extras?) => Promise<WebhookResponse> |
Send up to 10 embeds |
| Method | Signature | Description |
|---|---|---|
send |
(payload: SlackWebhookPayload) => Promise<WebhookResponse> |
Send a raw payload |
sendText |
(text: string, extras?) => Promise<WebhookResponse> |
Send a plain text message |
sendBlocks |
(blocks: unknown[], extras?) => Promise<WebhookResponse> |
Send Block Kit blocks |
Generic function that POSTs any JSON payload to a URL.
| Option | Type | Default | Description |
|---|---|---|---|
timeout |
number |
10000 |
Request timeout in ms |
retries |
number |
2 |
Retry attempts on failure |
retryDelay |
number |
500 |
Delay between retries in ms |
interface WebhookResponse {
ok: boolean; // true if status 2xx
status: number; // HTTP status code
}const { DiscordWebhook } = require('devcodes-webhook');
const logs = new DiscordWebhook(process.env.LOG_WEBHOOK_URL);
client.on('guildMemberAdd', async (member) => {
await logs.sendEmbed({
title: 'π New Member',
description: `${member.user.tag} joined **${member.guild.name}**`,
color: 0x57F287,
thumbnail: { url: member.user.displayAvatarURL() },
timestamp: new Date().toISOString(),
footer: { text: `Members: ${member.guild.memberCount}` },
});
});MIT Β© azaresw
Join our Discord for help and updates: discord.gg/ESh2Dp2xX9