Proper way to NOT send a reply back from webhook - twilio

I have setup a webhook and everything is working properly, however iam used to using a long number where STOP is handled automatically, but now I have a short code where we have to handle STOP ourselves. This isnt an issue on sending a message as I can check with my 'blacklist' numbers before sending the message. My question is in the Reply webhook, what is the best way or standard way to NOT send the reply message.
Below is twilios sample code (i added the comment where i would check if they are black listed)
public class SmsController : TwilioController
{
public TwiMLResult Index(SmsRequest incomingMessage)
{
var messagingResponse = new MessagingResponse();
// check for phone number in blacklist to NOT SEND
messagingResponse.Message("The copy cat says: " +
incomingMessage.Body);
return TwiML(messagingResponse);
}
}
If the number is blacklisted and i dont want to send the reply how do I "gracefully" not reply to them as this example takes a TwiMLResult and message response. Do i just set the message to an empty string ? do I return null? Any thoughts ? Thank you !

Related

Status call back URL in twilio

I want to get the status of my call while using twilio.
I am configuring a status call back url for the same which is accepting a Post verb. But not sure What should the method of the REST webservices have in its POST method? If Twilio is posting back the status, then what should the POST method of the webservices do? Not able to get a idea on this, please help..
I am programming it in .net
Twilio developer evangelist here.
The status callback requests will send all the regular parameters that any Twilio Voice webhook sends as well as a few extra parameters that you can find in the documentation here.
Finally I found a solution how to get back status from twilio. Just design an Http Handler and use the context property to get back the parameters. The handler should look like this:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim callsid = context.Request.Params.Get("CallSid")
Dim FromNumber = context.Request.Params.Get("From")
Dim ToNumber = context.Request.Params.Get("To")
Dim callStatus = context.Request.Params.Get("CallStatus")
' ...
End Sub

getting null response from recieveAndConvert() spring -amqp

I have created on replyQ and done biniding with one direct exchange.
Created the message by setting replyto property to "replyQ"
And sending the message on rabbit to the other service.
The service at other end getting the message and sending reply on given replyTo queue.
and now I am trying to read from a replyQ queue using
template.receiveAndConvert(replyQueue));
But getting null response and i can see the message in the replyQ.
That is the service is able to send the reply but am not able to read it from the given queue
Please help what is going wrong.
template.receiveAndConvert() is sync, blocked for some time one time function, where default timeout is:
private static final long DEFAULT_REPLY_TIMEOUT = 5000;
Maybe this one is your problem.
Consider to switch to ListenerContainer for continuous queue polling.
Another option is RabbitTemplate.sendAndReceive(), but yeah, with fixed reply queue you still get deal with ListenerContainer. See Spring AMQP Reference Manual for more info.
I don't know if this could help anyone, but I found out that declaring the expected Object as a parameter of a method listener did the work
#RabbitListener(queues = QUEUE_PRODUCT_NEW)
public void onNewProductListener(ProductDTO productDTO) {
// messagingTemplate.receiveAndConvert(QUEUE_PRODUCT_NEW) this returns null
log.info("A new product was created {}", productDTO);
}

StatusCallback does not work as expected

Overview:
I am working on a VB.NET application that places a call into Twilio, the number is not a test number. I am using the C# library with the code written in VB.Net.
When I use this line of code:
Console.WriteLine(account.SendSmsMessage(Caller, to1, strBody))
I receive a text message on my phone however the post back is never posted to my website. I have included the URL of the site on the account under Messaging > Request URL.
When I reply to the message, Twilio does make a post to my site. From what I understand, a POST should have been made when Twilio was first sent a message from my application, however this is not the case.
When using this code, I do not get any text message and no POST is made.
Console.WriteLine(account.SendMessage(Caller, to1, strBody, PostBackURL))
I have tried SendSMSMessage, I have tried it with the URL on my account and without it,
nothing seems to effect the behavior.
I need the SmsMessageSid at the time the message is sent. From everything I have seen, Twilio does not provide a response other then what is sent to the PostBackURL, I could parse a response for the
SmsMessageSid however since there is no response that is not an option. If I am mistaken on that point that would be great, however it looks like the only way to get a reply is with the post back URL. Thanks for your help with this! Below you will find an excerpt of the code I am working with:
PostBackURL = "http%3A%2F%2F173.111.111.110%3A8001/XMLResponse.aspx"
' Create Twilio REST account object using Twilio account ID and token
account = New Twilio.TwilioRestClient(SID, Token)
message = New Twilio.Message
Try
'WORKS
'Console.WriteLine(account.SendSmsMessage(Caller, to1, strBody))
'DOES NOT WORK
Console.WriteLine(account.SendMessage(Caller, to1, strBody, PostBackURL))
Catch e As Exception
Console.WriteLine("An error occurred: {0}", e.Message)
End Try
Console.WriteLine("Press any key to continue")
Console.ReadKey()
I'm doing something similar with C# and like you, I'm not getting the POST to the callback URL. I don't know why that's not working, but if all you need is the sid when you send the message, you should be able to do this:
message = SendSmsMessage(Caller, to1, strBody))
and message.Sid will give you what you need, assuming no exceptions.

Message-Id is being replaced when sending mail via JavaMail

