Sending my own image to slack

Skip to first unread message

Aug 22, 2015, 8:11:42 AM8/22/15
to Lita
Hi all,

I'm not really sure what's the best way to do this.

I want to create an image with text overlayed (using rmagick) and reply to slack with this image.
Something like : lita <image> <text> would generate an <image_with_text>

As I understood from a previous discussion here, I can't send this image back as an attachment to slack.

Can I use built-in http server to serve this image to slack? If yes, how?
Or should I use my own http server to display it? By copying files to the http server directly?

Thank you for your help, I love this bot!


Jimmy Cuadra

Aug 22, 2015, 8:48:27 PM8/22/15
to, Lita
Hi David,

There are a few ways you can approach this, but ultimately it comes down to storing the generated image file on a web server and sending a link to that file to Slack via Lita. For the Slack users to be able to see the image when the click on it, it must be hosted on a server where the user has network access, either publicly or within a private network (or VPN). It can also be hosted on a publicly accessible server.

Where you store the generated image file and how you transfer it there is up to you. The two approaches I'd probably consider myself are 1) using a service like Amazon S3 and using their Ruby API client (or a simple HTTP client) to upload the file 2) storing the file locally on the same server Lita is running on and make it publicly accessible.

For the latter, an easy way to serve the image would be to use Rack::Static Another option would be to use an HTTP route within Lita to read and respond with the file manually using the provided Rack::Response object.

Hope this helps!

You received this message because you are subscribed to the Google Groups "Lita" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
For more options, visit

David Alia

Aug 23, 2015, 8:01:00 AM8/23/15
to Jimmy Cuadra, Lita
Hi Jimmy,

Thanks for this clear and detailed answer.
S3 was my first idea, but I thought latency would be too high.

I'm sorry I didn't get the last part with the HTTP route within Lita, could you help me?

Thank you

Jimmy Cuadra

Aug 23, 2015, 8:28:54 AM8/23/15
to David Alia, Lita
Sure! Something like this:

http.get "/my_handler/:name.png do |request, response|
  file ="path/to/generated/images/#{request.env["router.params"][:name]}.png", "rb")
  response["Content-Type"] = "image/png"

This is a very naive implementation since it would allow any user input from the HTTP request to read an arbitrarily named file on the local disk, and reads the entire image file into memory at once, but it should be enough to give you an idea what the interface might look like.


David Alia

Aug 25, 2015, 8:59:07 AM8/25/15
to Jimmy Cuadra, Lita
Hi Jimmy,

Thanks a lot for your help, I'm quite new to ruby and this helps me!

I have tried to find examples of Lita http routes on Google, but didn't find anything (except your own code :)).

I did not clearly understand how these http routes can be triggered indeed...

Here is my use case, and how I wanted to solve it:

1) using a chat route to process text and image: route(/<cmd> <text>/, :cmd)
2) saving the generated image to disk
3) respond to slack with something like "http://<lita-http-server>/<my_handler>/path/to/:generated_image.jpg"

and that would be enough for slack to display this image.

I thought that the code you provided could allow to handle this url, but I'm (dumb and) stuck since:

- I don't know what to fill for <lita-http-server>
- I don't know how to have the http route triggered
- I thought I wouldn't have to implement such code (opening file, sending the content to the response) since Slack is able to display an image when he fetches the URL directly and recognizes an image file. In fact, I assume this is how it works but I am not sure since I can't make it work for the moment

Again, thanks for you time.

Jun 8, 2017, 1:46:57 AM6/8/17
to Lita,,
I second what David here says. Its been 2 years since this discussion started and neither you nor the entire Internet solve what David asked for. I have run into a similar problem as well and it would be plenty useful if you could either provide proper documentation with illustrative examples for Lita or give a homemade example as to how you would go about solving this problem.
Reply all
Reply to author
0 new messages