Responding to Media

Let’s say that a user has sent your bot a fun gif with a polar bear rolling through the snow. You might want to have your bot reply to this incoming image.

All incoming media on Facebook and Twilio can be responded to by using the special __media__ trigger.

If a user sends an image to a bot, the bot can have a response specifically for incoming media requests by including a trigger, like so:

+ __media__
- You look stunning!

The url and type of the last media attachment sent by the user to the bot can be accessed through the _mediaUrl and _mediaType namespace variables and these variables can be used within future responses.

+ __media__
* <get _mediaType> == image => Oh wow, you look exactly like me!  <send> See, check out my selfie.  ^image(<get _mediaUrl>)
- That’s not a picture, show me your face!
Twilio also offers the MIME type of incoming media, which can be accessed through the namespace variable _mediaTypeDetailed.

Media types supported

The kind of incoming media supported is dependent on the platform itself. As of April 2017,

Storing incoming media

Bear in mind that the _mediaType and _mediaUrl variables will be rewritten each time that user sends media to the bot.

If you would like to make use of an incoming media url later in your bot script, it is best practice to save that value in a separate bot variable.

+ __media__
- Did you just send me a selfie? ^buttons(Yes, No)
 
+ yes
- Sweet, now I can stare at it all the time. <set selfieUrl=<get _mediaUrl>>
 
+ no
- No!? Send over a selfie!