Search code examples
twiliotwilio-apitwilio-phptwilio-twiml

twilio Get custom parameters for enqueued calls


is it possible to get enqueued call's custom parameters

I'm en queuing all calls but now i can't get the custom parameters i have passed using twilio js

let conn = Device.connect({
      name: name,
      email: email,
    });

Please help

Thanks in advance.


Solution

  • This is easily done. You will get the parameters server-side in your TwiML app callback. Here is the PHP solution...

    First of all your connect call needs to be modified like so...

    let conn = Device.connect({
        params: {
          name: name,
          email: email,
        }
    });
    

    Your TwiML app configuration...

    TwiML app control panel

    In your PHP server...

    public function getVoiceXML(Request $request, 
        EntityManagerInterface $em
        ) : Response
    {
        error_log('in getVoiceXML');
        error_log(json_encode($request->query->all()));
        $name = $request->query->get('name');
        $email = $request->query->get('email');
     // ...
     }
    

    A few recommendations:

    1. Your custom parameters will be mixed in with all the other parameters coming in with the call. So name them distinctly to prevent name collision. 'myapp_name' and 'myapp_email' for example.
    2. Add parameters that describe the call. You have a large number of parameters coming in to the callback but there is no documentation for them and several can be misinterpreted. For example "Direction" is always "inbound" even when you are initiating the call from the browser.