Add New Provider
This guide walks you through creating a new provider for sending notifications via your preferred channel in OsmoX.Prerequisites
Before adding a new provider, ensure you have set up the OsmoX development environment by following the Development Setup guide.Implementation Steps
1
Install Dependencies
Install any required npm packages for your provider:
2
Update the Database
Add your provider to the
notify_master_providers table with the configuration template and related details.Then create an entry in notify_providers table with:- Provider configuration details
is_enabledfield set to1
3
Update Channel Types Constant
Add your new channel type in
src/common/constants/notifications.ts:If the provider supports delivery verification, add success/fail states to
ProviderDeliveryStatus. If not, add it to SkipProviderConfirmationChannels.4
Generate Provider Module
Create a new module using NestJS CLI:Move the module from
providers.module.ts to notifications.module.ts:5
Generate Service File
Create the service file:Move the service to your channel-specific module:
6
Implement Service Logic
In your
.service.ts file:- Import modules from the new dependencies
- Create an interface for input data
- Create a constructor for initialization and configuration
- Create a
sendmethod (sendEmail,sendSms, etc.) - Add
getDeliveryStatusmethod if the provider supports verification - Add any helper methods as needed
7
Add DTO for Validation
Create a DTO file at Update
src/modules/notifications/dtos/providers/<channel_type>-data.dto.ts:src/common/decorators/is-data-valid.decorator.ts:8
Create Job Consumer
Create
src/jobs/consumers/notifications/<channel_name>-notification.job.consumer.ts with:- Constructor injecting
Notificationrepository process<ChannelType>NotificationQueuemethodprocess<ChannelType>NotificationConfirmationQueuemethod (if applicable)
9
Update Queue Service
In Add switch cases in
src/modules/notifications/queues/queue.service.ts:Add dependency injection:createWorker:10
Create Migration
Add migration file in
src/database/migrations with format:
<Unix_timestamp>-migrationName.tsImplement both migration.up() and migration.down() methods.11
Add Documentation
Create
docs/channels/<channel_name>.md describing:- Environment variables
- Provider usage
- Sample request body
- Additional information
usage-guide.md to include the new channel.Service File Structure
Best Practices
Error Handling
Always implement proper error handling and update notification status accordingly
Logging
Add comprehensive logging for debugging and monitoring
Configuration
Use
ConfigService.getOrThrow() to ensure required env vars are presentTesting
Write unit tests for your service methods