0.6.7 • Published 8 days ago

africastalking v0.6.7

Weekly downloads
2,957
License
MIT
Repository
github
Last release
8 days ago

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 options = {
    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')(options);

// Initialize a service e.g. SMS
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 methoods 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

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

SmsService

  • send({ to, from, message, enqueue }): Send a message

    • to: Recipients 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, checkoutToken }): 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
    • checkoutToken: This is a token used to validate the subscription request. 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, 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
    • 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 Daily, Weekly and Monthly. 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: Phone number to dial. REQUIRED
  • 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

  • createCheckoutToken(phoneNumber): Create a new checkout token.

  • 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.

0.6.7

8 days ago

0.7.0-beta.0

8 days ago

0.7.0-beta.1

8 days ago

0.6.6

3 months ago

0.6.3

7 months ago

0.6.5

5 months ago

0.6.4

5 months ago

0.6.2

1 year ago

0.5.8

1 year ago

0.5.9

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.7

1 year ago

0.5.6

1 year ago

0.5.5-rc2

2 years ago

0.5.5-rc1

2 years ago

0.5.5

2 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.7

4 years ago

0.4.6

4 years ago

0.4.5-beta.1

4 years ago

0.4.5-beta.0

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0-beta.0

5 years ago

0.4.0

5 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

1.0.0-alpha.3

6 years ago

1.0.0-alpha.2

6 years ago

1.0.0-alpha.1

6 years ago

1.0.0-alpha

6 years ago

0.1.0

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1-b

8 years ago

0.0.1-a

8 years ago

0.0.1

8 years ago