Search code examples
twiliotwilio-twiml

Twilio twiml say different messages to each person on call?


I'm using Twilio to create phone calls between two phone numbers. In certain cases during the call I want to interrupt the call and play IVR messages. When I interrupt the call I want to play a different message to each person.

I see the way to interrupt the call is by redirecting the call here.

Then if I want to say some thing I use the twiml say command here.

But I can't see any way specifying which recipient receives what from the twiml. It seems that when you say a message it will be played to both people on the call.

Can Twilio support this functionality?


Solution

  • Twilio evangelist here.

    So I think what you are going to have to do in this case is leverage a Conference. This may change how your initiating the two legs of the call. If you are currently using <Dial> to connect the two callers together, the problem there is that there is no easy way to get the Call SID of the second leg of the call. This means there is no easy way to redirect that call.

    So instead of using <Dial>, what I normally do is when Caller A dials in, I put them into a conference, saving the name of the conference room to a database. Then I use the Twilio REST API to make an outbound call to Caller B. When they answer I put them into the same conference room as Caller A.

    This also means I have both calls Call SIS, which I can use to redirect the two call legs independently. So in your case, when you wanted to Say something to Caller A, you would simply redirect them our of the conference, use <Say> or <Play> to talk to them, then redirect them back into the conference. Same process for caller B.

    Hope that helps.