Socket
Socket
Sign inDemoInstall

nestjs-unifonic

Package Overview
Dependencies
1
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nestjs-unifonic

An API wrapper of Unifonic for Nest.js


Version published
Maintainers
1
Install size
2.14 MB
Created

Readme

Source

Nest Logo

A Unifonic API wrapper for Nest.js

build status npm version miniziped size Downloads MIT licensed GitHub Repo stars

Implementing the UnifonicModule from this package you gain access to Unifonic services through dependency injection with minimal setup.

Note: Only SMS APIs are covered currently. Other Unifonic services are intended for future releases. Meanwhile, you're welcome to contribute for these.

Installation

$ npm install --save nestjs-unifonic
$ yarn add nestjs-unifonic

Getting Started

To use Unifonic client we need to register module for example in app.module.ts

import { UnifonicModule } from "nestjs-unifonic";

@Module({
  imports: [
    UnifonicModule.forRoot({
      appSid: process.env.UNIFONIC_APP_SID,
      senderId: process.env.UNIFONIC_SENDER_ID,
    }),
  ],
})
export class AppModule {}

If you are using the @nestjs/config package from nest, you can use the ConfigModule using the forRootAsync() function to inject your environment variables like this in your custom module:

import { UnifonicModule } from "nestjs-unifonic";

@Module({
  imports: [
    UnifonicModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        appSid: configService.get("UNIFONIC_APP_SID"),
        senderId: configService.get("UNIFONIC_SENDER_ID"),
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

Example usage in service.

import { UnifonicService } from "nestjs-unifonic";

@Injectable()
export class AppService {
  public constructor(private readonly unifonicService: UnifonicService) {}

  async sendSMS() {
    return await this.unifonicService.SendMessage(phoneNumber, body);
  }
}

Following methods are available currently:

/**
   * Send text message, if timeScheduled given than it will be a Scheduled message.
   * @param recipient Required - Destination mobile number, mobile numbers must be in international format without 00 or + Example: (4452023498)
   * @param body Required - Message body supports both English and unicodes characters, concatenated messages is supported
   * @param timeScheduled Optional - Schedule send messages, in the following format yyyy-mm-dd HH:mm:ss
   * @param correlationId Optional - Is a unique identifier value that is attached to requests and messages
   */
  SendMessage(
    recipient: string,
    body: string,
    timeScheduled?: string,
    correlationId?: string
  ): Promise<UnifonicSmsResponse>;
  /**
   * Cancel previously scheduled message. If messageId is given,
   * then only that scheduled message is canceled, otherwise all messages are
   * cancelled that have been scheduled previously.
   * @param messageId Optional - A unique ID that identifies a message
   */
  StopScheduledMessage(messageId?: string): Promise<UnifonicSmsResponse>;
  /**
   * Get details of previously scheduled messages.
   */
  GetScheduledMessages(): Promise<UnifonicSmsResponse>;
  /**
   * Get the status details of a previously sent messages. Optional parameters working as search filters could be specified.
   * @param messageId Optional - A unique ID that identifies a message
   * @param senderId Optional - The Sender ID to send from, App default SenderID is used unless else stated
   * @param recipient Optional - Destination mobile number, mobile numbers must be in international format without 00 or + Example: (4452023498)
   * @param dateFrom Optional - The start date for the report time interval, date format should be yyyy-mm-dd
   * @param dateTo Optional - The end date for the report time interval, date format should be yyyy-mm-dd
   * @param correlationId Optional - Is a unique identifier value that is attached to requests and messages
   */
  GetPreviousMessages(
    messageId?: string,
    senderId?: string,
    recipient?: string,
    dateFrom?: string,
    dateTo?: string,
    correlationId?: string
  ): Promise<UnifonicSmsResponse>;

Author

License

MIT © sheikh566

Keywords

FAQs

Last updated on 26 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc