简体   繁体   English

使用 Twilio 发送短信后如何确保短信通过

[英]How to make sure a SMS went through after sending it with Twilio

I am using the Twilio java wrapper provided on the website and started making some tests.我正在使用网站上提供的 Twilio java 包装器并开始进行一些测试。 I am able to send text messages that are successfully received.我能够发送成功接收的短信。 However, I would like to make sure that the messages have been sent successfully and that no problem has been encountered by Twilio (bad phone number or whatever reason).但是,我想确保消息已成功发送并且 Twilio 没有遇到任何问题(电话号码错误或任何原因)。

I understand that when you make a REST request to Twilio to send a SMS, Twilio responds with the Status.我知道当您向 Twilio 发出 REST 请求以发送 SMS 时,Twilio 会以状态响应。 How could I get this response?我怎么能得到这个回应?

Here is the explanation page I found: http://www.twilio.com/docs/howto/sms-notifications-and-alerts这是我找到的解释页面: http : //www.twilio.com/docs/howto/sms-notifications-and-alerts

If you specify a StatusCallback URL when you make the request to send an SMS, we will make a request to the callback URL you provided after the message has finished processing, with the parameters either SmsStatus=sent or SmsStatus=failed.如果您在请求发送短信时指定 StatusCallback URL,我们将在消息处理完成后向您提供的回调 URL 发出请求,参数为 SmsStatus=sent 或 SmsStatus=failed。 You can use this information to do more processing on the SMS message.您可以使用此信息对 SMS 消息进行更多处理。 There's more information here: http://www.twilio.com/docs/api/rest/sending-sms#post-parameters-optional这里有更多信息: http : //www.twilio.com/docs/api/rest/sending-sms#post-parameters-optional

Alternately, if you hang on to the SMS Message Sid, you should be able to query the API for the message and get the status in the response.或者,如果您继续使用 SMS Message Sid,您应该能够查询消息的 API 并获得响应中的状态。 So if the sid is SM123, making a GET request to https://api.twilio.com/2010-04-01/Accounts/AC123/SMS/Messages/SM123.json should return a object with the status of the SMS Message.因此,如果 sid 是 SM123,则向https://api.twilio.com/2010-04-01/Accounts/AC123/SMS/Messages/SM123.json发出 GET 请求应该返回一个带有 SMS 消息状态的对象.

I recall that the response comes to your url and can be matched up by an ID.我记得响应来自您的 url,并且可以通过 ID 进行匹配。 In the REST post to SMSMessages you can specify a statuscallback url where Twilio will post a status message to your url.在 REST 发布到 SMSMessages 中,您可以指定一个 statuscallback url,Twilio 将在其中向您的 url 发布状态消息。

When you receive that post to your site, you can record it or take any other action you need, such as retrying or using another mode of communication.当您在您的网站上收到该帖子时,您可以将其记录下来或采取任何其他您需要的操作,例如重试或使用其他通信方式。

2020 年,借助 Java SDK,您现在可以使用该 SID 创建MessageFetcher ,然后调用fetch来请求Message实例,直到其getStatus返回“delivered”、“undelivered”或“failed”。

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

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