Comments (12)
Also +1 for native Promise support in this library. It's 2019 guys! Everyone uses Promises now.
from vonage-node-sdk.
I'm going to do a re-write this year, and promises are on my list of features to add with the rewrite.
from vonage-node-sdk.
@leggetter to support both, I only know of nodeify
, and that's not the easy way. I would suggest people use bluebird's Promise.promisifyAll
on importing the module, that should do the trick.
from vonage-node-sdk.
I would suggest if there is no callback to return a promise
from vonage-node-sdk.
@AlexLakatos - Do you have any thoughts on a recommended approach. Do we simply recommend using someLibrary.promisify
or is there a way of us easily adding Promise support to the library?
from vonage-node-sdk.
There's a library called bluebird, which seems to be widespread and maintained (that I personally always use), i would recommend using it : https://github.com/petkaantonov/bluebird
the api documentation is available here : http://bluebirdjs.com/docs/api-reference.html
finally, adding promises nearly always consists of :
const Promise = require('bluebird');
function myPromiseCall(param) {
return new Promise(resolve, reject) {
someAsyncCall(param, function(err, result){
if(err){
if(callback) callback(err);
return reject(err);
}
if(callback) callback(null, result);
resolve(result);
});
};
}
adding this support at your top level functions (like request calls) simplifies the whole callback/result management inside the api. once you start using them, you get out of all the callback hell
from vonage-node-sdk.
@AlexLakatos it could be a good solution, but would require exhaustive testing though
from vonage-node-sdk.
any update on this?
from vonage-node-sdk.
There are no plans to add promise support in the near future. bluebird
worked well for me over these last few weeks though. @machinshin I would suggest you give that a try.
from vonage-node-sdk.
I solved it this way:
first I made this function wrapper around nexmo.verify.request
verifyRequest(number, callback) {
nexmo.verify.request(
{
number,
brand: "Haip"
},
callback
);
}
Then you can wrap the function in a function that returns a promise like so:
function verifyRequestPromise(phone) {
return new Promise(function(resolve, reject) {
verifyRequest(
phone,
(err, result) => (Boolean(err) ? reject(err) : resolve(result))
);
});
}
from vonage-node-sdk.
Also with util.promisify
in Node 8+
Docs -> https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original
const util = require('util');
const verifyRequestPromise = util.promisify(nexmo.verify.request.bind(nexmo.verify));
const result = await verifyRequestPromise({
number,
brand: "Haip"
})
from vonage-node-sdk.
Merge with #294
from vonage-node-sdk.
Related Issues (20)
- Basic setup of SMS api is not working, I get status 0 (success) but no sms sent. HOT 3
- Not able to install Vonage/server-sdk HOT 9
- packages/verify/lib/interfaces/VerifyControlError.ts contains a broken import path HOT 5
- Documentation missing/unclear HOT 8
- Latest beta release uses deprecated "request" package, which has an open CVE HOT 3
- How can I create new User with this SDK??? HOT 1
- 401 Error when sending Whats App message HOT 5
- error Couldn't find package "@vonage/verify2@^1.3.0" required by "@vonage/server-sdk@^3.0.12" on the "npm" registry. HOT 3
- Typescript SyntaxError: Unexpected token '.' during compilation HOT 1
- WebsocketEndpointObject incorrect type
- Request timeout option is broken HOT 1
- Importing @vonage/server-sdk causes TypeScript errors because of incorrect imports in @vonage/voice HOT 14
- Error while trying to import library HOT 3
- [question] How to authenticate to the video package? HOT 2
- Request timeout option is still broken HOT 1
- Cannot send Whatsapp auth template message HOT 4
- readme example does not compile in TS HOT 2
- Messages CLI not working HOT 3
- Vonage.sms.verifySignature doesn't work with inbound SMS message HOT 3
- [Bug]: Issue with npm install HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vonage-node-sdk.