简体   繁体   English

如何将Twilio号码的来电转接到另一个号码?

[英]How to forward an incoming call to a Twilio number to another number?

I need to forward incoming calls to my Twilio number to a personal number.我需要将打到我的 Twilio 号码的来电转接到个人号码。 I need to do this by Java code because I have a few other Business logic executing when TwiMl App redirect the request and because of that, I can't use Twilio Studio.我需要通过 Java 代码执行此操作,因为当 TwiMl App 重定向请求时我还有一些其他业务逻辑正在执行,因此,我无法使用 Twilio Studio。

I tried a few ways but didn't work and can't make the following method work.我尝试了几种方法但没有用,无法使以下方法起作用。 I think these are deprecated now,我认为这些现在已被弃用,

Call call = Call.creator(
    new PhoneNumber(TWILIO_NUMBER),
    new PhoneNumber(FORWARD_TO),
    new PhoneNumber(TWILIO_NUMBER)
).create();

And even following redirect() method is also not there now.甚至下面的redirect()方法现在也不存在了。

Call.updater("call-sid")
    .redirect(FORWARD_TO).update();

So what I need is when a call comes to my Twilio number then that call should be forwarded to my personal number.所以我需要的是,当我的 Twilio 号码接到电话时,该电话应该转接到我的个人号码。 So how to do this?那么该怎么做呢? Can anybody help me?有谁能够帮我? Thanks in advance.提前致谢。

The code block in your question triggers an outgoing call, which is why it doesn't work to handle incoming calls (and because the third parameter should contain TwiML and not a phone number).您问题中的代码块会触发拨出电话,这就是为什么它无法处理来电(并且因为第三个参数应包含 TwiML 而不是电话号码)。

To handle incoming calls with business logic, you need to implement a webhook that returns TwiML.要使用业务逻辑处理传入呼叫,您需要实现一个返回 TwiML 的 webhook。 Use the <Dial> Tag in this TwiML response to initiate the call forwarding.使用此 TwiML 响应中的<Dial>标记来启动呼叫转移。 Check out this tutorial to learn more about this.查看本教程以了解更多相关信息。

The proper code should go like this:正确的代码应该是 go,如下所示:

import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Dial dial = new Dial.Builder("415-123-4567").build();
        Say say = new Say.Builder("Goodbye").build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial)
            .say(say).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}

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

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