user8610600
user8610600

Reputation: 71

Twilio programmable voice call android

I just want to integrate twilio programmable voice on my project(android + PHP) so when i dial a VOIP call using android app than the person who will receive call will hear twiml programmable message on call.

I have tried a lot and VOIP call is working fine but i want to add a programmable message when receiver will accept the call.

$callerNumber = '+123456789';

$response = new Twilio\Twiml();

if (!isset($to) || empty($to)) {
  $response->say('Congratulations! You have just made your first call! Good bye.');
} else if (is_numeric($to)) {


  $dial = $response->dial(
    array(
      'callerId' => $callerNumber,
    ));

  $dial->number($to);
} else {
  $dial = $response->dial(
    array(
       'callerId' => $callerId,

    ));
  $dial->client($to);


}
print $response;

I have used above code in the back-end and my VOIP call is working fine but i want to add a programmable message when receiver accept the call

Upvotes: 2

Views: 509

Answers (1)

philnash
philnash

Reputation: 73029

Twilio developer evangelist here.

In order to add a message to the receiver's call before they are connected, known as a call whisper you need to add a url attribute to your <Number> TwiML.

The URL in the attribute will receive a webhook when the person answers the phone. Return TwiML to the request and that TwiML will be played to the person on the phone before they are connected.

In your PHP, this looks like:

  $dial = $response->dial(
    array(
      'callerId' => $callerNumber,
    ));

  $dial->number($to, ['url' => 'https://example.com/whisper'];

Then, for the /whisper endpoint you can return TwiML that reads out a message with <Say> for example:

$response = new Twilio\Twiml();

$response->say('Congratulations! This is a whisper!');

print $response;

Upvotes: 1

Related Questions