# nestjs-unifonic

> An API wrapper of Unifonic for Nest.js

Latest version **1.0.1** (published 2023-08-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install nestjs-unifonic
pnpm add nestjs-unifonic
yarn add nestjs-unifonic
bun add nestjs-unifonic
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-08-26 |
| First published | 2023-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 23.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Sheikh Abdullah |
| Maintainers | sheikh566 |
| Keywords | unifonic, nestjs, sms, unifonic-nestjs, sdk, client |

## Links

- npm: https://www.npmjs.com/package/nestjs-unifonic
- Repository: https://github.com/Sheikh566/nestjs-unifonic
- Homepage: https://github.com/Sheikh566/nestjs-unifonic#readme
- Issues: https://github.com/Sheikh566/nestjs-unifonic/issues
- npm.io page: https://npm.io/package/nestjs-unifonic

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^1.4.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2023-08-26
- 1.0.0 — 2023-07-30

## README

<p align="center">
  <a href="https://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

<p align="center">A <a href="https://www.unifonic.com/" target="_blank">Unifonic</a> API wrapper for Nest.js</p>

[![build status](https://img.shields.io/github/workflow/status/sheikh566/nestjs-unifonic/Github%20CI%20-%20Build%20Status%20and%20Test%20Coverage)](https://github.com/wellyshen/use-places-autocomplete/actions?query=workflow%3ACI)
[![npm version](https://img.shields.io/npm/v/nestjs-unifonic)](https://www.npmjs.com/package/nestjs-unifonic)
[![miniziped size](https://badgen.net/bundlephobia/minzip/nestjs-unifonic)](https://bundlephobia.com/result?p=nestjs-unifonic)
[![Downloads](https://badgen.net/bundlephobia/minzip/nestjs-unifonic)](https://img.shields.io/npm/dt/nestjs-unifonic.svg?maxAge=3600)
[![MIT licensed](https://img.shields.io/github/license/sheikh566/nestjs-unifonic)](https://raw.githubusercontent.com/sheikh566/nestjs-unifonic/master/LICENSE)
![GitHub Repo stars](https://img.shields.io/github/stars/sheikh566/nestjs-unifonic)

Implementing the `UnifonicModule` from this package you gain access to Unifonic services through dependency injection with minimal setup.

<b>Note: Only SMS APIs are covered currently. Other Unifonic services are intended for future releases. Meanwhile, you're welcome to contribute for these.</b>

## Installation

```bash
$ npm install --save nestjs-unifonic
```

```bash
$ yarn add nestjs-unifonic
```

## Getting Started

To use Unifonic client we need to register module for example in app.module.ts

```typescript
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:

```typescript
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.

```typescript
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:

```typescript
/**
   * 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

- Sheikh Abdullah: [GitHub](https://github.com/sheikh566), [Twitter](https://twitter.com/Abdullah_Oye), [LinkedIn](https://linkedin.com/in/sheikhabdullah)

## License

MIT © sheikh566

---
_Source: https://npm.io/package/nestjs-unifonic · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
