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请求,如下所示:
然而,在本教程中,他们使用ngrok创建了一个HTTP隧道,以允许HTTP请求通过我的应用程序应该能够在任何人的计算机上运行,而无需事先配置。你建议我如何做到这一点
# 1 楼答案
我担心,如果不将应用程序公开给网络,您将无法使用特定的API
您可以尝试做的是轮询/获取:
一个简短的例子是here