PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 19, 2022

[FIXED] How does one nest Twilio Twiml <Play> inside <Gather> using Twilio\Twiml php

 November 19, 2022     twilio, twilio-php     No comments   

Issue

How would I nest Play inside Gather ? I have the following Twiml xml:

 $twiml = new Twiml();
    $twiml->gather('gather',array());
    $twiml->play('https://api.twilio.com/cowbell.mp3', array("loop" => 5));
    $response = Response::make($twiml, 200);
    $response->header('Content-Type', 'text/xml');
    return $response;

required result:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather input="speech" action="/completed">
  <Play loop="5">https://api.twilio.com/cowbell.mp3</Play>
</Gather>


Solution

Use this:

$twiml = new Twilio\Twiml();
$gather = $twiml->gather(array('input' => 'speech', 'action' => '/completed'));
$gather->play('https://api.twilio.com/cowbell.mp3', array("loop" => 5));

$response = Response::make($twiml, 200);
$response->header('Content-Type', 'text/xml');
return $response;


Answered By - Andy
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing