Forward media attachments in Twilio studio - twilio

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!

Related

Is there a way to x-callback from Telegram to another app?

I am creating a Telegram bot and need to x-callback to another application.
This is my x-callback that opens VLC and streams a video. It works fine when I use it in Siri Shortcuts or in Safari. But I need it to work on Telegram chat conversation.
vlc-x-callback://x-callback-url/stream?url=https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4
When I send it as raw text it obviously doesn't recognize it as a valid url and does nothing.
I have tried to format it Markdown, MarkdownV2 and HTML styles but none works.
I've also tried InlineKeyboardButton giving it the text and url but it throws a BadRequest error
telegram.error.BadRequest: Inline keyboard button url is invalid
Is there any workaround to x-callback from Telegram to another app?
My question is implementation independent, but here is my code using python-telegram-bot
from telegram import Update, ParseMode, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import CommandHandler, CallbackContext, Updater
my_x_callback = 'vlc-x-callback://x-callback-url/stream?url=https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4'
def test(update: Update, context: CallbackContext):
update.message.reply_text(my_x_callback)
update.message.reply_text(f'[Play it on VLC]({my_x_callback})', parse_mode=ParseMode.MARKDOWN)
update.message.reply_text(f'[Play it on VLC]({my_x_callback})', parse_mode=ParseMode.MARKDOWN_V2)
update.message.reply_text(f'Play it on VLC', parse_mode=ParseMode.HTML)
button = InlineKeyboardButton('Play it on VLC', url=my_x_callback)
update.message.reply_text(
'Testing InlineKeyboard',
reply_markup=InlineKeyboardMarkup([[button]])
)
if __name__ == '__main__':
updater = Updater('TOKEN')
updater.dispatcher.add_handler(CommandHandler('test', test))
updater.start_polling()
updater.idle()
I had a similar use case once where I wanted to use mailto: links. My workaround is to create a website URL that points to the mailto: link. I.e. flow is:
Generate mailto link depending on users request
Generate https:// url that points to the link - in my case that's done via a self-hosted YOURLS instance
used that generated URL either for an inline buttton or as text link.

How to collect images with a Whatsapp bot using Twilio

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.)

How to send a link via MFMailComposer?

My actual problem is to send a link with a YouTube-Adress per email with Swift.
I use MFMailComposer and sure, it´s no problem to attach a file. But a link?
Is there any way to attach a link only, so the receiver can click the link that calls the YouTube-Page???
Just use HTML for that purpose:
// Add your body in a HTML format
let body = "<p>This is a test. Check out the link to youtube</p> YouTube"
// In your mail instance in setMessageBody, add your body and set isHTML to true
mail.setMessageBody(body, isHTML: true)
Update
If you don´t need a placeholder you could just add http://... URL in the email text as #rmaddy commented.

How to parse email message as html format when there is no attachment

I am new in using IMAP. Now I am trying to use IMAP to see my emails in my web page from mail server. I have configured the settings. And I think the configuration is ok. Now I want to show the message body as html format. My code is:
// getting email body text
if($attachments[1]['is_attachment']!=""){ // if attachmentavailable.
$part_number = '1.2';
}
else{
$part_number = '1';
}
$message = quoted_printable_decode(imap_fetchbody($inbox, $email_number, $part_number));
When email has attachment, it is showing as html format. But when there is no attachment the message is showing as plain text. There is no bold or any other formatted font if I give and there is no link also.
If I use part number 1.2 in else part no message is shown.
Now how can I print email message as html format where there is no attachment.
Learn about the BODYSTRUCTURE format. E-mails can come up in about a ton of different structures, and unless your application actually takes a look at the structure of the MIME message, your code is blindly guessing what to do.

How to fetch mail by id with barbushin imap class

I'm currently working on the imap class by barbushin. It's the only php class over the internet I can find regardless to any encoding issue. Thanks to the coder.
I have a list of messages in a table. Each message sending a message id as GET (say $mid). When a link clicked, the page turned into a view page. It should open that message and display the relevant content right? But it is not. Every message has the same content (the 1st content). The code is designed for gmail but I use it for my client. And it's work.
This is a code:
require_once('../ImapMailbox.php');
define('EMAIL', 'my#domain.com');
define('PASSWORD', '*********');
define('ATTACHMENTS_DIR', dirname(__FILE__) . '/attachments');
$mailbox = new ImapMailbox('{imap.gmail.com:993/imap/ssl}INBOX', EMAIL, PASSWORD, ATTACHMENTS_DIR, 'utf-8');
$mails = array();
// Get some mail
$mailsIds = $mailbox->searchMailBox('ALL');
if(!$mailsIds) {
die('Mailbox is empty');
}
$mailId = reset($mailsIds);
$mail = $mailbox->getMail($mailId);
var_dump($mail);
var_dump($mail->getAttachments());
The original is here: https://github.com/barbushin/php-imap
Finally, I found my way home. According to the script there's a line says "mailId". Which is straight forward what is it about.
It was set to the first array by reset(). So the only thing I need to do is extract the message id from it ($mailId is an array of ids). So I simply add an array behind it.
$mailId=$mailsIds[$_GET[uid]];
While $_GET[uid] is a message id sent from a previous page.

Resources