All Projects → AfricasTalkingLtd → africastalking-node.js

AfricasTalkingLtd / africastalking-node.js

Licence: MIT license
Official Node.js SDK for Africa's Talking

Programming Languages

javascript
184084 projects - #8 most used programming language
Pug
443 projects
CSS
56736 projects

Projects that are alternatives of or similar to africastalking-node.js

Africastalking Java
Official Java SDK
Stars: ✭ 27 (-76.11%)
Mutual labels:  payment, sms, voice
Twilio Csharp
Twilio C#/.NET Helper Library for .NET Framework 3.5+ and supported .NET Core versions
Stars: ✭ 541 (+378.76%)
Mutual labels:  sms, voice
Twilio Java
A Java library for communicating with the Twilio REST API and generating TwiML.
Stars: ✭ 371 (+228.32%)
Mutual labels:  sms, voice
africastalking.Net
Africa's Talking API Wrapper for C#
Stars: ✭ 16 (-85.84%)
Mutual labels:  voice, ussd
46elks-getting-started
An introduction to the 46elks API with code examples
Stars: ✭ 45 (-60.18%)
Mutual labels:  sms, voice
Vonage Node Sdk
Vonage API client for Node.js. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 323 (+185.84%)
Mutual labels:  sms, voice
Nexmo Node Code Snippets
NodeJS code examples for using Nexmo
Stars: ✭ 36 (-68.14%)
Mutual labels:  sms, voice
vonage-node-code-snippets
NodeJS code examples for using Nexmo
Stars: ✭ 46 (-59.29%)
Mutual labels:  sms, voice
Vonage Dotnet Sdk
Nexmo REST API client for .NET, ASP.NET, ASP.NET MVC written in C#. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 76 (-32.74%)
Mutual labels:  sms, voice
Vonage Java Sdk
Vonage Server SDK for Java. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 75 (-33.63%)
Mutual labels:  sms, voice
Vonage Python Sdk
Vonage Server SDK for Python. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 134 (+18.58%)
Mutual labels:  sms, voice
useful-twilio-functions
A set of useful Twilio Functions.
Stars: ✭ 53 (-53.1%)
Mutual labels:  sms, voice
Vonage Php Sdk Core
Vonage REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 849 (+651.33%)
Mutual labels:  sms, voice
Vonage Go Sdk
A lightweight library to help Go users everywhere integrate with the Vonage APIs. Issues and PRs all really welcome!!
Stars: ✭ 38 (-66.37%)
Mutual labels:  sms, voice
Vonage Ruby Sdk
Vonage REST API client for Ruby. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 203 (+79.65%)
Mutual labels:  sms, voice
tz-mpesa-ussd-push
Vodacom Tanzania USSD Push API Client
Stars: ✭ 18 (-84.07%)
Mutual labels:  payment, ussd
mailslurp-client
Official MailSlurp Client
Stars: ✭ 33 (-70.8%)
Mutual labels:  sms
credit-card-prompt
Credit card prompt with validation and address lookup
Stars: ✭ 13 (-88.5%)
Mutual labels:  payment
Kalkun
Open Source Web based SMS Manager
Stars: ✭ 186 (+64.6%)
Mutual labels:  sms
MockSMS
Android application to create/craft fake sms.
Stars: ✭ 63 (-44.25%)
Mutual labels:  sms

Africa's Talking Node.js SDK

NPM

The wrapper provides convenient access to the Africa's Talking API from applications written for Node.js.

Documentation

Take a look at the API docs here.

Install

You can install the package from npm by running:

$ npm install --save africastalking

Usage

The package needs to be configured with your app username and API key, which you can get from the dashboard.

You can use this SDK for either production or sandbox apps. For sandbox, the app username is ALWAYS sandbox

const credentials = {
    apiKey: 'YOUR_API_KEY',         // use your sandbox app API key for development in the test environment
    username: 'YOUR_USERNAME',      // use 'sandbox' for development in the test environment
};
const Africastalking = require('africastalking')(credentials);

// Initialize a service e.g. SMS
const sms = Africastalking.SMS

// Use the service
const options = {
    to: ['+254711XXXYYY', '+254733YYYZZZ'],
    message: "I'm a lumberjack and its ok, I work all night and sleep all day"
}

// Send message and capture the response or error
sms.send(options)
    .then( response => {
        console.log(response);
    })
    .catch( error => {
        console.log(error);
    });

See example for more usage examples.

Initialization

Initialize the SDK as a requirement by doing require('africastalking')(options). After initialization, you can get instances of offered services as follows:

Services

All methods are asynchronous

All phone numbers use the international format. e.g. +234xxxxxxxx.

ApplicationService

  • fetchApplicationData(): Get app information. e.g. balance

For more information, please read http://docs.africastalking.com/userdata/balance

