I've created a Whatsapp chat bot that collects various user information but I am unable to collect an image that a user sends. How can I do this? Is it a matter of using the right Field type, which I've tried doing but none of the default field's apply to images? Please help if anyone knows of a solution.
Heyooo. 👋 Twilio Developer Evangelist here.
If a User sends an image via Whatsapp the image URL will be available in the sent webhook. You can have a look at the payload the webhook includes:
body: {
MediaContentType0: 'image/jpeg',
SmsMessageSid: 'MM9...',
NumMedia: '1',
SmsSid: 'MM9...',
SmsStatus: 'received',
Body: '',
To: 'whatsapp:+141...',
NumSegments: '1',
MessageSid: 'MM9bc...',
AccountSid: 'ACa34...',
From: 'whatsapp:+49176...',
MediaUrl0: 'https://api.twilio.com/2010-04-01/Accounts/ACa34bb5d3c305d08ae1308786f4d79b72/Messages/MM9bc3...',
ApiVersion: '2010-04-01'
}
You'll find the NumMedia and MediaUrl0 property which includes the URL of the sent image. You can then download these images and do whatever you like with them.
To retrieve the image after the message and webhook were sent you can have a look at the MediaResource Docs. You can fetch media also programmatically with something along the following lines:
client.messages('MM...')
.media('ME...')
.fetch()
.then(media => console.log(media.contentType));
In case you're using Studio you can have a look at this tutorial which handles Whatsapp Media with a fun use case.
Let me know if that helps. 😊
(It's hard to give more advice because I'm not sure what you're trying to do.)
Related
I am setting up a workflow to forward all incoming text messages to zendesk. I used the send message widget and in the body added:
BODY: {{trigger.message.Body}}
MEDIA: {{trigger.message.Media}}
The body sends as expected. But I cannot get the media to send. I would even take a URL that directs to where the media is.
Solved! It is:
{{trigger.message.MediaUrl0}}
You can then use that also in that exact text in the Media URL field and it works!
I have this code in laravel
$client->calls->create(
array(
'from'=> '+6326263667',
'to'=> ???,
'url'=> 'twilio bin url'
)
);
I don't know what to put in the "to" array. I'm copying the node version of this like:
client.calls.create({
from: from,
to: process.argv[2],
url: url
})`
it there any other way if not like this?
Twilio Developer Evangelist here.
The to field is expecting the telephone number (in E.164 format) you wish to call.
In your Node example there, process.argv[2] is referring to the first argument passed to a command line operation.
If you want to learn more, I recommend you check out the Programmable Voice Quickstart for PHP.
I'm using the google gmail api in swift. All is working well, it's compiling etc.
I'm now trying forward an email, the only way I see this possible so far is by using a thread id.
So I'm using the API tester found here to send tests. Will will focus on this. It can be found here1
So I've input this, the "raw" is Base64 URL encoded string.
{
"raw": "VG86ICBlbWFpbFRvU2VuZFRvQGdtYWlsLmNvbSAKU3ViamVjdDogIFRoZSBzdWJqZWN0IHRlc3QKSW4tUmVwbHktVG86ICBteUVtYWlsQGdtYWlsLmNvbQpUaHJlYWRJZDogIDE1YjkwYWU2MzczNDQ0MTIKClNvbWUgQ29vbCB0aGluZyBpIHdhbnQgdG8gcmVwbHkgdG8geW91ciBjb252by4u",
"threadId": "15b90ae637344412"
}
The "raw" in plain text is
To: emailToSendTo#gmail.com
Subject: The subject test
In-Reply-To: myEmail#gmail.com
ThreadId: 15b90ae637344412
Some Cool thing i want to reply to your convo..
when I execute it I get this back
{
"id": "15b944f6540396df",
"threadId": "15b90ae637344412",
"labelIds": [
"SENT"
]
}
But when I check both email account, from and to. None of them say the previous messages but are in the same "thread" or convo.
If anyone can help it would be much appreciated I've spent all day on this issue and half of yesterday and did TONS of research on it.
as stated here I should I'm adding the threaded and In-Reply-To in the right way I believe
The ID of the thread the message belongs to. To add a message or draft to a thread, the following criteria must be met:
The requested threadId must be specified on the Message or Draft.Message you supply with your request.
The References and In-Reply-To headers must be set in compliance with the RFC 2822 standard.
The Subject headers must match.
I'm using the slack-notifier gem to send notifications to my slack channel.
notifier = Slack::Notifier.new "https://hooks.slack.com/services/ABC1234567890"
notifier.ping "Text <#user1>"
That is the general setup in rails.
When I send to #user1 (my coworker), everything is OK.
But if I send it to #user2 (myself), text is displayed without mention creating notification or being a clickable link.
Also, if i send it to a usergroup, #my_team text is same above.
I have also tried !my_team and <#user1|user1> . The output to the slack channel looks like <my_team> or #user1. So it appears it is not parsing correctly.
Why could this be happening?
(Moving my comment to an answer.)
I'd suggest this:
notifier.ping "Text #user1", parse: "full"
The "full" parse mode means you'll get automatic linking of #username, #channelname, etc., just like you get when typing into the Slack website/clients.
In Twilio when the ImageMedia URL is given it is accessing the twilio api as follows
https://api.twilio.com/2010-04-01/Accounts/{account sid}/Messages/{message sid}/Media/{media sid}
If you have manually logged into the twilio API that url redirects to the image located at
http://media.twiliocdn.com.s3-website-us-east-1.amazonaws.com/{account sid}/{image id}
How can I get the direct image ID from the twilio API to include in my web app?
I am working with node.js and every time I try to poll the media resources all I receive is the link to the api.twilio.com and not the mdeia.twiliocdn.com
The library doesn't handle this feature that I can find
However, if anyone else comes across the same problem here is the solution
install request.
Then just get NumMedia and MediaUrl parameters...
if(req.body.NumMedia > 0){
var request = require('request')
request.get(req.body.MediaUrl0).auth(config.twilio.sid, config.twilio.auth, false).pipe(fs.createWriteStream("/var/www/app/public/mms/" + sid + '1.jpg' ));
}
Remember that up to 10 images can be sent so you would just need the logic too gather those extra images.