{"_id":"@brvhprince/termii-js","_rev":"7-54b8c5870ab4e978c14a0915b30642e0","name":"@brvhprince/termii-js","dist-tags":{"latest":"3.0.0"},"versions":{"2.0.0":{"name":"@brvhprince/termii-js","version":"2.0.0","keywords":["termii","nodejs","sms","sdk","messaging","otp","verification","verify","message","token"],"author":{"name":"brvhprince","email":"prince.akomea.stu@uenr.edu.gh"},"license":"ISC","_id":"@brvhprince/termii-js@2.0.0","maintainers":[{"name":"pennycodes","email":"wanpeninsula@gmail.com"}],"homepage":"https://github.com/brvhprince/termii-js#readme","bugs":{"url":"https://github.com/brvhprince/termii-js/issues"},"dist":{"shasum":"35b2c80889a3a3969bba0ace5bc239d9437cc6a1","tarball":"https://registry.npmjs.org/@brvhprince/termii-js/-/termii-js-2.0.0.tgz","fileCount":29,"integrity":"sha512-fXEzuSxvkK+OUTiw4rfphDy8ikMmczujnBAW6iFZW1vQvpuCcU07pNnjb1SxAe4a8K+w97dt2VWTOa7AEfsJ4g==","signatures":[{"sig":"MEQCIBSBN3OaxsCU8ssAiJBDXihNp+31rrZIm0yGqMSt/vOZAiABoOKPo3pFzWEOXzgxkx3XK6P7QAmGIqZvSd4iowFG5g==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":87147,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkSV5mACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmocfQ/8DMsQ5LAxVO0v4D7OmMH+nR6ZsqLrHCxdbEdiE39Blk7oz/lc\r\ngWF383+GTle9m7ZsnEVxaLa+L5aiyNEMvHon3rB6jr7Rwn+sdlKCzh/J8pP3\r\nYEb2XZGJr5x5mwN/M1/A8KDC8vgNbJoTJsSxfmSVdVUNfZSqQNUAL7XJFHB0\r\nSI6QOuEoqimL/GzbkBtbE0AAESVgiyGDv+KG8euVgXZaLVDxM0plMnkPR0/l\r\np91EFvkXYq50/zku1BoWsAVPJTFQQTkJ/yMBnyHtcaIlCvTZbIzg7BWfoalU\r\nIBUFwM1W6doB45ztTXT5+MpExxCl73bbk77bxVKRdQyleF1cXpngfPS9BD+D\r\n76JcZKKVg01t32weUcf4h6DvOZbTH09ypsAp0WMEPgmwt7M4auMhNVWTkzTr\r\n4Ud1+SGV+dQy8mCynoJQimnd+GwYpl+jmaOQkga5Vf20jEmurTMBwSt2Z8hd\r\nuV0Zjkd4i1oFok2txsFGJy3UrkMeT1YufImJ2Y0nllIcEZqSFyFj0MwIIlmC\r\nMAw7maJGi+nzUuVpvmcD7KeIRhrCtdCoKOwIyfbVB0u++v9z3iwC97C4lsFC\r\nWuL4MpHYircQURkT51dg8nzBG7CHMAjbwvrblBEviLepiFowDOyfnlfgGwZ5\r\n/5bSW4dLBA0o+X63v3klpYeKpEpQ5ItbodU=\r\n=pSQ9\r\n-----END PGP SIGNATURE-----\r\n"},"main":"lib/index.js","types":"lib/index.d.ts","gitHead":"f764c8b9e09de8c35e0cf2d64bae6fca1e9a4502","private":false,"scripts":{"lint":"tslint -p tsconfig.json","test":"jest -c jestconfig.json","build":"tsc","format":"prettier --write \"src/**/*.ts\" \"src/**/*.js\"","prepare":"npm run build","version":"npm run format && git add -A src","lint:fix":"tslint -p tsconfig.json --fix","preversion":"npm run lint","postversion":"git push && git push --tags","prepublishOnly":"npm test && npm run lint"},"_npmUser":{"name":"pennycodes","email":"wanpeninsula@gmail.com"},"repository":{"url":"git+https://github.com/brvhprince/termii-js.git","type":"git"},"_npmVersion":"8.19.3","description":"JavaScript SDK for Termii Provider","directories":{"lib":"lib"},"_nodeVersion":"16.19.1","dependencies":{"mitt":"^3.0.0","axios":"^1.3.6"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.5.0","tslint":"^6.1.3","ts-jest":"^29.1.0","prettier":"^2.8.8","typescript":"^5.0.4","@types/jest":"^29.5.1","tslint-config-prettier":"^1.18.0"},"_npmOperationalInternal":{"tmp":"tmp/termii-js_2.0.0_1682529894467_0.7485755904190532","host":"s3://npm-registry-packages"}},"3.0.0":{"name":"@brvhprince/termii-js","version":"3.0.0","description":"JavaScript SDK for Termii Provider","main":"lib/index.js","types":"lib/index.d.ts","repository":{"type":"git","url":"git+https://github.com/brvhprince/termii-js.git"},"author":{"name":"brvhprince","email":"prince.akomea.stu@uenr.edu.gh"},"homepage":"https://github.com/brvhprince/termii-js#readme","license":"ISC","private":false,"scripts":{"build":"tsc","format":"biome format --write src __tests__","lint":"biome lint src __tests__","lint:fix":"biome lint --write src __tests__","check":"biome check src __tests__","check:fix":"biome check --write src __tests__","test":"jest -c jestconfig.json","prepare":"npm run build","prepublishOnly":"npm test && npm run lint","preversion":"npm run lint","version":"npm run format && git add -A src","postversion":"git push && git push --tags"},"keywords":["termii","nodejs","sms","sdk","messaging","otp","verification","verify","message","token"],"bugs":{"url":"https://github.com/brvhprince/termii-js/issues"},"devDependencies":{"@biomejs/biome":"2.5.4","@types/jest":"^30.0.0","@types/node":"^22","jest":"^30.4.2","ts-jest":"^29.4.11","ts-node":"^10.9.2","typescript":"~5.9.3"},"dependencies":{"axios":"^1.18.1","mitt":"^3.0.1"},"directories":{"lib":"lib"},"_id":"@brvhprince/termii-js@3.0.0","gitHead":"4f53d800715d7541d396be168fb1c14341d11603","_nodeVersion":"22.18.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-42RH200P1+zYIw5/Rt9nJGkxscsuB1NWU1fbRN2xCU9PKtGaonrkQVp394aUdWwmU2W1OJvN8dLRWJ+6VN7cEQ==","shasum":"037220b0778de03b172b678909a5aad0c78b2772","tarball":"https://registry.npmjs.org/@brvhprince/termii-js/-/termii-js-3.0.0.tgz","fileCount":25,"unpackedSize":110823,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCsy6Q9ijNypjHTHav5NqUzFRL2EjCrODJLQiX8+5PwsAIgTaJ8qrt2iOpU5Qbol7jgeejInF0+I7qqGANT/wxLRjE="}]},"_npmUser":{"name":"pennycodes","email":"wanpeninsula@gmail.com"},"maintainers":[{"name":"pennycodes","email":"wanpeninsula@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/termii-js_3.0.0_1784648200544_0.8968939260430935"},"_hasShrinkwrap":false}},"time":{"created":"2023-04-26T17:24:54.404Z","modified":"2026-07-21T15:36:40.853Z","1.0.0":"2023-04-25T23:37:24.057Z","1.0.1":"2023-04-26T00:23:20.011Z","1.1.0":"2023-04-26T16:56:42.710Z","2.0.0":"2023-04-26T17:24:54.673Z","3.0.0":"2026-07-21T15:36:40.684Z"},"bugs":{"url":"https://github.com/brvhprince/termii-js/issues"},"author":{"name":"brvhprince","email":"prince.akomea.stu@uenr.edu.gh"},"license":"ISC","homepage":"https://github.com/brvhprince/termii-js#readme","keywords":["termii","nodejs","sms","sdk","messaging","otp","verification","verify","message","token"],"repository":{"type":"git","url":"git+https://github.com/brvhprince/termii-js.git"},"description":"JavaScript SDK for Termii Provider","maintainers":[{"name":"pennycodes","email":"wanpeninsula@gmail.com"}],"readme":"![npm (scoped)](https://img.shields.io/npm/v/@brvhprince/termii-js?color=%23FF7B37&style=flat-square)\n![npm](https://img.shields.io/npm/dm/@brvhprince/termii-js?style=flat-square)\n\n![NPM](https://img.shields.io/npm/l/@brvhprince/termii-js?style=flat-square)\n![GitHub last commit](https://img.shields.io/github/last-commit/brvhprince/termii-js?color=%23A4A61D&style=flat-square)\n![GitHub top language](https://img.shields.io/github/languages/top/brvhprince/termii-js?style=flat-square)\n![GitHub repo size](https://img.shields.io/github/repo-size/brvhprince/termii-js)\n\n![GitHub forks](https://img.shields.io/github/forks/brvhprince/termii-js?style=social)\n![GitHub Repo stars](https://img.shields.io/github/stars/brvhprince/termii-js?style=social)\n![GitHub watchers](https://img.shields.io/github/watchers/brvhprince/termii-js?style=social)\n\n![Twitter Follow](https://img.shields.io/twitter/follow/pennycodes?style=social)\n# Termii NodeJs Library\n\n> A Node client library for consuming the  [Termii API](https://www.developers.termii.com/)\n\n## v3.0.0 — breaking changes\n\nThis release targets the Termii **v3** API. If you are upgrading from 2.x, read\nthe [CHANGELOG](CHANGELOG.md) first. The two changes that affect most code:\n\n**Paginated results moved from `data` to `content`.**\n\n```javascript\n// 2.x\nconst { data } = await provider.messaging.list_phonebooks();\n\n// 3.x\nconst { content, totalElements, totalPages } = await provider.messaging.list_phonebooks();\n```\n\nAffects `list_sender_ids`, `list_phonebooks`, `list_campaigns` and\n`get_campaign_history`. `list_contacts` nests its page one level deeper — see\n[Contacts](#contacts-documentation).\n\n**The default base URL is now `https://v3.api.termii.com/api/`.** Base URLs are\naccount-specific; if yours differs, pass it as the third constructor argument.\n\n## Prerequisites\n\nThis project requires NodeJS (version 18 or later) and Yarn.\nVersion 18 is the floor because contact uploads use the global `FormData` and `Blob`.\n[Node](http://nodejs.org/) and [Yarn](https://yarnpkg.com/) are really easy to install.\nTo make sure you have them available on your machine,\ntry running the following command.\n\n```sh\n$ yarn -v && node -v\n1.22.22\nv22.18.0\n```\n\n## Table of contents\n\n- [Termii NodeJs Library](#Termii-NodeJs-Library)\n    - [Prerequisites](#prerequisites)\n    - [Table of contents](#table-of-contents)\n    - [Getting Started](#getting-started)\n    - [Installation](#installation)\n    - [Usage](#usage)\n        - [Import and Initialize](#import-and-initialize-the-library)\n        - [Set Sender ID](#set-a-new-sender-id)\n    - [Resources](#resources)\n        - [Messaging](#messaging-documentation)\n            - [Sender ID](#sender-id--documentation)\n            - [Messages](#messages-documentation)\n            - [Send Message Without Sender ID](#send-message-without-sender-id-documentation)\n            - [Send Message With Template](#send-message-with-template-documentation)\n            - [Send Email Notification](#send-email-notification-documentation)\n            - [Phonebooks](#phonebooks-documentation)\n            - [Contacts](#contacts-documentation)\n            - [Campaigns](#campaigns-documentation)\n        - [Token](#token-documentation)\n          - [Send Token](#send-token-documentation)\n          - [Email Token](#email-token-documentation)\n          - [Send Voice Token](#send-voice-token-documentation)\n          - [Make Voice Call](#make-voice-call-documentation)\n          - [Send In App Token](#send-in-app-token-documentation)\n          - [Verify Token](#verify-token-documentation)\n        - [Insights](#insights-documentation)\n          - [Account Balance](#balance-documentation)\n          - [Phone Number Search](#search-documentation)\n          - [Phone Number Status](#status-documentation)\n          - [Inbox History](#history-documentation)\n        - [Express Middleware](#middleware)\n          - [Verifying Signatures](#verifying-signatures)\n    - [Contributing](#contributing)\n    - [Built With](#built-with)\n    - [Versioning](#versioning)\n    - [Authors](#authors)\n    - [License](#license)\n\n## Getting Started\n\nYou need to create a [Termii account](https://accounts.termii.com/#/register) if you don't have one already,\nto get your API Key, Sender ID and Secret key.\n\n> Termii-js was made for the browser, but works in any JavaScript runtime.\n\n## Installation\n\n**BEFORE YOU INSTALL:** please read the [prerequisites](#prerequisites)\n\n\nTo install and set up the library, run:\n\n```sh\n$ npm install @brvhprince/termii-js\n```\n\nOr if you prefer using Yarn:\n\n```sh\n$ yarn add @brvhprince/termii-js\n```\n\n## Usage\n\n### Import and Initialize the library\n\n\n```javascript\n// using ES6 modules\nimport { Termii } from '@brvhprince/termii-js'\n\n// using CommonJS modules\nconst { Termii } = require(\"@brvhprince/termii-js\");\n\n// Initialize\n\nconst provider = new Termii(\"api_key_here\", \"sender_id\");\n\n// Your account's base URL is shown on your Termii dashboard. Pass it as a third\n// argument when it differs from the default (https://v3.api.termii.com/api/).\nconst custom = new Termii(\"api_key_here\", \"sender_id\", \"https://your.base.url/api/\");\n```\n\n### Set a new Sender Id\n\n```javascript\nprovider.set_sender_id(\"new_sender_id\")\n```\n\n# Resources\nResources available on the API\n\n| Name                                  | Description                                                                                                                                                        |\n|---------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Messaging](#messaging-documentation) | Messaging allows you to send messages across SMS and WhatsApp Channels [Learn More](https://www.developers.termii.com/switch)                                      |\n| [Token](#token-documentation)         | Generate, send and verify one-time-passwords [Learn More](https://www.developers.termii.com/token)                                                                 |\n| [Insights](#insights-documentation)   | Retrieve real-time delivery report of messages sent to customers as well as the status of their contacts  [Learn More](https://www.developers.termii.com/insights) |\n| [Middleware](#middleware)             | Express Middleware to handle webhook requests                                                                                                                      |\n\n\n## Messaging [Documentation](https://www.developers.termii.com/switch)\n\nSend messages to any country in the world across SMS and WhatsApp channel\n\n### Sender ID  [Documentation](https://www.developers.termii.com/sender-id)\n\nA Sender ID is the name or number that identifies the sender of an SMS message\n\n*   **List Sender IDs**\n    ```javascript\n    \n    // returns paginated results of 15 items per page\n    const senderIds = await provider.messaging.list_sender_ids();\n    \n    console.log(senderIds.content);       // the sender IDs\n    console.log(senderIds.totalElements); // total across all pages\n    \n    // get page\n    const nextSenderIds = await provider.messaging.list_sender_ids(2); \n    \n    // filter by name and/or approval status\n    const active = await provider.messaging.list_sender_ids(1, { status: \"active\" });\n    ```\n    \n    > A sender ID must be **approved** before it can send. Requesting one leaves it\n    > `pending`, and sending with a pending ID fails with a `404`.\n\n*   **Request a new sender Id**\n    ```javascript\n    \n    const payload = {\n      // between 3 and 11 characters\n      sender_id: \"Penny\",\n      usecase: \"Send promotional messages\",\n      company: \"Pennycodes\"\n    }\n    \n    const response = await provider.messaging.request_sender_id(payload);\n    \n    console.log(response.code) // ok \n    ```\n\n### Messages [Documentation](https://www.developers.termii.com/messaging)\n\nThis API allows businesses send text messages to their customers across different messaging channels\n\n*   **Send Message**\n    ```javascript\n    \n    const payload = {\n      to: \"233552345567\",\n      sms: \"Hello there, welcome to Termii\"\n    }\n    \n    const response = await provider.messaging.send(payload);\n    \n    console.log(response.code) // ok \n    console.log(response.message_id_str) // prefer this over message_id, which exceeds Number.MAX_SAFE_INTEGER\n    ```\n    \n    The route defaults to `generic`. Pass `channel` to override it:\n    \n    ```javascript\n    import { MessagingChannels } from '@brvhprince/termii-js'\n    \n    await provider.messaging.send({\n      to: \"233552345567\",\n      sms: \"Hello there\",\n      channel: MessagingChannels.DND // dnd | generic | whatsapp | voice\n    });\n    ```\n    \n    > `MessagingChannels.VOICE` automatically sends `type: \"voice\"`, which the\n    > voice route requires.\n    \n*   **Send Bulk Message**\n    ```javascript\n    \n    const payload = {\n      to: [\"23490555546\", \"23423490126999\",\"23490555546\"],\n      sms: \"Hello there, welcome to Termii\"\n    }\n    \n    const response = await provider.messaging.send_bulk(payload);\n    \n    console.log(response.code) // ok \n    ```\n    \n    > Bulk delivery supports only the `dnd` and `generic` channels, and cannot\n    > send `voice`. The types enforce this at compile time.\n\n### Send Message Without Sender ID [Documentation](https://www.developers.termii.com/number)\n\nThis API allows businesses send messages to customers using Termii's auto-generated messaging numbers that adapt to customers location.\n\n```javascript\n\nconst payload = {\n  to: \"233552345567\",\n  sms: \"Hello there, welcome to Termii\"\n}\n\nconst response = await provider.messaging.send_without_sender_id(payload);\n\nconsole.log(response.code) // ok \n```\n\n### Send Message With Template [Documentation](https://www.developers.termii.com/templates)\n\nTemplates API helps businesses set a template for the one-time-passwords (pins) sent to their customers via whatsapp\n\n```javascript\n\nconst payload = {\n  phone_number: \"233552345567\",\n  device_id: \"device_one\",\n  template_id: \"template_one\",\n  data: {\n    product_name: \"Termii\",\n    otp : 120435,\n    expiry_time: \"10 minutes\"\n  }\n}\n\nconst response = await provider.messaging.send_with_template(payload);\n\nconsole.log(response.code) // ok \n```\n\nTemplates can also carry a media object. The `media` object is **required** on\nthis endpoint, unlike `send_with_template`.\n\n```javascript\n\nconst response = await provider.messaging.send_with_template_media({\n  phone_number: \"233552345567\",\n  device_id: \"device_one\",\n  template_id: \"template_one\",\n  data: { product_name: \"Termii\" },\n  media: {\n    url: \"https://example.com/receipt.png\",\n    caption: \"Your receipt\"\n  }\n});\n```\n\n### Send Email Notification [Documentation](https://developers.termii.com/email-product-notification)\n\nDeliver a product notification to a customer via email using a saved template.\n\n```javascript\n\nconst payload = {\n  email: \"customer@example.com\",\n  subject: \"Your order has shipped\",\n  email_configuration_id: \"email_configuration_id_from_dashboard\",\n  template_id: \"template_id\",\n  variables: {\n    order_id: \"1234\",\n    customer_name: \"Ada\"\n  }\n}\n\nconst response = await provider.messaging.send_email_notification(payload);\n\nconsole.log(response.code) // ok\n```\n\n### Phonebooks [Documentation](https://www.developers.termii.com/phonebook)\n\nCreate, view & manage phonebooks using these APIs. Each phonebook can be identified by a unique ID, which makes it easier to edit or delete a phonebook.\n\n* **List Phonebooks**\n\n    ```javascript\n    \n   // returns paginated results of 15 items per page\n    const phonebooks = await provider.messaging.list_phonebooks();\n  \n    console.log(phonebooks.content); // the phonebooks\n  \n     // get page\n    const nextPhonebooks = await provider.messaging.list_phonebooks(2);\n    ```\n  \n* **Create Phonebook**\n\n    ```javascript\n    \n    const payload =  {\n      phonebook_name: \"Royals\",\n      description: \"My royal leads\"  \n  }\n  \n    const response = await provider.messaging.create_phonebook(payload);\n  \n    console.log(response.message) // Phonebook added successfully\n    ```\n  \n* **Update Phonebook**\n\n    ```javascript\n    \n    // takes the id, the new name, and an optional description\n    const response = await provider.messaging.update_phonebook(\n      \"phonebook_id\",\n      \"Premium\",\n      \"My premium leads\"\n    );\n  \n    console.log(response.message) // Phonebook updated successfully\n    ```\n  \n* **Delete Phonebook**\n\n    ```javascript\n    \n    const response = await provider.messaging.delete_phonebook(\"phonebook_id\");\n  \n    console.log(response.message) // Phonebook deleted successfully\n    ```\n\n### Contacts [Documentation](https://www.developers.termii.com/contacts)\n\nContacts API allows you manage (i.e. edit, update, & delete) contacts in your phonebook.\n\n* **List Contacts of Phonebook**\n\n    ```javascript\n    \n   // the page is nested under `data`, alongside the owning phonebook\n    const contacts = await provider.messaging.list_contacts(\"phonebook_id\");\n  \n    console.log(contacts.data.content); // the contacts\n    console.log(contacts.phonebook);    // the phonebook they belong to\n    console.log(contacts.headers);      // column headers\n  \n     // get page\n    const nextContacts = await provider.messaging.list_contacts(\"phonebook_id\", 2);\n    ```\n  \n* **Create Contact**\n\n    ```javascript\n    \n    const payload =  {\n      phone_number: \"556789909\",\n      country_code: \"233\"\n  }\n  \n    const response = await provider.messaging.create_contact(\"phonebook_id\",payload);\n  \n    console.log(response.data.id) // 3647982\n    ```\n  \n* **Upload Contacts from CSV**\n\n    ```javascript\n    import fs from \"node:fs/promises\";\n  \n    const response = await provider.messaging.upload_contacts({\n      file: new Blob([await fs.readFile(\"contacts.csv\")]),\n      filename: \"contacts.csv\",\n      pid: \"phonebook_id\",\n      country_code: \"233\"\n    });\n  \n    console.log(response.message) // Your list is being uploaded in the background...\n    ```\n  \n    > The upload is processed asynchronously, so contacts do not appear in\n    > `list_contacts` immediately.\n  \n* **Delete Contact**\n\n    ```javascript\n    \n    const response = await provider.messaging.delete_contact(\"contact_id\");\n  \n    console.log(response.message) // Contact deleted successfully\n    ```\n\n### Campaigns [Documentation](https://www.developers.termii.com/campaign)\n\nCampaign API allows you to view, manage and send a campaign to a phonebook.\n\n* **List Campaigns**\n\n    ```javascript\n    \n   // returns paginated results of 15 items per page\n    const campaigns = await provider.messaging.list_campaigns();\n  \n    console.log(campaigns.content); // the campaigns\n  \n     // get page\n    const nextCampaigns = await provider.messaging.list_campaigns(2);\n    ```\n  \n* **Fetch Campaign History**\n\n    ```javascript\n    \n   // returns paginated results of 15 items per page\n    const history = await provider.messaging.get_campaign_history(\"campaign_id\");\n  \n     // get page\n    const nextHistory = await provider.messaging.get_campaign_history(\"campaign_id\", 2);\n    ```\n  \n* **Send Campaign**\n\n    ```javascript\n    \n    const payload =  {\n      phone_number: \"556789909\",\n      country_code: \"233\",\n      message: \"Hello, Welcome to Termii\",\n      phonebook_id: \"phonebook_id\",\n      campaign_type: \"personalized\"\n  }\n  \n    const response = await provider.messaging.send_campaign(payload);\n  \n    console.log(response.message) // Your campaign has been scheduled\n    ```\n  \n* **Retry Campaign**\n\n    ```javascript\n    \n    const response = await provider.messaging.retry_campaign(\"campaign_id\");\n  \n    console.log(response.message) // Campaign queued\n    ```\n\n\n## Token [Documentation](https://www.developers.termii.com/token)\n\nToken allows businesses generate, send and verify one-time-passwords.\n\n### Send Token [Documentation](https://www.developers.termii.com/send-token)\n\nThe send token API allows businesses trigger one-time-passwords (OTP) across any available messaging channel on Termii.\n\n```javascript\n\nconst payload = {\n  to: \"23490126727\",\n  pin_length: 6,\n  message_text: \"Your pin is\"\n}\n\nconst response = await provider.token.send_token(payload);\n\nconsole.log(response.pinId) // 29ae67c2-c8e1-4165-8a51-8d3d7c298081\n```\n\n### Email Token [Documentation](https://www.developers.termii.com/email-token)\n\nThe email token API enables you to send one-time-passwords to an email address\n\n```javascript\n\nconst payload = {\n  email_address: \"test@termii.com\",\n  code: \"092471\",\n  email_configuration_id: \"email_configuration_id_from_dashboard\"\n}\n\nconst response = await provider.token.email_token(payload);\n\nconsole.log(response.code) // ok\n```\n\n### Send Voice Token [Documentation](https://www.developers.termii.com/voice-token)\n\nThe voice token API enables you to generate and trigger one-time passwords (OTP) through the voice channel to a phone number\n\n```javascript\n\nconst payload = {\n  phone_number: \"23490126727\"\n}\n\nconst response = await provider.token.send_voice_token(payload);\n\nconsole.log(response.pinId) // 29ae67c2-c8e1-4165-8a51-8d3d7c298081\n```\n\n### Make Voice Call [Documentation](https://www.developers.termii.com/voice-call)\n\nThe voice call API enables you to send messages from your application through our voice channel to a phone number\n\n```javascript\n\nconst payload = {\n  phone_number: \"23490126727\",\n  code: 1223\n}\n\nconst response = await provider.token.make_voice_call(payload);\n\nconsole.log(response.pinId) // 29ae67c2-c8e1-4165-8a51-8d3d7c298081\n```\n\n### Send In App Token [Documentation](https://www.developers.termii.com/in-app-token)\n\nThis API returns OTP codes in JSON format which can be used within any web or mobile app.\n\n```javascript\n\nconst payload = {\n  phone_number: \"23490126727\",\n  pin_length: 6\n}\n\nconst response = await provider.token.send_in_app_token(payload);\n\nconsole.log(response.status) // success\nconsole.log(response.data.otp) // 522726\n```\n\n### Verify Token [Documentation](https://www.developers.termii.com/verify-token)\n\nVerify token API, checks tokens sent to customers and returns a response confirming the status of the token.\n\n```javascript\n\nconst payload = {\n  pin_id: \"pin_id\",\n  pin: 123456\n}\n\nconst response = await provider.token.verify_token(payload);\n\nconsole.log(response.verified) // True\n```\n\n\n## Insights [Documentation](https://www.developers.termii.com/insights)\n\nRetrieve real-time delivery report of messages sent to customers as well as the status of their contacts\n\n### Balance [Documentation](https://www.developers.termii.com/balance)\nThe Balance API returns your total balance and balance information from your wallet, such as currency.\n\n```javascript\n    \nconst balance = await provider.insights.balance();\n\nconsole.log(balance.balance) // 19.85\n```\n\n### Search [Documentation](https://www.developers.termii.com/search)\nThe search API allows businesses verify phone numbers and automatically detect their status as well as current network\n\n```javascript\n\nconst response = await provider.insights.search_phone_number(\"phone_number\");\n\nconsole.log(response.status) // DND blacklisted\n```\n\n### Status [Documentation](https://www.developers.termii.com/status)\nThe status API allows businesses to detect if a number is fake or has ported to a new network.\n\n```javascript\n\nconst payload = {\n  phone_number: \"523353245594\",\n  country_code: \"GH\"\n}\nconst response = await provider.insights.status_phone_number(payload);\n\nconsole.log(response.result) // {@returns typeof array}\n```\n\n### History [Documentation](https://www.developers.termii.com/history)\nThis Inbox API returns reports for messages sent across the sms, voice & whatsapp channels.\n\n```javascript\n\nconst inbox = await provider.insights.history();\n\nconsole.log(inbox) // {@returns typeof array}\n```\n\n## Middleware\n\nExpress Middleware to handle Webhook Events\n\nAdd your webhook url in your [Termii Developer Console](https://accounts.termii.com/#/account/webhook/config)\n\n```javascript\n// using ES6 modules\nimport { Webhook } from '@brvhprince/termii-js'\n\n// using CommonJS modules\nconst { Webhook } = require(\"@brvhprince/termii-js\");\n\n// Initialize\n\nconst provider = new Webhook(\"secret_key\");\n\n//Inbound-Message Received\n\nprovider.on(\"inbound\", data => {\n  // Act\n  console.log(\"Here We are!\");\n});\n\n\n//Outbound Message (Delivery Report)\n\nprovider.on(\"outbound\", data => {\n  // Act\n  console.log(\"Here We are!\");\n});\n\n\n//Device offline Notification\n\nprovider.on(\"device_status\", data => {\n  // Act\n  console.log(\"Here We are!\");\n});\n\n\n// Hooks with Express\napp.post(\"/my/webhook/url\", provider.middleware);\n\n```\n\n### Verifying signatures\n\nTermii signs the **raw** request bytes. Re-serialising a parsed body can reorder\nkeys and change whitespace, producing a hash that never matches. Capture the raw\nbuffer so the middleware can verify against exactly what was signed:\n\n```javascript\napp.use(\n  express.json({\n    verify: (req, res, buf) => {\n      req.rawBody = buf;\n    },\n  })\n);\n```\n\nWithout this the library falls back to `JSON.stringify(request.body)`, which only\nmatches when key order happens to round-trip unchanged. Events whose signature\ndoes not verify are silently ignored.\n\n## Contributing\n\nPlease do :heart:\n\n## Built With\n\n* [TypeScript](https://www.typescriptlang.org/)\n\n## Versioning\n\nI use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/brvhprince/termii-js/tags).\n\n## Authors\n\n* **Prince Takyi** - *Initial work* - [Prince Takyi Akomea](https://github.com/brvprince)\n\nSee also the list of [contributors](https://github.com/brvhprince/termii-js/contributors) who participated in this project.\n\n## License\n\n[ISC License](LICENSE) © Prince Takyi Akomea\n","readmeFilename":"README.md"}