AirtimeService

  • airtime.send({ recipients }): Send airtime to a bunch of phone numbers.

  • recipients: An array of objects containing the following keys:

    • phoneNumber: Recipient of airtime. REQUIRED.
    • currencyCode: 3-digit ISO format currency code. REQUIRED.
    • amount: Amount to charge. REQUIRED.
  • maxNumRetry: This allows you to specify the maximum number of retries in case of failed airtime deliveries due to various reasons such as telco unavailability. The default retry period is 8 hours and retries occur every 60seconds. For example, setting maxNumRetry=4 means the transaction will be retried every 60seconds for the next 4 hours.OPTIONAL.

  • Example:

    airtime.send({
        recipients: [
            {
                phoneNumber: '+xxxxxxxxxxxx',
                currencyCode: 'KES',
                amount: 90
            },
            {
                phoneNumber: '+xxxxxxxxxxxx',
                currencyCode: 'KES',
                amount: 897
            }
        ],
        maxNumRetry: 3, // Will retry the transaction every 60seconds for the next 3 hours.
    });

For more information, please read http://docs.africastalking.com/airtime/sending

SmsService

  • Send a message to one recipient.

        send({
          to: '+xxxxxxxxxxxx',
          from: 'XYZ LTD',
          message: 'Hello world',
          enqueue: true,
        });
  • Send a message to multiple recipients.

        send({
          to: ['+xxxxxxxxxxxx','+yyyyyyyyyyyy','+zzzzzzzzzzzz'],
          from: 'XYZ LTD',
          message: 'Hello world',
          enqueue: true,
        });
  • Send different messages to different recipients.

        send([
          {
            to: ['+aaaaaaaaaaaa','+bbbbbbbbbbbb','+cccccccccccc'],
            from: 'XYZ LTD',
            message: 'Congratulations team! You have won it!',
            enqueue: true,
          },
          {
            to: '+xxxxxxxxxxxx',
            from: 'XYZ LTD',
            message: 'Congratulations coach! Your team has won!',
            enqueue: true,
          }
        ]);
    • to: Recipient(s) phone number. REQUIRED
    • from: Shortcode or alphanumeric ID that is registered with Africa's Talking account
    • message: SMS content. REQUIRED
    • enqueue: Set to true if you would like to deliver as many messages to the API without waiting for an acknowledgement from telcos.
  • sendPremium({ to, from, message, enqueue, keyword, linkId, retryDurationInHours }): Send premium SMS

    • send() parameters plus:
    • keyword: You premium product keyword
    • linkId: We forward the linkId to your application when the user send a message to your service
    • retryDurationInHours: It specifies the number of hours your subscription message should be retried in case it's not delivered to the subscriber
  • fetchMessages({ lastReceivedId }): Manually retrieve your messages

    • lastReceivedId: "This is the id of the message that you last processed". Defaults to 0
  • fetchSubscription({ shortCode, keyword, lastReceivedId }): Fetch your premium subscription data

    • shortCode: This is the premium short code mapped to your account. REQUIRED
    • keyword: A premium keyword under the above short code and mapped to your account. REQUIRED
    • lastReceivedId: "This is the id of the message that you last processed". Defaults to 0
  • createSubscription({ shortCode, keyword, phoneNumber }): Create a premium subscription

    • shortCode: This is the premium short code mapped to your account. REQUIRED
    • keyword: A premium keyword under the above short code and mapped to your account. REQUIRED
    • phoneNumber: The phone number to be subscribed. REQUIRED

For more information on:

PaymentService

  • cardCheckoutCharge({ productName, paymentCard/checkoutToken, currencyCode, amount, narration, metadata }) Initiate a card checkout.

    • productName: Your payment product. REQUIRED
    • paymentCard: Card to charge.
    • checkoutToken: Token from a previous successful transaction. Replaces paymentCard.
    • currencyCode: 3-digit ISO format currency code. REQUIRED
    • amount: Amount to charge. REQUIRED
    • narration: Checkout description. REQUIRED
    • metadata: Additional info to go with the checkout
  • cardCheckoutValidate({ transactionId, otp }) Validate a card checkout.

    • transactionId: Transaction ID returned on charge request. REQUIRED
    • otp: A user-provided OTP. REQUIRED
  • bankCheckoutCharge({ productName, bankAccount, currencyCode, amount, narration, metadata }) Initiate a bank checkout.

    • productName: Your payment product. REQUIRED
    • bankAccount: Bank account to charge. REQUIRED
    • currencyCode: 3-digit ISO format currency code. REQUIRED
    • amount: Amount to charge. REQUIRED
    • narration: Checkout description. REQUIRED
    • metadata: Additional info to go with the checkout
  • bankCheckoutValidate({ transactionId, otp }) Validate a bank checkout.

    • transactionId: Transaction ID returned on charge request. REQUIRED
    • otp: A user-provided OTP. REQUIRED
  • bankTransfer({ productName, recipients }) Initiate a bank transfer.

    • productName: Your payment product. REQUIRED
    • recipients: A list of banks to transfer to. REQUIRED
  • mobileCheckout({ productName, providerChannel, phoneNumber, currencyCode, amount, metadata }): Initiate mobile checkout.

    • productName: Your payment product. REQUIRED
    • providerChannel: Provider channel to consider when charging.
    • phoneNumber: Mobile wallet to charge. REQUIRED
    • currencyCode: 3-digit ISO format currency code. REQUIRED
    • amount: Amount to charge. REQUIRED
    • metadata: Additional info to go with the checkout
  • mobileB2C({ productName, recipients }): Send mobile money to consumer.

    • productName: Your payment product. REQUIRED
    • recipients: A list of consumers that will receive the money. REQUIRED
  • mobileB2B({ productName, provider, transferType, currencyCode, destinationChannel, destinationAccount, amount, requester, metadata }): Send mobile money to busness.

    • productName: Your payment product. REQUIRED
    • provider: Provider used to process request. Checkout payments.PROVIDER.*. REQUIRED
    • transferType: Checkout payments.TRANSFER_TYPE.*. REQUIRED
    • currencyCode: 3-digit ISO format currency code. REQUIRED
    • destinationChannel: Name or number of channel to receive payment. REQUIRED
    • destinationAccount: Account name used to receive money. REQUIRED
    • amount: Amount to transfer. REQUIRED
    • requester: PhoneNumber through which KPLC will send tokens when using B2B to buy electricity tokens.
    • metadata: Additional info to go with the transfer
  • mobileData(productName, recipients): Send mobile data to customers.

    • productName: Payment product on Africa's Talking. REQUIRED
    • recipients: A list of recipients. Each recipient has:
      • phoneNumber: Customer phone number (in international format). REQUIRED
      • quantity: Mobile data amount. REQUIRED
      • unit: Mobile data unit. Can either be MB or GB. REQUIRED
      • validity: How long the mobile data is valid for. Must be one of Day, Week and Month. REQUIRED
      • metadata: Additional data to associate with the transaction. REQUIRED
  • walletTransfer({ productName, targetProductCode, currencyCode, amount, metadata }) Move money form one payment product to another.

    • productName: Your payment product. REQUIRED
    • targetProductCode: ID of recipient payment product on Africa's Talking. REQUIRED
    • currencyCode: 3-digit ISO format currency code. REQUIRED
    • amount: Amount to transfer. REQUIRED
    • metadata: Additional info to go with the transfer. REQUIRED
  • topupStash({ productName, currencyCode, amount, metadata }) Move money from a Payment Product to an app's stash.

    • productName: Your payment product. REQUIRED
    • currencyCode: 3-digit ISO format currency code. REQUIRED
    • amount: Amount to transfer. REQUIRED
    • metadata: Additional info to go with the transfer. REQUIRED
  • fetchProductTransactions({ productName, filters }): Fetch payment product transactions.

    • productName: Your payment product. REQUIRED

    • filters: Query filters. Includes:

      • pageNumber: Page number to fetch results from. Starts from 1. REQUIRED
      • count: Number of results to fetch. REQUIRED
      • startDate: Start Date to consider when fetching.
      • endDate: End Date to consider when fetching.
      • category: Category to consider when fetching.
      • prodiver: Provider to consider when fetching.
      • status: Status to consider when fetching.
      • source: Source to consider when fetching.
      • destination: Destination to consider when fetching.
      • providerChannel: Provider channel to consider when fetching.
  • findTransaction({ transactionId }): Find a particular transaction.

    • transactionId: Transaction ID returned on charge request. REQUIRED
  • fetchWalletTransactions({ filters }): Fetch wallet transactions.

    • filters: Query filters. Includes:
      • pageNumber: Page number to fetch results from. Starts from 1. REQUIRED
      • count: Number of results to fetch. REQUIRED
      • startDate: Start Date to consider when fetching.
      • endDate: End Date to consider when fetching.
      • categories: Comma delimited list of categories to consider when fetching.
  • fetchWalletBalance(): Fetch your wallet's balance

For more information, please read http://docs.africastalking.com/payments

VoiceService

  • voice.call({ callFrom, callTo }): Initiate a phone call

    • callFrom: Your Africa's Talking issued virtual phone number. REQUIRED
    • callTo: Comma-separated string of phone numbers to call. REQUIRED
    • clientRequestId: Additional information that can be used to tag the call in your callback URL.
  • voice.fetchQuedCalls({ phoneNumber }): Get queued calls

    • phoneNumber: Your Africa's Talking issued virtual phone number. REQUIRED
  • voice.uploadMediaFile({ phoneNumber, url }): Upload voice media file

    • phoneNumber: Your Africa's Talking issued virtual phone number. REQUIRED
    • url: URL to your media file. REQUIRED

Helpers that will construct proper xml to send back to Africa's Taking API when it comes POSTing.

  • Say, Play, GetDigits, Dial, Record, Enqueue, Dequeue, Conference, Redirect, Reject

Remember to send back an HTTP 200.

For more information, please read http://docs.africastalking.com/voice and issue #15

TokenService

  • generateAuthToken(): Generate an auth token to use for authentication instead of an API key.

USSD

For more information, please read http://docs.africastalking.com/ussd

Development

Run all tests:

$ npm install
$ npm test

or on Windows...

$ npm install
$ npm run test-windows

Issues

If you find a bug, please file an issue on our issue tracker on GitHub.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].