I have tried to find a solution to this with any luck, so i decided to post it here.
The problem is, when i send a message with javaMail, it automatically generates a Message-Id (The one i store into my database to then identify replies to this message) but it is being changed for some reason by the smpt server when the message is sent so i wont be able to trace any related to this message.
For example
I first send a message via gmail to one of the accounts sycronized with my mail client, then i check the message with my message client and everything is ok the Message-Id is
<CAPDSfCN1qPAhBCRmFK-zwP=MM=KjgpYuvhVRFAPwz1PjOqtnFA#mail.gmail.com>
Then i send a reply for this message via my message client, the id generated by javaMail is
<1907960987.0.1322086080735.JavaMail.root#smtp.live.com>
Finally, when i go to check the reply in my email account it has the following values in its headers
Message-ID: <BLU0-SMTP33091BE2B32A7F46E370665C2C90#phx.gbl> FAIL
In-Reply-To: <CAPDSfCN1qPAhBCRmFK-zwP=MM=KjgpYuvhVRFAPwz1PjOqtnFA#mail.gmail.com> OK
As you see, the Message-Id is changed, i was expecting it to be
<1907960987.0.1322086080735.JavaMail.root#smtp.live.com>
Why is this happening?
I appreciate any help
Thank you all
--Edit
According to sugestions i made a test using smtpsend demo from javaMail (I implemented a subclass of MimeMessage to generate my own Message-Id).
java -jar -Dmail.smtp.starttls.enable=true -Dmail.smtp.port=587 SMTPSend.jar -d -M smtp.live.com -U myaccount#hotmail.com -P mypass -o myaccount#hotmail.com -A anotheraccount#gmail.com
Between smtpsend output when message was sent, there was the Message-Id generated
<60eea6ae-2657-41bd-b475-3a57eff885ac#mydomain.com>
But then, when i went to check this message on anotheraccount#gmail.com, the Message-Id was different
<BLU0-SMTP109215E6BB99B93FC106B1E88B00#phx.gbl>
Why is it changing my Message-Id on the fly... i dont get it
--Edit 2
I noticed that the problem is now happening just when i send mails from a hotmail account
message-id is not changing anymore when i send mails from a gmail account (i think that implementing my own Message-Id generation method helped to solve that)
Thanks for replying
I know this is an old thread, but this answer could still maybe help people.
You need to overrule updateMessageID() in MimeMessage as it gets called everytime before sending an e-mail.
class MyMessage extends MimeMessage {
public MyMessage(Session session) {
super(session);
}
protected void updateMessageID() throws MessagingException {
setHeader("Message-ID", "<your-message-id#domain.nl>");
}
}
And if you would like to pass the unique id for each MyMessage...
class MyMessage extends MimeMessage {
String uniqueMessageId;
public MyMessage(Session session, String uniqueMessageId) {
super(session);
this.uniqueMessageId = uniqueMessageId;
}
protected void updateMessageID() throws MessagingException {
setHeader("Message-ID", "<" + uniqueMessageId + ">");
}
}
And then call it, eg:
MyMessage message = new MyMessage(session, "201610131428_newsletter1#domain.nl");
We've encountered the same issue with Simple Java Mail and as far as I know the only way to catch the actual ID assigned by the SMTP server is to parse the 250 OK response which includes it (in case of MS Exchange).
As Bill (the prime author of the original JavaMail) mentions below, the SMTP server should actually never change the Message ID, but some servers like MS Exchange explicitly allow configuration otherwise. For example see: https://social.technet.microsoft.com/Forums/en-US/132df54c-871b-4e9d-98c9-5b5caa993322/custom-message-id-replaced-by-outlook-smtp-server?forum=exchangesvrclients.
If you are seeing this behavior with all servers you connect to, chances are you are not setting MessageID the right way (Java/Jakarta Mail is a little obtuse about this). In that case refer to the other answer.
Your mail server is broken. It should not be changing the Message-ID header.
Report the problem to the owner of your mail server.

how to share a link via sms in blackberry

I am building an application where I need the option to share via email and SMS.
I have done the share via Email, where when the user selects the image, the url is passed as the content of the email. But while sharing via SMS, I can't do something like setContent as I did for email and fetch the url in the SMS directly, instead of user typing the address manually.
I am using Message class in email and MessageConnection class for SMS, as shown in the blackberry community example.
The Message object you receive when calling MessageConnection.newMessage(TEXT_MESSAGE) is actually a TextMessage object (or a BinaryMessage object with BINARY_MESSAGE).
If you cast the received object to the proper class (TextMessage or BinaryMessage), you should be able to use its setPayloadText(String data) (or setPayloadData(byte[] data) for a BinaryMessage) to enter a value in the message before sending it.
Your code should look like this:
Message msg = myMessageConnection.newMessage(TEXT_MESSAGE, /* address */);
TextMessage txtMsg = (TextMessage)msg;
txtMsg.setPayloadText(/* Text to send */);
myMessageConnection.send(msg);
When you send an email, you can set the body of it and send it to the user from the Email native application. You cant do taht for SMSs. I worked on that issue and for BB Torch I was able to set the text of the SMS message but for other devices that was impossible. I always obtain an empty text message!!
So y suggestion to you is using the following code wich will send the SMS to a number without the interference of the user
MessageConnection conn = (MessageConnection) Connector.open("sms://" + userNumber);
TextMessage txtmessage = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
txtmessage.setPayloadText(text);
conn.send(txtmessage);

Resources