how do I know if SMS has reached at destination in Twilio

一笑奈何 提交于 2019-12-10 21:48:09

问题


i am developing a web app and in that I am sending SMS using twilio gateway.I need to show on my page the status of SMS.If SMS is sent then it will show delivered else it will show pending. So please tell me how do i know whether the message has been delivered or not.

Following is the sample code

public class Example {

  public static final String ACCOUNT_SID = "AC5b8866a232v3b63bfgh0f9a872b2dfddd";
  public static final String AUTH_TOKEN = "7a0068ca7d07036cbbddeba03370aujdhnm";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    Map<String, String> params = new HashMap<String, String>();

    params.put("To", "+number");
    params.put("From", "+number");
 System.out.println(System.getProperty("java.class.path"));
    SmsFactory messageFactory = client.getAccount().getSmsFactory();
    Sms message = messageFactory.create(params);

  }
}

回答1:


Twilio evangelist here.

First of all please note that the SmsMessages resource has been deprecated and you should now be using the new Messages endpoint. You can check out the Sending SMS Messages quickstart for updated Java code that shows how to use the new resource with the Java helper library.

Second, in order to receive notifications as a Messages status changes you should include the StatusCallback parameter when you send the Message. Including this parameter tells Twilio to make a request to the parameters URL when the message status changes.

Also note since its not clear from your post title, the "sent" status simple means that Twilio successfully sent the message to the carrier. It does not necessarily mean that the carrier was able to deliver the message to the intended recipient.

Hope that helps.




回答2:


Message.getStatus() is what you need. I think the response is one of queued, sending, sent, or failed.



来源:https://stackoverflow.com/questions/19858044/how-do-i-know-if-sms-has-reached-at-destination-in-twilio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!