-1

I'm trying to use a TwiML moustache template for the callerId attribute in the following Bin:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial callerId="+11234567890">
        <Number>{{to}}</Number>
    </Dial>
</Response>

However, when I do something like this:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial callerId={{from}}>
        <Number>{{to}}</Number>
    </Dial>
</Response>

the message says that it's an invalid TwiML. The phone number in the app will be changing so I need that value to be dynamic. How would I use a template here?

Also, I've tried to set various parameters via Java like this:

    public void makeCall() {
        if (accessToken != null) {
            params.put("To", toNumber);
            params.put("From", "11234567890");
            params.put("Caller", "11234567890");
            params.put("CallerId", "client:11234567890");
            ConnectOptions connectOptions = new ConnectOptions.Builder(accessToken)
                    .params(params)
                    .build();
            activeCall = Voice.connect(context, connectOptions, callListener);

        }

but to no avail, because the message on the Twilio dashboard always reports:

Dial: Invalid callerId value

Additionally, the two articles describing Bins didn't cover this case: link and link

heiligbasil
  • 149
  • 3
  • 11

1 Answers1

2

Try capitalizing From and To. That should fix the issue.

Alan
  • 10,465
  • 2
  • 8
  • 9
  • After making "To" lowercase, it worked better but sadly changing the case on the "For" attribute didn't seem to make a difference: All uppercase, all lowercase, or titlecase. Also I'm still in the dark about the syntax for the _callerId_ attribute template... – heiligbasil Jan 22 '21 at 03:12
  • CallerId has to be a phone number in E.164 format if you are dialing out to the PSTN which is what Dial Number does. The From should be client:11234567890, based on your code which is invalid for PSTN calls. – Alan Jan 22 '21 at 04:16
  • That gave me more combinations to try: client:11234567890 and client:+11234567890 and +11234567890. The hurdle seems to be though I don't know the right syntax to remove the _callerId_ attribute from the TwiML bin, shown above. Removing it, gives an error no matter what my Java parameter says. There must be a way through this... – heiligbasil Jan 22 '21 at 05:37
  • There is a TwiML Bin Function you can use to normalize the From sent in if it is not in E.164 format, {{#e164}}{{From}}{{/e164}}. What you are trying to do is 100% possible. – Alan Jan 22 '21 at 14:35
  • I appreciate your help Alan and I think you're right - there is a way. What you gave me seems to help partially... but whenever I remove the _callerId_ attribute and make a call, a robotic voice says: "We are sorry; an application error has occurred. Goodbye." And I need the _callerId_ attribute to change depending on what number it's being called from. I'm sure there's something I've overlooked. – heiligbasil Jan 22 '21 at 17:03
  • 1
    You will need to map a Twilio Client identity, i.e. client:xxx, to a specific telephone number when placing a call out to the PSTN (there are two call legs, the client leg to Twilio and the Twilio leg to the phone network). As you've seen, your TwiML is setting the `callerId` you can pass in from the client side what E.164 number for the client to use, https://www.twilio.com/docs/voice/how-share-information-between-your-applications#sending-custom-parameters-to-your-backend-application, or do a lookup on the backend to map a specific client identity to a phone number and generate your TwiML. – Alan Jan 22 '21 at 18:03