africastalkingltd / africastalking-node.js Goto Github PK
View Code? Open in Web Editor NEWOfficial Node.js SDK for Africa's Talking
Home Page: https://developers.africastalking.com
License: MIT License
Official Node.js SDK for Africa's Talking
Home Page: https://developers.africastalking.com
License: MIT License
Need a demo of a callback url in action, Im not sure I understand how the Callback URL works in node. The docs only have one demo and its in PHP only.
Maybe we can set a response of 200 when replying; without this, the AT API retries to send a DLR or message to US even when we received; but didn't acknowledge.
The AfricasTalking.fetchAccount() call seems to work on the sandbox, but returns a 401 error on production apps. I think it's due to the header being apiKey
instead of Apikey
(lib/index.js
line 77)
Line 21 of airtime.js in the lib folder of the npm package has a bug, or rather the code in the said line 21 cannot work with the code on the documentation.
Contributors to the AfricaIsTalking API would benefit from having clear and comprehensive guidelines on how to contribute effectively to the project. Currently, there is no contribution guide available, making it challenging for newcomers to get started and for existing contributors to follow best practices consistently.
We propose creating a Contribution Guide for the AfricaIsTalking API. This guide will provide step-by-step instructions and best practices for contributing to the project. It should cover topics such as:
A well-structured contribution guide will have several advantages:
Onboarding New Contributors: Newcomers will find it easier to understand the project's workflow and coding standards, reducing the barrier to entry.
Consistency: Contributors will follow a consistent process when submitting contributions, making it easier for maintainers to review and merge changes.
Improved Code Quality: By providing guidelines for writing code and running tests, we can ensure that contributions meet the project's quality standards.
Community Growth: A clear contribution guide can attract more contributors, fostering a healthy and active open-source community.
Acceptance Criteria:
CONTRIBUTING.md
in the project repository.CONTRIBUTING.md
file.Additional Information:
We believe that providing a contribution guide will greatly enhance the development experience for all contributors and help the AfricaIsTalking API project thrive. Your input and contributions to creating this guide are highly appreciated.
Please feel free to discuss and offer suggestions related to this issue. Thank you for your support and dedication to the project!
Hello, I would like to use the airtime API but noticed it's not yet implemented. I would like to add the implementation and make a pull request if you don't mind.
I'm going to implement the airtime.send(options)
as shown in the repository doc.
Do you have any coding guide or convention I ought to follow?
It would be amazing if we have typescript support for the nodejs sdk, currently it doesn't have the support for nodejs
Hello, i really wanna learn to use your api, but i cant get over this one stubborn error. what i'm i doing wrong?
the voice helpers are very interesting; what approach do we take? plain xml response? or command to construct xml ? The helpers will be great, this will make voice so easy ๐
voice.say("X is a letter! It's not a word")
Here the approach is to wrap say
around root xml response - what of nested commands? and attributes, how to create the xml response?
Of course this is for incoming calls, with the callback url handler.
voice.call
is ok. I don't think there's much there. I mean initiating a call.
voice.say("say something", voice="woman") // ?
Say
then Play
a URL
/*
<Say>Please listen to our awesome record</Say>
<Play url="http://www.myvoicemailserver.com/audio/vmail.wav"/>
*/
voice.say("Hi, listen to", play=url)
and how do we wrap getDigits
when we say
?
voice.say("say something I'm giving ... ", voice=woman, getDigits=True, record=True) // ?
// sadly without named parameters
// also, recording - maybe an attribute to be set
call redirect?
if (dtmfDigit === '9') {
voice.redirect('http://some_url_callback');
}
then, this would be expected.
<Response>
<Dial phoneNumbers="+254711XXXYYY,+254733YYYZZZ,[email protected]" ringBackTone="http://mymediafile.com/playme.mp3" record="true" sequential="true"/>
</Response>
maps to
// callerId specific to calling out from SIP
voice.dial(phoneNumbers=phones, maxDurationInSec=10, record=True,
ringBackTone="some_url", sequential="True", callerId="some_num");
Problem with this is that we need all possible mappings, and I think there's many cases, we might miss a few and not generate a proper functional XML string, but the XML response will still work.
So, basically we generate this by passing attributes on a command, is this a good approach?
we also need a SIP section, will look at this later.
Updated to version v0.5.0
and on sending sms i get error The request contains bad syntax or cannot be fulfilled
but on reverting back to 0.4.1
everything works okay
There are multiple broken links on the README.md file.
This is because ATs documentation link changed:
-https://docs.africastalking.com/
+https://developers.africastalking.com/
The link to npm
is also broken
I am using "africastalking": "^0.5.3"
With sandbox username and API Keys, I am able to send SMS. But when I swap the credentials to LIVE DATA, it returns The supplied authentication is invalid
Reverting back to SANDBOX environment data works well.
=== npm audit security report ===
Manual Review
Some vulnerabilities require your attention to resolve
Visit https://go.npm.me/audit-guide for additional guidance
High Server-Side Request Forgery
Package axios
Patched in >=0.21.1
Dependency of africastalking
Path africastalking > axios
More info https://npmjs.com/advisories/1594
When installing the package just this morning, there was one critical security warning and several other deprecation warnings. The security one might be important to fix.
warning africastalking > unirest > request > [email protected]: This module moved to @hapi/hawk. Please make sure to switch over as this distribution is no longer supported and may contain bugs and critical security issues.
warning africastalking > unirest > request > [email protected]: Use uuid module instead
warning africastalking > unirest > request > hawk > [email protected]: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
warning africastalking > unirest > request > hawk > [email protected]: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
warning africastalking > unirest > request > hawk > boom > [email protected]: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
warning africastalking > unirest > request > hawk > [email protected]: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
warning africastalking > unirest > request > hawk > cryptiles > [email protected]: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
warning africastalking > unirest > request > hawk > [email protected]: This module moved to @hapi/sntp. Please make sure to switch over as this distribution is no longer supported and may contain bugs and critical security issues.
warning africastalking > unirest > request > hawk > sntp > [email protected]: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
Hey,
Getting the following error whenever I try sending a message either through the sandbox api and even the production one:
{ Error: getaddrinfo ENOTFOUND api.africastalking.com api.africastalking.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'api.africastalking.com',
host: 'api.africastalking.com',
port: 443 }
Thanks!
node v5 advisory on the README? I think we'll just make the move this early and ignore the es5 branch.
and just maybe have this instead:
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
https://nodejs.org/en/download/package-manager/
are we shooting for backward compatibility?
I have issues when building app in production using africas talking api
e.js:56
throw new Error(
^
Error: Attempt to change mapping for "form" extension from "application/x-www-form-urlencoded" to "application/x-www-form-urlencoded". Pass `force=true` to allow this, otherwise remove "form" from the list of extensions for "application/x-www-form-urlencoded".
at Mime.define (/Users/mussa/Documents/Source/Vircap/vircap-backend/node_modules/mime/Mime.js:56:15)
at Object.<anonymous> (/Users/mussa/Documents/Source/Vircap/vircap-backend/node_modules/unirest/index.js:26:6)
Hello Africastalking,
I am having an issue with my node application which gives me the error:
/var/www/server/node_modules/africastalking/lib/customAxios/airtime.js:7
...data,
^^^
SyntaxError: Unexpected token ...
I think it refers to the three dots before the variable data.
How can this be solved because it runs okay on my localhost but when I try to run it on the server it gives me the said error.
Thank you.
This will be even much more elaborate than it's now : ) An example is
โโโ app
โย ย โโโ build
โย ย โโโ node_modules
โย ย โโโ src
โย ย โโโ final
โย ย โโโ work
| โโโ step-1
| โโโ step-2
| โโโ step-n
| โโโ step-final
Hi,
I just upgraded from 0.0.2 to 0.0.9 so that I can use the sandbox.
When I instrument my app using my production API account + key, it works great:
c2-dev-6 { username: 'ABC',
c2-dev-6 apiKey: 'XXX',
c2-dev-6 format: 'json',
c2-dev-6 sandbox: 'false' }
But when I instrument my app using my sandbox API account + key, I get 401 when I send a message:
c2-dev-7 { username: 'ABC',
c2-dev-7 apiKey: 'YYY',
c2-dev-7 format: 'json',
c2-dev-7 sandbox: true }
Any thoughts? I've tried passing true as both as a string and boolean.
I use nextjs + express, It returns the same error titled above
I use your exact example
We have been using the SDK for quite a while now, but of recent some real security issues has been popping up due to some outdated dependencies within the grpc dependency SDK
Below are list of vulnerable dependencies in grpc:
Please I urge you guys to investigate the above-listed dependencies which require urgent update due to the severity of the vulnerability
Great Library ๐
Though am running into an error when trying to send a simple sms. Seems to be something when returning a promise.
Here is the error
.then(function(s) {
^
TypeError: Cannot read property 'then' of undefined
Code:
var AfricasTalking = require('africastalking')(options);
var sms = AfricasTalking.SMS;
var opts = {
to: 0704654445,
message: 'Server is Running'
};
console.log(opts);
sms.send(opts)
.then(function(s) {
console.log(s);
})
.catch(function(error) {
console.log(error);
});
Finish up on premium SMS and implement payments.
payments
var options = {
'phoneNumber': '+2547XXXXXXXX',
'productId': 'ATX_Id324324153452',
'amount': 'KES 2000'
}
Payment.send(options)
.then(success)
.catch(error);
Will there be possible support for TypeScript in the future ? Also are PR's welcome from non-employees ?
@aksalj can we setup git hooks on npm; to update the package and version on a git push?
The test suite in npm test
currently does not validate that the responses are handled for all libraries. Only the USSD API makes use of the supertest
server to mock API responses. This ought to be extended to all libraries. From what I can tell, the following libraries need API response testing:
It doesn't look like the voice.js
or payment.js
libraries are tested.
I noticed in SMS.send and other api wrapper methods you're calling _validateParams() outside the Promise wrapper and throwing an error. This means the user has to wrap the method call in try-catch block to prevent a crash but still has to check for other errors using the catch() hook of the Promise, this seems counter-intuitive. Wouldn't it be better to just include the _validateParams() call within the promise block so that an error thrown is handled in the promise's catch() hook?
Maybe you can add a property to the error thrown to indicate that it was a validation error.
For one of my project, I want to send different messages to different numbers simultaneously, for instance,
when a loan is given out, a message (you have recieved a loan of <some amount> from person X
is sent to the borrower
, and another sent to the lender (You have sent <some amount> to person Y
).
But africastalking seems not to have that options
What I propose could enable such flexibility;
import AfricasTalking from "africastalking";
const africasTalking = new AfricasTalking({
username: "sandbox",
apiKey: process.env.AFRICA_TALKING_KEY
});
const sms = africasTalking.SMS;
...
sms.send([
{
to: phone1,
message: `message to ${recipient1}.`
},
{
to: phone2,
message: `message to ${recipient2}.`
}
])
...
what africastalking
accepts;
sms.send(
{
to: phone1,
message: `message to ${recipient1}.`
}
)
@aksalj The voice call promise would reject as the return status from AT's API would be 200
instead of 201
. I edited the test to cater for both responses. This shouldn't be a problem as both 200
and 201
technically refer to successful requests.
In a fresh clone of the AT nodejs API, there is one test failure for AfricasTalking.fetchAccount()
.
Steps to Reproduce
git clone https://github.com/AfricasTalkingLtd/africastalking-node.js
npm install
npm test
Expected Result
15 passing (16s)
Actual Result
14 passing (14s)
1 failing
1) Account fetched account info:
Error: timeout of 5000ms exceeded. Ensure the done() callback is being called in this test.
I need Africa's to be able to import africastalking on Deno as a third party package. I'll be glad if anyone made it happen.
It would be interesting to make use of ES6 features already available on stable node such as generators
The Voice API
currently specifies the CallTo
parameter as an array of phone numbers in comma-separated string format, which can be passed to the options object as shown below:
const options = {
callFrom: "+256******", // Set your Africa's Talking phone number in international format
callTo: ["+2567*******", "+256*******"], // Set the numbers you want to call to in a comma-separated list
};
However, when initiating a call, it appears that the API is only dialing the last number in the array, rather than calling all the numbers as expected.
The expected behavior is for the callTo
parameter to facilitate calling all the numbers listed in the array, ensuring that each number in the list receives a call.
I get an undefined
with
var endSession = false;
var message = '';
var sessionId = params.sessionId;
var serviceCode = params.serviceCode;
var phoneNumber = params.phoneNumber;
console.log(sessionId, serviceCode, phoneNumber, params.text);
result:
undefined '*384*306#' '+254701435178' '1'
Hello,
How does the SMS service deal with different fonts? When i use certain fonts, the message that's sent is in a different form. Some fonts are seemingly being parsed/escaped by ATs validation layer such that a string like ๐๐ฒ๐น๐น๐ผ is sent as d 'd 2d 1d 1d. How can I solve this? Using nodeJS for the backend
Hello, the method for building USSD menus as shown in the docs (using a series of if/switch statements on the input) seems tedious and impractical in the case of complex nested menus.
I've written a simple library that is compatible with the Africastalking API to make this easier. It takes a different approach by treating each menu screen as state and the whole ussd session as state machine, and uses rules based on input values, regular expressions or functions to link two states.
Here's the the library (ussd-menu-builder). The library is usable but lacks unit tests and has an incomplete documentation. I intend to finish those up before pushing to npm.
I thought I'd share it with you guys. You probably won't add it to your official NodeJs library cause it maybe a bit opinionated, but you could use it when giving tutorials or other projects.
Background
// africastalking-node.js/lib/customAxios/index.js (line 5)
function initializeAxios (config, production = false) {
// ...
}
lib/airtime.js
and lib/application.js
files, the implementation is the cause of the bug:// africastalking-node.js/lib/airtime.js (line 27)
const customAxios = initializeAxios(this.config, false);
Rectification
function initializeAxios (config) {
const isSandbox = config.username === 'sandbox';
}
const customAxios = initializeAxios(this.config);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.