twilio / twilio-node

Node.js helper library
MIT License
1.41k stars 515 forks source link

Events for Calls #5

Closed ghost closed 11 years ago

ghost commented 11 years ago

The unofficial node-twilio-api has a nice feature where its call object emits an event when the status of the call changes. For example:

app.makeCall("+12225551234", "+13335551234", function(err, call) {
  if(err) throw err;

  call.on('connected', function(status) {
    //Called when the caller picks up
    call.say("This is a test. Goodbye!");
  });
  call.on('ended', function(status, duration) {
      //Called when the call ends
  });
});

This makes things a heck of a lot easier when dealing with user data stored in sessions, request/response objects (especially POST data), etc.

Imagine if on('ended') you could then do res.send(...) within the same route. Would this be possible to implement here?

kwhinnery commented 11 years ago

@bminer has a lot of neat high-level features in his module (he's a badass)! The design of that API also encompasses handling incoming HTTP requests and generating TwiML on behalf of the developer, which allows for these types of features that go beyond what is actually part of the Twilio API. I agree, this particular bit is very cool.

My goal with this module was to stay pretty close to the metal of the actual Twilio API. This has the benefit of making it very easy to add features as Twilio adds features, and maintain parity with the actual Twilio APIs. It also prevents a developer from having to master two sets of APIs and concepts (the node module API plus the actual Twilio API). Also, as you add abstraction layers, you increase the chance that the abstraction actually gets in the way of what developers need to accomplish in non-trivial applications.

I think there's room for higher-level helpers (API for buying a number in a single step, an event emitter for handling voice/SMS URLs, Connect middleware for the same...). However, this particular interface is more abstract than I would be willing to go with the official library, at least at this point. If you feel strongly that this module is too low-level, you can definitely propose an additional object model on top of the current low-level APIs as another GH issue.

Thanks for the feedback!

bminer commented 11 years ago

@kwhinnery Badass? Hardly! But thanks anyway, lol. I agree with you, though: the unofficial node-twilio-api module seems to be more high-level (and therefore more "opinionated"); whereas, this module is more low-level, which can be more beneficial in certain situations (portability across languages, etc.). That's the beauty of node and npm: there are multiple modules that do the same thing, and you get to pick the one most appropriate for your application.

Nice work on this module, by the way! It looks like it's very complete and well documented.