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.
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 have programmed a telegram bot. This works fine when sending to groups or to users. However I do a special requirement. I need to be able to send to another bot. When adding both bots to a group as administrators. I still cannot receive the message with my second bot. I only see it with my real user account, that is added to this group.
What am I missing?
I used OKHttp to send the message
Request request = new Request.Builder()
.url("https://api.telegram.org/bot"+telSetup.getToken()+"/sendMessage?chat_id="+lAdr+"&parse_mode=HTML&text="+strMessage)
.build();
client.newCall(request).enqueue(new MyIPProcessing(request.toString()));
and
if (response.message().equals("OK")){
List <String> lStr=response.request().url().encodedPathSegments();
...
to receive messages ... which basically works for communication with "real users".
Any ideas welcome ....
According to Bots FAQ
Bots talking to each other could potentially get stuck in unwelcome loops.
To avoid this, we decided that bots will not be able to see messages from other bots regardless of mode.
You can connect 2 (or more) bots with a private channel!
Just prompt the bots as admin in the channel.
Then when a bot send a post to the channel, other admin bots can see the message/file/...
Bot wouldn't be able to send message to other bots. in most platform APIs it return an error. kindly go through the documentation for the client(bot) and see its functionalities
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!
I am trying to send a GCM message to my device, and for some reason, on the server, the getErrorCodeName() is returning InvalidRegisration.
I basically implemented the example from google, and registered, and sent the registration ID to the log, and wholesale copied it from the log to the code on the server where I am trying to do the send.
Any idea on what could be wrong?
Result result = sender.send(message,"foo", 1);
System.out.println("Message sent: "+result.getErrorCodeName());
I have double checked to see that logcat is not truncating the value being printed out, and it isn't. I logged the length of the registration id and matched it with the length of the string/regid I'm using on the server when I am sending the notification.
Not sure what's going on.
The send() method has to follow this format:
send (Message message, String registrationId, int retries)
Looking at your snippet of code, you will need to revise the second parameter.
If you had just replaced the actual registration ID for privacy reasons, I would suggest checking that you are sending the registration ID completely. As mentioned here, it could have been truncated or altered in transit from your client device to your server.
I am using the Twilio java wrapper provided on the website and started making some tests. 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).
I understand that when you make a REST request to Twilio to send a SMS, Twilio responds with the Status. How could I get this response?
Here is the explanation page I found: 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. You can use this information to do more processing on the SMS message. There's more information here: 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. 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.
I recall that the response comes to your url and can be matched up by an ID. In the REST post to SMSMessages you can specify a statuscallback url where Twilio will post a status message to your 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.
In 2020, with the Java SDK, you can now create a MessageFetcher with that SID and then call fetch to ask for the Message instance until its getStatus returns "delivered", "undelivered", or "failed".