Giter VIP home page Giter VIP logo

Comments (13)

aksalj avatar aksalj commented on August 19, 2024 3

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.

pbombo avatar pbombo commented on August 19, 2024 2

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.

ianjuma avatar ianjuma commented on August 19, 2024 2

that's perfect! awesome! this will make it so easy to build voice apps on node 💯

from africastalking-node.js.

ianjuma avatar ianjuma commented on August 19, 2024 1

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.

ianjuma avatar ianjuma commented on August 19, 2024 1

@habbes That's the way to go now; @aksalj had already highlighted that.

from africastalking-node.js.

pbombo avatar pbombo commented on August 19, 2024

This is also looking interesting, default parameters in ES6

from africastalking-node.js.

ianjuma avatar ianjuma commented on August 19, 2024

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.

aksalj avatar aksalj commented on August 19, 2024

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.

pbombo avatar pbombo commented on August 19, 2024

@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.

aksalj avatar aksalj commented on August 19, 2024

@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.

ianjuma avatar ianjuma commented on August 19, 2024

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.

habbes avatar habbes commented on August 19, 2024

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.

danmbeyah avatar danmbeyah commented on August 19, 2024

@ianjuma is the voice library in AT node package updated with CallHandler()?

from africastalking-node.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.