lfmunoz
lfmunoz

Reputation: 912

In Twilio voice, how do I make TWO outgoing calls and connect both together?

I want to programmatically make two outgoing calls using the Java Twilio API. What I have so so far is as following:

I registered two numbers with twilio. The I execute the following code to make the first outgoing call:

        val call = Call.creator(
                PhoneNumber(numberOne), // TO
                PhoneNumber(TWILIO_NUMBER0), // FROM
                URI.create(twilioInformURL(id)) // INSTRUCTIONS for when person picks up
        ).setMethod(HttpMethod.POST)
         .setStatusCallback(twilioStatusURL(id))
         .setStatusCallbackMethod(HttpMethod.POST)
         .setStatusCallbackEvent(listOf("initiated", "in-progress", "ringing", "answered", "completed"))
         .create()

This will call numberOne number from TWILIO_NUMBER0, then do an API POST Call to my URL where I return the following to make the second call:

        val number = Number.Builder(numberTwo).build()
        val dial = Dial.Builder().number(number).build()
        val response = VoiceResponse.Builder().dial(dial).build()
        return response.toXml()

Unfortunately this doesn't work. It just calls and reads out numberTwo.

If anyone knows how to make this work I would really appreciate it.

Upvotes: 0

Views: 658

Answers (1)

philnash
philnash

Reputation: 73027

Twilio developer evangelist here.

If Twilio is just reading out your number then you are likely not serving the TwiML as XML. If Twilio doesn't see a Content-Type header of text/xml or application/xml then it assumes text content and reads out the text contents of the elements.

Make sure you are setting your Content-Type header in the webhook response and this should work.

Upvotes: 1

Related Questions