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);

  }
}
有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top