2
votes

I'm trying to figure out how to create calls from my Twilio number after I've dialed into it and entered a number. After reading the docs I see that this is done with the gather feature, which can then be redirected to another Twiml document to handle the response. However, I can't quite get it to work. I'm extremely confused on how to execute Twiml correctly and how to access the request parameters in another Twiml doc. I've also looked into Twimlets but I wasn't able to construct what I needed there correctly either.

I've gone back and tried to just make a simple voice message play when only my number calls. If it's not me calling then it needs to be redirected to a Twiml url which will try to connect to my phone. If that fails it will prompt the caller to leave a message.

//Handle incoming call requests 
app.post('/call', function(req, res)  {
  var twiml = new twilio.TwimlResponse();
  res.type('text/xml');

  if ( req.body.From === "+1555555555") { 
    twiml.say('Hello', {voice: alice});
    res.send(twiml.toString());  
  } else {
    // Do something here.
  }
});

I've found the correct solution for my problem. I wasn't initiating the twilio.TwimlResponse() correctly.

1
What have you tried so far? Can you share some code that isn't working for you?philnash
@philnash I've updated my post. Thank you.JorgeEstaAqui
Ok, so what's not working? It looks like if your number calls it should work. You need to res.send in the else clause of your conditional (or put the res.send(twiml.toString()) after the conditional.philnash
@philnash When I call my twilio number, it calls my actual number and doesn't say anything. My desired goal at the moment is, that when I call my Twilio number I want it to just say "Hello". The end goal is to have it prompt me for a phone number that it will then connect me to.JorgeEstaAqui
Are you using body-parser to parse the incoming URL encoded body? Are you definitely getting req.body.From?philnash

1 Answers

0
votes

In order to solve this issue, I needed to use == instead of === so that my req.body.from value wouldn't get coerced.