Add buttons in whatsapp message response twilio - twilio

I currently have the following code which successfully replies any message I send with "Ola":
#app.route("/bot", methods=["POST"])
def bot():
incoming_msg = request.values.get('Body', '').lower()
resp = MessagingResponse()
msg = resp.message()
quote = 'Ola'
msg.body(quote)
return str(resp)
I would like to have response buttons to my reply. Please see attached image, I'd like to add the "Got it" button with my message text. Is that possible for python. Thanks.

To send quick reply or call to action buttons over WhatsApp using Twilio, you need to create a template and add the buttons to the template. To trigger the template, you need to send a message containing the text of the template in the body. This is all covered in more detail in the Twilio documentation on using buttons in WhatsApp.
Note, you need to have a working WhatsApp number in your account to create and send templates. You cannot use the Sandbox to test out this feature.

Related

Tweepy bot to tweet DMs

I would like to make a bot on twitter to use with my friends, it would be like a spotted. The bot would need to tweet the messages they send on his dm. On the internet I found this function, but I don't know if it's right, nor how to close this puzzle, can someone help me?
api.list_direct_messages()
You can get the DM messages with
auth = tweepy.OAuthHandler('api_key', 'api_secret')
auth.set_access_token('access_token', 'token_secret')
api = tweepy.API(auth)
messages = get_api().list_direct_messages(count=5)
The code above would rin in a thread to fetch the messages every x minutes.
Once you have the messages you can process the list, send the tweet and delete the DMs (to avoid processing it again).
for message in messages:
text = message.message_create["message_data"]["text"]
api.update_status(f'Tweet DM content: {text}'
# remove DM
api.destroy_direct_message(message.id)

Twilio Send Message API Error 21603

I'm using postman to see the response format of send message api in Twilio. The Api that I'm using is https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages.
I have entered the basic authentication parameters (Account_Sid and AuthToken as username and password) the json request format is
{
"To":"My Number",
"From":"Twilio Number",
"Body":"Hello this msg is from postman"}
But I'm getting error 21603 which states "A 'From 'phone number is required". Can you please tell me where I'm wrong. The messages are sent when using Twilio console.
I can't see your Postman but, maybe this is what you're missing...
Click on the Body tab and make sure form-data is selected from the radio buttons.
Also if you go to Twilio docs page (https://www.twilio.com/docs/sms/send-messages) you can see the expected response if you click on the OUTPUT link (tab) that is located at the top right of the code sample.

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.

iOS in MessageComposer add image and text

I want to send MMS in iOS and for that I will be using Message Composer API.
Now I can send mms by adding text in body and image as attachment.
But I want to send message which will be combination of image and text:
ex :
Hi [image] how are you [image] .
How can I achieve this.
Sending MMS via MFMessageComposeViewController is available in iOS 7 only:
First check if you can send MSS with the canSendAttachments method:
if ([MFMessageComposeViewController canSendAttachments]) {
// YES we can send a MMS
}
The easiest way is to use addAttachmentURL:withAlternateFilename: to attach attachments to you messages. You are not able to get your image in the middle of the text.

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