Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
africastalking
Advanced tools
The wrapper provides convenient access to the Africa's Talking API from applications written for Node.js.
Take a look at the API docs here.
You can install the package from npm by running:
$ npm install --save africastalking
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.
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
Application Service : AfricasTalking.APPLICATION
All methods are asynchronous
All phone numbers use the international format. e.g. +234xxxxxxxx
.
SMS
send({ to, senderId, message, enqueue })
: Send an SMS to one or more phone numbers
send([{ to, senderId, message, enqueue }])
: Send multiple SMSes to one or more phone numbers
to
: Recipient(s) phone number. Can either a single phone number or an array of phone numbers REQUIRED
senderId
: Shortcode or alphanumeric ID that is registered with Africa's Talking accountmessage
: 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
keyword
: You premium product keywordlinkId
: We forward the linkId
to your application when the user send a message to your serviceretryDurationInHours
: It specifies the number of hours your subscription message should be retried in case it's not delivered to the subscriberfetchMessages({ 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:
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
.
findTransactionStatus(transactionId)
: Find the status of a given airtime transaction.
transactionId
: ID of the transaction you would like to find.For more information, please read https://developers.africastalking.com/docs/airtime/sending
MobileData
send({ productName, recipients })
productName
: This is the application's product name.recipients
: An array of objects containing the following keys:
phoneNumber
: Recipient of the mobile data. REQUIRED
.quantity
: a numeric value for the amount of mobile data. It is based on the available mobile data package(see "Bundle Package" column of mobile data pricing). REQUIRED
.unit
: The units for the specified data quantity, the format is: MB
or GB
. It is based on the available mobile data package(see "Bundle Package" column of mobile data pricing). REQUIRED
.validity
: The period of the data bundle’s validity this can be Day
, Week
, BiWeek
, Month
, or Quarterly
. It is based on the available mobile data package (see "Validity" column of mobile data pricing). REQUIRED
.metadata
: A JSON object of any metadata that you would like us to associate with the request. OPTIONAL
.findTransaction({ transactionId })
: Find a mobile data transaction
fetchWalletBalance()
: Fetch a mobile data product balance
For more information, please read the https://developers.africastalking.com/docs/data/overview
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.fetchQuedCalls({ phoneNumber })
: Get queued calls
phoneNumber
: Your Africa's Talking issued virtual phone number. REQUIRED
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 comesPOST
ing.
Say
, Play
, GetDigits
, Dial
, Record
, Enqueue
, Dequeue
, Conference
, Redirect
, Reject
Remember to send back an HTTP 200.
For more information, please read https://developers.africastalking.com/docs/voice/overview and issue #15
USSD
For more information, please read https://developers.africastalking.com/docs/ussd/overview
Token
generateAuthToken()
: Generate an auth token to use for authentication instead of an API key.Insights
checkSimSwapState([phoneNumbers])
: Check the sim swap state of a given [set of ] phone number(s).Application
fetchApplicationData()
: Get app information. e.g. balanceFor more information, please read https://developers.africastalking.com/docs/application
Run all tests:
$ npm install
$ # add credentials AT_APP_API_KEY, AT_APP_USERNAME and TEST_PHONENUMBER to .env
$ npm test
or on Windows...
$ npm install
$ # add credentials AT_APP_API_KEY, AT_APP_USERNAME and TEST_PHONENUMBER to .env
$ npm run test-windows
If you find a bug, please file an issue on our issue tracker on GitHub.
FAQs
Official AfricasTalking node.js API wrapper
We found that africastalking demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.