0

I have this bit of code to send an MMS message with a GIF. (using Ruby with Sinatra, hosted on Heroku).

client.messages.create(
  to: to,
  from: phone, 
  body: message,
  media_url: 'http://media.giphy.com/media/zl170rmVMCpEY/giphy.gif'
)

It fails, and Twilio's debug console shows a 12300 invalid content-type error. I'm certain I'm missing something simple here, but I cannot figure out what.

1 Answers1

1

The URL you are using is returns a different type of content based on the Accept header of the request.

In Chrome a response with a "Content-Type" header of "text/html". Which is surprising given the .gif suffix on the URL.

Chrome accept headers look like: Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

However if I use curl -I http://media.giphy.com/media/zl170rmVMCpEY/giphy.gif I get Content-Type: image/gif

If you look at the image URL on the HTML page, in Chrome, it is actually: https://i.giphy.com/zl170rmVMCpEY.webp

webp is an alternative format to gif, I suspect it is served instead of gif if the browser supports it.

If Twilio supports webp format images you could use that instead.

Gify also seem to use mp4 format, it looks like they brand as gif, but don't actually serve gif's to clients which can accept HTML or WebP content.

Kris
  • 19,188
  • 9
  • 91
  • 111
  • Huh. How come an example [like this](https://www.twilio.com/blog/2014/10/send-daily-animated-gifs-using-firebase-giphy-node-js-and-twilio-mms.html) works? (under header: Sending A Gif On Signup). I know this is node.js and not Ruby, but I'd guess the link works the same. –  May 22 '17 at 20:34
  • Maybe gify changed the way they serve content since this was written. – Kris May 22 '17 at 20:36
  • `curl -I http://media.giphy.com/media/zl170rmVMCpEY/giphy.gif` shows the Content-Type as `image/gif`. – Kris May 22 '17 at 20:39
  • Based on all of this, is there a way I can force Giphy to return an image/gif? –  May 22 '17 at 20:53
  • Maybe, but I think that is a separate question and may depend on the HTTP client Twilio use to fetch the URL (i.e. what the value of the `Accept` header looks like). – Kris May 22 '17 at 22:00