有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java接收来自Twilio的短信

我正在创建一个程序,询问用户“你今天过得怎么样”:

    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Message message = Message.creator(new PhoneNumber("+000000"), // To
                                                                        // number
            new PhoneNumber("0000000"), // From number
            "How are you doing today?" // SMS body
    ).create();

    System.out.println(message.getSid());

然后,该程序将监听用户从手机回复的任何回复

现在,Twilio谈到了接收短信:

You can associate that phone number with an SMS URL. When someone sends a text message to that phone number, Twilio makes an HTTP request to your URL with the body of the message and the sender's phone number. You can then respond to the SMS by returning a reply message in the HTTP response to Twilio.

现在,我了解到,当用户发回短信时,Twilio会向我的程序发出HTTP请求,如下所示:

enter image description here

然而,在本教程中,他们使用ngrok创建了一个HTTP隧道,以允许HTTP请求通过我的应用程序应该能够在任何人的计算机上运行,而无需事先配置。你建议我如何做到这一点


共 (1) 个答案

  1. # 1 楼答案

    我担心,如果不将应用程序公开给网络,您将无法使用特定的API

    您可以尝试做的是轮询/获取:

    When you send an SMS or MMS message via the REST API, using the <Message> verb in TwiML, or someone sends a message to one of your Twilio numbers Twilio creates a Message instance resource. The Messages list resource represents the set of messages sent from and received by an account.

    Retrieving sent and received messages from history can be achieved by querying the Messages list resource.

    一个简短的例子是here