简体   繁体   English

如何使用 TwiML 而不是 URL 在 Java 中使用 Twilio 进行出站呼叫?

[英]How to make an outbound call in Twilio with Java, using TwiML and not a URL?

I'm looking to make an outbound call in a Java application using Twilio.我正在寻找使用 Twilio 在 Java 应用程序中进行出站呼叫。 All of the tutorials I found used a static TwiML file hosted on a URL.我发现的所有教程都使用了托管在 URL 上的静态 TwiML 文件。 I haven't been able to find any documentation on how to pass in TwiML as a parameter for an outgoing call.我还没有找到任何关于如何将 TwiML 作为传出呼叫的参数传递的文档。

I found this on this link, but it doesn't explain how to dynamically render TwiML: https://www.twilio.com/docs/guides/how-to-make-outbound-phone-calls-in-java#where-to-next我在这个链接上找到了这个,但它没有解释如何动态呈现 TwiML: https ://www.twilio.com/docs/guides/how-to-make-outbound-phone-calls-in-java#where -到下一个

Of course, the TwiML you use to make the outbound call doesn't need to be a static file like in this example.当然,用于进行出站调用的 TwiML 不需要像本示例中那样是静态文件。 Server-side Java code that you control can dynamically render TwiML to use for the outbound call.您控制的服务器端 Java 代码可以动态呈现 TwiML 以用于出站调用。

I've tried the following:我尝试了以下方法:

PhoneNumber to = new PhoneNumber(toPhone); // Replace with your phone number
PhoneNumber from = new PhoneNumber(fromPhone); // Replace with a Twilio number
TwiML twiml = new VoiceResponse.Builder()
        .say(new Say.Builder(message).build())
        .build();
Call call = Call.creator(to, from, twiml.toXml()).create(client);

While the Call.creator() has some overloaded methods of (PhoneNumber, PhoneNumber, String) , none of them will accept TwiML, nor XML.虽然Call.creator()有一些(PhoneNumber, PhoneNumber, String)的重载方法,但它们都不接受 TwiML,也不接受 XML。

How do make an outbound call in Java using TwiML?如何使用 TwiML 在 Java 中进行出站呼叫? Thanks谢谢

Twilio developer evangelist here. Twilio 开发人员布道者在这里。

You cannot make an outbound call with Twilio and directly pass the TwiML that you want the call to follow at the same time.您不能使用 Twilio 进行出站呼叫并同时直接传递您希望呼叫跟随的 TwiML。

When you make the outbound call you need to pass a URL.当您进行出站呼叫时,您需要传递一个 URL。 That URL does not have to return static TwiML though.不过,该 URL 不必返回静态 TwiML。 If you want to return dynamic TwiML you need to set the URL for the call to a URL of a web application that can respond to the request with TwiML.如果要返回动态 TwiML,则需要将调用的 URL 设置为可以使用 TwiML 响应请求的 Web 应用程序的 URL。

It might make it more obvious what I mean if you check out some of the dynamic tutorials.如果您查看一些动态教程,可能会更清楚我的意思。 This one on building an automated phone survey dynamically generates the next question and takes input from the user in response.这个关于构建自动电话调查的问题会动态生成下一个问题并从用户那里获取输入作为响应。 Thisclick to call implementation in Java also dynamically generates the <Dial> when the call connects. Java 中的这种单击呼叫实现还会在呼​​叫连接时动态生成<Dial>

Let me know if that helps at all.让我知道这是否有帮助。

I understand that your question and Phil's answer are over four years old;我知道您的问题和菲尔的回答已经超过四年了; however, one can place outbound calls with Twilio and directly pass the TwiML that you want the call to follow concurrently, starting in Twilio version 3.39.0 as shown here: https://github.com/twilio/twilio-node/releases/tag/3.39.0 .但是,可以使用 Twilio 进行出站呼叫并直接传递您希望呼叫同时遵循的 TwiML,从 Twilio 版本 3.39.0 开始,如下所示: https ://github.com/twilio/twilio-node/releases/标签/3.39.0 One can now opt the URL for TwiML starting in this release.从这个版本开始,现在可以选择 TwiML 的 URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM