Logo Lanfrica

AfricasTalkingLtd/africastalking-node.js

Domain:

digital infrastructure

Record type:

software
Creator:
Afr
Host:
Official Node.js SDK for Africa's Talking # Africa's Talking Node.js SDK > 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: ```bash $ 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` ```javascript 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: - SMS Service : `AfricasTalking.SMS` - Airtime Service : `AfricasTalking.AIRTIME` - Mobile Data Service : `AfricasTalking.MOBILE_DATA` - Voice Service : `AfricasTalking.VOICE` - USSD : USSD API - Token Service : `AfricasTalking.TOKEN` - Insights : `AfricasTalking.INSIGHTS` - WhatsApp : `AfricasTalking.WHATSAPP` - Application Service : `AfricasTalking.APPLICATION` ## Services All methods are asynchronous All phone numbers use the international format. e.g. `+234xxxxxxxx`. ### `SMS` - `send({ to, senderId, message, enqueue })`: Send an SMS …