从 Twilio 接收短信
Receive SMS from Twilio
我正在创建一个程序,询问用户类似 "How are you doing today":
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());
然后程序将监听用户从 phone 发回的任何响应。
现在,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 请求,如下所示:
但是,在本教程中,他们使用 ngrok 创建了一个 HTTP 隧道以允许 HTTP 请求通过。 我的应用程序应该能够 运行 在任何人的计算机上无需事先配置 。您建议我如何实现这一目标?
恐怕如果不将您的应用程序暴露在网络上,您将无法使用那个特定的 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。
我正在创建一个程序,询问用户类似 "How are you doing today":
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());
然后程序将监听用户从 phone 发回的任何响应。
现在,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 请求,如下所示:
但是,在本教程中,他们使用 ngrok 创建了一个 HTTP 隧道以允许 HTTP 请求通过。 我的应用程序应该能够 运行 在任何人的计算机上无需事先配置 。您建议我如何实现这一目标?
恐怕如果不将您的应用程序暴露在网络上,您将无法使用那个特定的 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。