This repository contains the code for a multi-channel notification delivery system implemented in Node.js. It supports sending notifications via push notifications, SMS, and email.
- Features
- Prerequisites
- Installation
- Usage
- Demo
- API Endpoint
- Code Structure
- Postman Collection
- Credits
- License
- Send notifications to multiple channels: Web push , SMS, and email.
- Easily extensible to support additional notification channels.
- Built-in validation checks for input data.
- CORS support for handling cross-origin requests.
- Node.js installed on your machine
- Twilio account for sending SMS
- SMTP server for sending email - MailTrap
- Web push server for sending push notifications
-
Clone the repository:
git clone <repository_url>
-
Install dependencies:
npm install
-
Set up environment variables by creating a
.env
file in the root directory and adding the necessary configuration. Use.env.example
as a template
-
Setup Twilio Account to send SMS
-
Setup MailTrap Account to recieve emails
-
Update
.env
fileTWILIO_ACCOUNT_SID , TWILIO_AUTH_TOKEN , TWILIO_PHONE_NUMBER ,EMAIL_USER , EMAIL_PASSWORD , EMAIL_HOST , EMAIL_PORT
-
Start the server:
npm start
-
Run index.html file and click on
Enable Notifications
(acting as client)
- You will see a
Service Worker
running inDeveloper Tools -> Application -> ServiceWorker
[ You will find the endpoint , authKey , p256dhKey (subscription details ) logged to the running service ]
- Use the provided Postman collection to test the API endpoints for sending notifications.
Web-Push Notification
SMS
- URL:
/notify
- Method: POST
- Body: JSON object with the following fields:
message
: The content of the notification.channels
: An array of channels to send the notification to (push
,sms
,email
).targetUsers
: An array of objects containing details of the target users/devices for each channel.
app.js
Main application file handling API requests and routing.pushNotificationService.js
: Service for sending push notifications ( currently sending to the all subscribed clients , but configurable )smsService.js
: Service for sending SMS messages.emailService.js
: Service for sending emails.validation.js
: Module for input validation.
You can import the provided Postman collection to test the API endpoints locally.
- This project uses various libraries and services, including Twilio for SMS, Nodemailer for email, and web-push for push notifications.
This project is licensed under the MIT License.