Comments (13)
Could something like this be a good solution?
// example (express)
app.post('/callback/voice', new AfricasTalking.VOICE.CallHandler((phoneCall) => {
var session = phoneCall.session;
//...
if (phoneCall.isActive) {
//...
} else if (phoneCall.isCompleted){
//...
}
var response = voice.builder()
.say("UI", {voice: "woman"})
.play("DEd")
.getDigits("SW", {say:{voice: "man"}})
//... more say(), play(), record(), etc.
.build();
phoneCall.respond(null, response);
}));
from africastalking-node.js.
Passing an options object seems like a decent compromise and it could still have default values something like below is still possible
function (options) {
var someSetting = options.someSetting || defaultValue;
}
from africastalking-node.js.
that's perfect! awesome! this will make it so easy to build voice apps on node 💯
from africastalking-node.js.
also, ES6 does not support named parameters 👎 - so, maybe pass an options object instead. and have this as the only argument, to just have this as the only named parameter object.
then the only drawback is that with that we won't have default values for parameters?
@pbombo and also how can we return the responses in commands? When we are done with the response build - maybe a var
, with endSession = True
so, basically this would be an xml Response
builder.
var options = {
...
}
var response0 = voice.say("Hey, whatever", options);
var response1 = voice.command(options);
resp.end(response);
from africastalking-node.js.
@habbes That's the way to go now; @aksalj had already highlighted that.
from africastalking-node.js.
This is also looking interesting, default parameters in ES6
from africastalking-node.js.
I think my reaction was "JS can do that?" lol, I assumed it would, it's very pythonic. Better than ||
Problem is, the default value is within options, so it's not on call. This would have been great with named parameters.
from africastalking-node.js.
I think it can be done well even without named parameters. Something like this would be nice:
let str = "Salut!", anotherStr, url;
let options = { // action's secondary attributes as needed
voice: 'dude',
record: false
//...
};
voice.say(str, options)
.play(url)
.then(success)
.catch(error);
voice.getDigits(options)
.say(str, options)
.then(success)
.catch(error);
But quick question: Is the documentation at http://docs.africastalking.com/voice up to date? I remember @ianjuma you said there were some big changes coming to voice... 😕
from africastalking-node.js.
@aksalj I think the idea was to avoid user having to do this
let options = { // action's secondary attributes
voice: 'dude',
record: false
//...
};
that is the real value of default parameters IMO.
Ideally you'd just have javascript voice.say(str)
without the need to set options
from africastalking-node.js.
@ianjuma is the problem named parameters or default parameters?
With named params (which is what I think @ianjuma was referring to) you can have both this:
voice.say(str, voice='Female', record=false)
and this:
voice.say(str, record=false, voice='Female')
be the exact same call.
That way you can avoid passing params in a given order (therefore passing only those you need). JavaScript does not support named parameters yet afaik. But we can "simulate" this behavior with objects like this:
let options = { // only set the options you need, otherwise default values will be used
voice: 'Female',
record: false
//...
};
voice.say(str, options);
// if you don't need to override the default options, just do
voice.say(str);
Then say()
is implemented like @pbombo said with something = options.something || defaultValue
.
from africastalking-node.js.
I think both, ES6 doesn't support it, this could have been more readable.
I wish we didn't have to do that; I think the order of params should be free from the user, so
we might have the options
set. My problem is with attributes, it just seems un-conventional to have those in options
. Python problems :( but that's the way to go I agree.
@aksalj some of the commands were updated, and there parameters too. Say, Play, Record, Redirect, Reject
should be ok now. I've been slow with that, sadly 😞 Users on the API have been creating XML
responses, I really want this helper approach, I think it will make working with Voice easy.
Also @aksalj @pbombo I can map a number to your account, for testing with this?
now, order of commands? How are we making this response. Responses are usually simple and straight forward. So, are we grabbing the response string and returning it?
voice.say(str, options)
.play(url)
.then(success)
.catch(error);
from africastalking-node.js.
May I contribute to this discussion. I also go for having an options object. Considering the lack of default params and strong intellisense-like features, one ends up looking up the docs a lot just to remember the order of params.
from africastalking-node.js.
@ianjuma is the voice library in AT node package updated with CallHandler()
?
from africastalking-node.js.
Related Issues (20)
- destructuring an undefined key HOT 1
- Security Venerability HOT 1
- Update Premium Urls. HOT 1
- v0.5.0 may have breaking changes ..sendsms error HOT 1
- High vulnerability with [email protected] HOT 2
- Cannot read property 'send' of undefined HOT 2
- send different messages to different numbers simultaneously ? HOT 2
- Vulnerability Report on Axios HOT 2
- The supplied authentication is invalid HOT 2
- Support for multiple numbers & clientRequestId in voice sdk
- Installing africastalking using npm not working HOT 10
- Error: Attempt to change mapping for "form" extension from "application/x-www-form-urlencoded" to "application/x-www-form-urlencoded". Pass `force=true` HOT 3
- Cannot read property 'send' of undefined HOT 1
- Support for Deno HOT 1
- Broken links on README.md file
- Typescript support HOT 5
- Voice API `callTo` Parameter Only Initiates Call to Last Number in Array HOT 6
- Request for Contribution Guide HOT 3
- Updating dependencies
- SMS Message With A Different String Font Being Sent in a Cryptic Manner 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 africastalking-node.js.