universal-contact-notifier
v1.0.6
Published
A generic Node.js/TypeScript notifier library to send contact form submissions to Discord via Webhook, with future multi-channel support.
Maintainers
Readme
universal-contact-notifier
A generic Node.js/TypeScript notifier library to send “Contact Form” submissions to messaging channels.
v1.0.0 ships with Discord support; future adapters (Telegram, Slack, SMS, email, etc.) can be added under src/sender/.
- Required fields:
email,message - Optional fields:
title,name,date,extraFields(any key→value),color,username,avatarUrl
Created by Alberto Linde (https://albertolinde.com)
Table of Contents
- Installation
- Configuration
- Project Structure
- API Reference
- Usage Examples
- Publishing to NPM
- Hosting on Git
- Troubleshooting
- License
Installation
npm install universal-contact-notifier
# or
yarn add universal-contact-notifierConfiguration
- Create a Discord Webhook
- In your Discord server → Channel Settings → Integrations → Webhooks → Create Webhook
- Copy the Webhook URL (e.g.
https://discord.com/api/webhooks/...)
- Set
DISCORD_WEBHOOK_URL- Locally: copy
.env.example→.env, paste your Webhook URL - In production: configure
DISCORD_WEBHOOK_URLas an environment variable
- Locally: copy
# .env
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/123456789012345678/your-tokenProject Structure
universal-contact-notifier/
├── package.json
├── tsconfig.json
├── .env.example
├── LICENSE
└── src/
├── colors.ts
├── types.ts
├── errors.ts
├── validation.ts
├── builder.ts
├── sender/
│ ├── index.ts
│ └── discord.ts
└── index.tsAPI Reference
sendContact(channel, options): Promise<void>
- Parameters
channel: currently only'discord'options: seeContactOptions
interface ContactOptions {
email: string; // required
message: string; // required
title?: string; // optional embed title
name?: string; // optional
date?: string; // optional
extraFields?: Record<string,string>; // optional additional fields
color?: ColorName | string; // optional palette key (UPPERCASE) or HEX
username?: string; // optional webhook username override
avatarUrl?: string; // optional webhook avatar URL override
}- Throws
DiscordContactErroron validation or network errors
Usage Examples
import { sendContact, DiscordContactError, COLORS } from 'universal-contact-notifier';
async function main() {
try {
await sendContact('discord', {
email: '[email protected]',
message: 'Hello world!',
title: '🚀 New Inquiry',
name: 'Alice',
date: '2025-06-08T14:30:00Z',
extraFields: { phone: '+1-555-1234' },
color: 'PURPLE', // from COLORS: TEAL, RED, BLUE, GREEN, YELLOW, PURPLE, GRAY
username: 'Contact Bot',
avatarUrl: 'https://example.com/avatar.png'
});
console.log('Notification sent!');
} catch (err) {
if (err instanceof DiscordContactError) {
console.error('Notify failed:', err.message);
} else {
console.error('Unexpected error:', err);
}
}
}
main();Troubleshooting
Missing/invalid
DISCORD_WEBHOOK_URL
Ensure it begins withhttps://discord.com/api/webhooks/....Validation errors
DiscordContactErrorwill explain missingemailormessage.Network/Discord errors
Check embed size limits (fields ≤1024 chars, description ≤4096 chars).Node version
Requires Node ≥18 for built-infetch.
License
This project is licensed under the MIT License. See LICENSE for details.
