Messages are not delivered to numbers but Twilio is charging me and giving me status sent only with my code.
private val client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
def sendSMS(smsTo: String) = {
val params = Map("To" -> smsTo, "From" -> twilioNumber, "Body" -> "status?")
val messageFactory = client.getAccount.getSmsFactory
messageFactory.create(params)
}
But when I am using API Explorer its giving status delivered.
Is it my code's fault or Twilio?
I want my SMS delivered to users.
Twilio Evangelist here here.
When you send the SMS message using the REST API (the Java/Scala helper library here) you are getting the status sent because Twilio has sent the message to the carrier. The carrier will typically update Twilio to say the message was delivered.
There should be nothing wrong with your code at all. What you can do is capture the return value from:
messageFactory.create(params)
Which will contain a message ID (messageSID below). You can then fetch this message from the server to get an update on its status with something like:
var params = Map("SID" -> messageSID)
client.getAccount.getSmsMessage(params)
The full list of status are here. But it looks like everything you have should be spot on. Hope this helps.
Related
We are using Twilio Programmable Messaging for sending SMS, in our Kotlin backend service with Twilio SDK.
Gradle dependency
implementation("com.twilio.sdk:twilio:7.51.0")
Also, we are tracking the delivery status of the sent SMS messages. For that, we need to set a status callback before sending an SMS.
val creator = Message.creator(to, from, textMessage)
.setStatusCallback(webhook.smsStatus)
Receiving message status
Our other service is set up for receiving a status callback.
#PostMapping(path = ["events"], consumes = [MediaType.APPLICATION_FORM_URLENCODED_VALUE])
#ResponseStatus(NO_CONTENT)
fun receiveSmsStatus(status: SmsStatus) {
communicationsService.processSmsStatus(status.MessageSid, status.MessageStatus)
}
Everything is working fine and we successfully receive and process SMS delivery statuses.
But every 100th status callback contains payload with nullable MessageSid and MessageStatus. At the same time, it contains payload with From and To phone numbers.
Why might this happen? And is it okay for MessageSid and MessageStatus to be NULL? I thought these fields are required.
I suggest opening a ticket with Twilio support via the Twilio Console (upper right corner under ? - Submit a ticket). If you can associate the outbound SMS SID returned when calling the /Messages resource with the associated statusCallback (say by matching the number the SMS was sent to since the MessageSID is null), that may help Twilio support identify the issue.
Screenshots in the ticket will also be useful for them.
I would like to send a message to a batch of devices by using their tokens because I have different reciever groups that are quite dynamic and can change. I have my groups defined on the backend Spring Boot server and the Message.Builder has only a "setToken" method. Does this mean that i have to loop through all of the tokens to send the message?
Reference: https://firebase.google.com/docs/reference/admin/java/reference/com/google/firebase/messaging/Message.Builder.html
The documentation for sending messages to multiple devices suggests that you need to use MulticastMessage for that.
// Create a list containing up to 100 registration tokens.
// These registration tokens come from the client FCM SDKs.
List<String> registrationTokens = Arrays.asList(
"YOUR_REGISTRATION_TOKEN_1",
// ...
"YOUR_REGISTRATION_TOKEN_n"
);
MulticastMessage message = MulticastMessage.builder()
.putData("score", "850")
.putData("time", "2:45")
.addAllTokens(registrationTokens)
.build();
BatchResponse response = FirebaseMessaging.getInstance().sendMulticast(message);
// See the BatchResponse reference documentation
// for the contents of response.
System.out.println(response.getSuccessCount() + " messages were sent successfully");
I have sent my mail through java mail and registered my email on Amazon to get the response notifications (Bounce, Delivered) etc.
How can i succesfully match these two to say when i have sent the mail, the mail i sent has the following incomming response.
Note: Everything is setup (Webhooks to get the response from AWS SNS)
I tried matching it by the messageId, but it seems aws adds a different messsageId than the java mail one. Example
MimeMessage msg = new MimeMessage(session);
msg.getMessageID(); // returns "<1619401941.3.1560500581268#Tinus-NB>"
And the from the AWS SNS response
"MessageId" : "7cd42bc4-e5c2-576b-a567-7eb9baa51cad" // directly
"Message" : "{\"notificationType\":\"Delivery\",\"mail\":{\"timestamp\":\"2019-06-14T08:38:55.113Z\",\"messageId\":\"0102016b5523c189-55acd572-ba3f-4750-aaae-b7019080f1ae-000000\",\"delivery\":{\"timestamp\":\"2019-06-14T08:39:03.043Z\",\"processingTimeMillis\":7930,\"smtpResponse\":\"250 2.0.0 OK 1560501543 f15si1572805ede.113 - gsmtp\"}}" // this is in the Message object in the JSON
Just to be clear, I want to match these two, to know what i sent and what the response was.
I am using Java Mail and not the AWS SDK lib
SES overwrites MessageID whatever you set because it also needs to know which email is it. In your case, when sending emails from Javamail,in the last section of your code, you can print the 250 response code+ message ID from SES and match it with the message ID you received from SNS.
When SES accepts an email in SMTP conversation, it gives 250 ok+ message ID and the same message ID can be seen in SNS notification.
Found it, i just had to include the original headers
I am creating a program that asks the user something like "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());
And then then the program will listen for whatever response the user texts back from their phone.
Now, Twilio says this about receiving SMS:
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.
Now, I understand that when the user texts back, Twilio makes an HTTP request to my program, like so:
However, in the tutorial, they create an HTTP tunnel using ngrok to allow the HTTP request to go through. My application is supposed to be able to run in anyone's computer without prior configuration. How would you recommend I achieve this?
I'm afraid that without exposing your application to the Net you won't be able to use that particular API.
What you can try to do instead is polling / fetching:
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.
A short example to start with is available here.
I am using the gcm-server.jar to send gcm Messages from Server because its easy to use. (http://www.java2s.com/Code/Jar/g/Downloadgcmserverjar.htm).
Messages are sent with this code. This works fine:
Message msg = new Message.Builder().addData("message", message).build();
Sender sender = new Sender();
Result result = sender.send(msg, token, 5);
...
How can I send a GCM Message with Notification Payload like in this JSON:
{"to":"token" ,
"notification":{
"sound":"default",
"badge":"1",
"title":"this is the title",
"body":"this is the body"}}
You need to have a server set up where you parse these messages in JSON format so that GCM can process it accordingly.
Usually this depends on what server technology you are using. Also, you might want to check the validity of the library you referenced as GCM framework has been updated substantially.
Here's a good place to start.
And another good tutorial here. (although this one is older too but gives you understanding of server side implementation)
Hope this helps!