0.0.4 • Published 1 year ago

@aryans_web/backend-toolkit v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

AlertClient

A TypeScript-based alert client for sending notifications via SMS, Email, and WhatsApp using different providers.

🚀 Features

  • Supports multiple providers for SMS, Email, and WhatsApp.
  • Fully typed with TypeScript for safety and autocompletion.
  • Uses a provider map for extensibility.
  • Works with Exotel, AWS SES, and VFirst (easily extendable).

📦 Installation

npm install @aryans_web/alert-client

or

yarn add @aryans_web/alert-client

🛠️ Usage

1️⃣ Initialize the Alert Client

import AlertClient from '@aryans_web/alert-client'

const client = AlertClient<'sms' | 'email' | 'whatsapp'>({
	sms: { provider: 'exotel', publishKey: 'your-key' },
	email: {
		provider: 'SES',
		apiKey: 'your-api-key',
		url: 'https://email-api.com'
	},
	whatsapp: { provider: 'vfirst', publishKey: 'your-key' }
})

2️⃣ Send Alerts

Send an SMS

client.sms({ numbers: ['1234567890'], message: 'Hello!' }).then(console.log)

Send an Email

client
	.email({
		from: 'no-reply@example.com',
		to: ['recipient@example.com'],
		subject: 'Test Email',
		html: '<h1>Hello</h1>'
	})
	.then(console.log)

Send a WhatsApp Message

client
	.whatsapp({ numbers: ['1234567890'], message: 'Hello on WhatsApp!' })
	.then(console.log)

3️⃣ AWS SNS Publisher

Publish an SNS Message

import { snsPublisher } from '@aryans_web/alert-client'

snsPublisher({
	topicArn: 'arn:aws:sns:us-east-1:123456789012:MyTopic',
	message: 'Hello, this is an SNS message!'
}).then(console.log)

4️⃣ Make HTTP Requests

Send a Custom HTTP Request

import { makeRequest } from '@aryans_web/alert-client'

makeRequest({
	url: 'https://api.example.com/data',
	method: 'POST',
	headers: { 'Content-Type': 'application/json' },
	body: JSON.stringify({ key: 'value' })
}).then(console.log)

🤝 Contributing

  1. Fork the repo
  2. Create a new branch (git checkout -b feature-name)
  3. Make changes and commit (git commit -m 'Add new feature')
  4. Push to the branch (git push origin feature-name)
  5. Open a Pull Request

📜 License

MIT License © Aryan Maurya