1.0.1 • Published 9 months ago

nestjs-unifonic v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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

1.0.1

9 months ago

1.0.0

9 months ago