2

I have a script which uses a gem that has eventmachine which listens for an API call (it's the slack-api gem).

On my dev environment, I just run bundle exec ruby ruby_slack.rb and the console shows that it is listening. When the API call hits, then I see the stdout.

How do I have this same behavior in heroku?

I created a Procfile which has: web: bundle exec ruby slack.rb but I think it's just waiting for a request from the web app to run it.

I want this to run (and keep running) listening for events.

Thanks.

Satchel
  • 16,414
  • 23
  • 106
  • 192
  • Did you try setting it up as a Rack application? – MIdhun Krishna Jun 20 '15 at 07:12
  • I don't know how to do that. I can google it. What does this enable me to do? – Satchel Jun 20 '15 at 15:08
  • Rack acts as a web server interface to your application written in ruby. http://stackoverflow.com/questions/2256569/what-is-rack-middleware. btw, is there any way you can show what your application looks like? – MIdhun Krishna Jun 20 '15 at 16:08
  • How would I show it? There's no web interface. Is just waits for an API call in a do loop. It uses a real time API that messages and it looks like event machine picks it up and then runs it. How do I enable rack in Heroku? Looks like I could use a config.ru file but wanted to see if there were a similar example of a persistent listener. – Satchel Jun 21 '15 at 04:20

1 Answers1

0

You need a web server that responds on the port that Heroku asks it to respond and a thread for websocket processing. For example with Sinatra:

require 'sinatra/base'

module MyBot
  class Web < Sinatra::Base
    get '/' do
      'Hello world.'
    end
  end
end

Thread.new do
  # run your Slack RealTime bot here
end

run MyBot::Web

This is captured in this tutorial. Also generally try slack-ruby-bot which does all the heavy lifting for you.

dB.
  • 4,700
  • 2
  • 46
  • 51