npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

verimor-api-sdk

v2.0.2

Published

A NodeJS SDK for the Verimor API

Downloads

17

Readme

Verimor SMS SDK

Source: GitHub Repository Author: Bilal ATLI

A TypeScript SDK for the Verimor SMS API, providing an easy and efficient way to integrate SMS, IYS consent management, and other functionalities into your applications.


Table of Contents


Features

  • Comprehensive API Coverage: Access all endpoints provided by the Verimor SMS API.
  • Unified Client Interface: Simplified usage through a single Verimor client.
  • IYS Integration: Manage IYS consents and campaigns seamlessly.
  • Blacklist Management: Easily add, retrieve, and remove blacklisted numbers.
  • Proxy Support: Configure proxy settings for network routing.
  • TypeScript Support: Fully typed interfaces and enums for robust development.
  • Error Handling: Consistent and informative error responses.

Installation

Install the SDK via npm:

npm install verimor-api-sdk

Getting Started

Initializing the Client

Import the Verimor client and initialize it with your API credentials:

import { Verimor } from 'verimor-api-sdk';

const client = new Verimor('your_username', 'your_password');

Usage

Sending SMS Messages

Send SMS messages to one or multiple recipients.

const smsRequest = {
  msg: 'Hello, this is a test message.',
  dest: ['905xxxxxxxxx', '905yyyyyyyyy'],
  iys_recipient_type: 'BIREYSEL',
};

client.smsApi
  .sendSms(smsRequest)
  .then((response) => {
    console.log('SMS sent successfully:', response);
  })
  .catch((error) => {
    console.error('Error sending SMS:', error);
  });

Calculating SMS Credits

Calculate the number of SMS credits required for a message based on its length and character set.

const message = 'Hello, this is a test message.';
const creditsRequired = client.smsUtils.calculateSmsCredits(message);
console.log(`Credits required: ${creditsRequired}`);

Checking Account Balance

Retrieve your account's current SMS credit balance.

client.accountApi
  .getBalance()
  .then((balance) => {
    console.log('Account balance:', balance);
  })
  .catch((error) => {
    console.error('Error fetching balance:', error);
  });

Retrieving Message Status

Get the delivery status of your sent messages.

client.messageApi
  .getMessageStatus({ id: 20121 })
  .then((statuses) => {
    statuses.forEach((status) => {
      console.log(`Message ID: ${status.message_id}, Status: ${status.status}`);
    });
  })
  .catch((error) => {
    console.error('Error fetching message status:', error);
  });

Fetching Inbox Messages

Retrieve SMS messages received in your account's inbox.

client.inboxApi
  .getInboxMessages('2023-01-01T09:00:00', '2023-01-01T12:00:00')
  .then((messages) => {
    messages.forEach((message) => {
      console.log(`From: ${message.source_addr}, Message: ${message.content}`);
    });
  })
  .catch((error) => {
    console.error('Error fetching inbox messages:', error);
  });

Blacklist Management

Adding Numbers to the Blacklist

client.blacklistApi
  .addNumbersToBlacklist(['905444876543', '905335876543'])
  .then((response) => {
    console.log('Numbers added to blacklist:', response);
  })
  .catch((error) => {
    console.error('Error adding numbers to blacklist:', error);
  });

Fetching Blacklisted Numbers

client.blacklistApi
  .getBlacklistedNumbers()
  .then((data) => {
    data.records.forEach((record) => {
      console.log(`Blacklisted Number: ${record.phone}, Source: ${record.source}`);
    });
  })
  .catch((error) => {
    console.error('Error fetching blacklisted numbers:', error);
  });

Deleting Numbers from the Blacklist

client.blacklistApi
  .deleteNumbersFromBlacklist(['905444876543', '905335876543'])
  .then((response) => {
    console.log('Numbers removed from blacklist:', response);
  })
  .catch((error) => {
    console.error('Error removing numbers from blacklist:', error);
  });

IYS Integration

Manage IYS consents and campaigns.

Sending IYS Consents

import {
  IysConsentType,
  IysConsentSource,
  IysConsentStatus,
  IysRecipientType,
} from 'verimor-api-sdk';

const consents = [
  {
    type: IysConsentType.MESSAGE,
    source: IysConsentSource.WEB,
    status: IysConsentStatus.APPROVED,
    recipient_type: IysRecipientType.INDIVIDUAL,
    consent_date: '2022-04-14T13:30:30',
    recipient: '905311234567',
  },
];

client.iysApi
  .sendIysConsents('BASLIGIM', consents)
  .then((campaignId) => {
    console.log('IYS consents sent, campaign ID:', campaignId);
  })
  .catch((error) => {
    console.error('Error sending IYS consents:', error);
  });

Fetching IYS Campaigns

client.iysApi
  .getIysCampaigns()
  .then((data) => {
    data.records.forEach((campaign) => {
      console.log(`Campaign ID: ${campaign.id}, Source: ${campaign.source}`);
    });
  })
  .catch((error) => {
    console.error('Error fetching IYS campaigns:', error);
  });

Fetching IYS Consent Reports

const campaignId = 1234;

client.iysApi
  .getIysConsentReports(campaignId)
  .then((report) => {
    console.log('IYS consent report:', report);
  })
  .catch((error) => {
    console.error('Error fetching IYS consent report:', error);
  });

Advanced Configuration

Proxy Settings

If you need to route API requests through a proxy server, you can configure proxy settings when initializing the client.

import { Verimor, ProxyConfig } from 'verimor-api-sdk';

const proxyConfig: ProxyConfig = {
  host: 'proxy.example.com',
  port: 3128,
  auth: {
    username: 'proxyUser',
    password: 'proxyPass',
  },
};

const client = new Verimor('your_username', 'your_password', proxyConfig);

Error Handling

All API methods throw an ErrorResponse if the API call fails. You can catch these errors to handle them appropriately.

client.smsApi
  .sendSms(smsRequest)
  .catch((error) => {
    if (error instanceof ErrorResponse) {
      console.error('API Error:', error.message);
      console.error('Error Code:', error.code);
      console.error('Detailed Errors:', error.errors);
    } else {
      console.error('Unexpected Error:', error);
    }
  });

License

This project is licensed under the MIT License.