Giter VIP home page Giter VIP logo

slack-ruby-bot-server's People

Contributors

alexagranov avatar aok-solutions avatar ashkan18 avatar ceebeeuk avatar corprew avatar crazyoptimist avatar darbyfrey avatar dblock avatar duffn avatar jcraigk avatar maths22 avatar swalberg avatar tmsrjs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slack-ruby-bot-server's Issues

sample_app_activerecord Gemfile needs fixing(incompatible versions)

sample_app_activerecord git:(master) bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies....
Bundler could not find compatible versions for gem "activesupport":
  In Gemfile:
    otr-activerecord was resolved to 1.0.0, which depends on
      activerecord (<= 5.0, >= 4.0) was resolved to 4.0.0, which depends on
        activesupport (= 5.1.0)

    otr-activerecord was resolved to 1.0.0, which depends on
      activerecord (<= 5.0, >= 4.0) was resolved to 4.0.0, which depends on
        activesupport (= 4.0.0)

    slack-ruby-bot-server was resolved to 0.6.2, which depends on
      grape was resolved to 0.19.2, which depends on
        activesupport

sample_app_mongoid is fine though.

Have all the Mongo ENV variables in one place.

Extract the checking of the ENV variables into a class method and reuse it from the .yml file to avoid repeating the list. It would also let you add a variable without having to update the .yml in all downstream apps.

Related to #31.

Undefined method 'owner='

I'm trying to use the server/service code from this repository in a Rails app. I'm getting this error:

E, [2016-06-02T15:59:47.186642 #753] ERROR -- : undefined method `owner=' for #<SlackRubyBot::Client:0x007f58c27ef500> (NoMethodError)

I looked here for some indication of what owner might be:

https://github.com/dblock/slack-ruby-bot/blob/master/lib/slack-ruby-bot/client.rb

but there's nothing in that gem that appears to help me with owner. I'm not sure what the intent or purpose of setting owner is.

Document how to add hooks

I’d like to specify my own message hook, which I’d like to be called if the default SlackRubyBot::Hooks::Message handler returns false. I see how to do this if I were creating a SlackRubyBot directly but don’t see how when I’m using SlackRubyBotServer. It would be very helpful if this could be added to the documentation.

Update domain (and other info) on successful connection

I, [2016-08-31T01:38:37.642093 #169]  INFO -- : Starting team game=pong, name=Foo, id=****.
I, [2016-08-31T01:38:37.711036 #169]  INFO -- : Successfully connected to https://bar.slack.com.

It's hard to locate the team by its domain name, bar.

Error with sample active record app - pg version?

Hi,

(newby warning...)

I set up the slack-ruby-bot and now wanted to try the active record sample server app.

After running the bundler, when I try to create the db...

rake db:create db:migrate --trace

...I receive the following error (as part of the trace)

Gem::MissingSpecVersionError: Could not find 'pg' (~> 0.18) - did find: [pg-1.0.0]

I can`t spot where the pg version is being specified as ~> 0.18.

I'm running Ruby 2.5.0.

Any ideas?

delete /app.json, doesn't appear to do anything.

in https://devcenter.heroku.com/articles/setting-up-apps-using-the-heroku-platform-api

To call the API, you need the URL of its source tarball.For this example, use this URL. The API expects the app.json file, that contains this configuration information, to be present at the root of the source bundle’s directory structure.

Heroku doesn't, at least in my deploy and based on my reading of the docs, pick up app.json files from gems. app.json probably should have been deleted in 560295b

LMK, and I'll submit a PR to delete this after I get to #32.

Should add documentation for App, Service, and Server

I'm not using this gem quite how it's described in the readme.

I have a React app that starts the OAuth flow with Slack, and then sends the code to its backend, a Rails app. I'm creating or finding a User and returning a JWT for the React app for the user to sign in, but I also want to ensure a bot is created if it doesn't exist for their Team. The Rails app exchanges the code with the OAuth2 gem. From there, I just copied what happens in the create teams API endpoint into my own code, and I create the Team and start an instance of the bot manually.

I'm not using the included API at all. I'm just using this gem to abstract running a slack-bot-ruby instance for each Slack Team that uses the app. I would already need a Team model for how the app works so it's just adding a Slack bot on top of it.

It would be helpful to have most methods documented so it's easier to integrate this gem into existing projects.

account_inactive when trying to add app

Hello. I had this gem working fine, but now I got this error while trying to add app to a team. I have tried to remove app and add it again, but got the same error too (both on my local machine and on VPS).

Errors is:


17:57:10 web.1  | 76.179.202.171 - - [16/Nov/2016:17:57:10 -0500] "GET /?code=<deleted>&state= HTTP/1.1" 200 1086 0.0024
17:57:10 web.1  | E, [2016-11-16T17:57:10.599181 #2262] ERROR -- : Slack::Web::Api::Error: account_inactive
17:57:10 web.1  |   /home/railsuser/.rvm/gems/ruby-2.3.1/gems/slack-ruby-client-0.7.7/lib/slack/web/faraday/response/raise_error.rb:9:in `on_complete'
17:57:10 web.1  |   /home/railsuser/.rvm/gems/ruby-2.3.1/gems/faraday-0.9.2/lib/faraday/response.rb:9:in `block in call'
17:57:10 web.1  |   /home/railsuser/.rvm/gems/ruby-2.3.1/gems/faraday-0.9.2/lib/faraday/response.rb:57:in `on_complete'
17:57:10 web.1  |   /home/railsuser/.rvm/gems/ruby-2.3.1/gems/faraday-0.9.2/lib/faraday/response.rb:8:in `call'
17:57:10 web.1  |   /home/railsuser/.rvm/gems/ruby-2.3.1/gems/faraday-0.9.2/lib/faraday/request/url_encoded.rb:15:in `call'
17:57:10 web.1  |   /home/railsuser/.rvm/gems/ruby-2.3.1/gems/faraday-0.9.2/lib/faraday/request/multipart.rb:14:in `call'
17:57:10 web.1  | 76.179.202.171 - - [16/Nov/2016:17:57:10 -0500] "POST /api/teams HTTP/1.1" 400 710 0.1070
17:57:10 web.1  | 76.179.202.171 - - [16/Nov/2016:17:57:10 -0500] "GET /api/status HTTP/1.1" 200 113 0.0138

Get email address of Slack user

Hi there,

I was wondering what the best way is to obtain the email address of a user that is sending a message to my bot. I tried calling "users_profile" as follows:

module SlackEvabot
  module Commands
    class Unknown < SlackRubyBot::Commands::Unknown
      match(/^(?<bot>\S*)[\s]*(?<expression>.*)$/)

      def self.call(client, data, _match)

        email_address = client.users_profile(user: data.user)   # Doesn't work!

        client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand '#{data.text}'.", gif: 'understand')

      end
    end
  end
end

But I get the following error:

`undefined method `users_profile' for #<SlackRubyBot::Client:0x00007f83383d2ad0>

Use Team ID in commands

Hi!

I'm building a bot with custom methods and one command looks like this,

match /^Start the course (?<slug>\S+)$/i do |client, data, match|
    subscription = Dailybitsof.create(data.channel, match['slug'])
    client.say(channel: data.channel, text: "#{subscription}")
end

But I need to send the team_id to the method and I can't figure out how. Is there any simple way?

How to use OmniAuth in this project?

Hey there,

I would like to use OmniAuth to allow users to to connect Facebook to my slackbot. Does anyone have a good starting point to work from? :)

Many thanks,
Sherman

Reloading the server team object when modifying from the API

Hi,

I'm working on a bot where the API can make changes to the Team object but the changes aren't reflected in the bot until it's restarted. I was able to follow the example from the market bot, where the Stripe payment is recorded and can verify that if I reload the document from MongoDB, that the changes are there. However the bot code doesn't see it until I restart the server. I see that the Server instance for that team has a persistent copy.

For example:

  • ask the bot to dump the team (client.say(channel: data.channel, text: client.owner.inspect))
  • from a console, team.update_attributes!(thefield: 'testing')
  • ask the bot to dump the team again, note that it hasn't changed
  • reload the bot
  • ask the bot to dump the team again, thefield has changed.

I've followed the Stripe code from the example bots and don't see the object gets reloaded. Could you provide some advice, please?

Thanks.

How to ignore messages posted by the bot itself?

Hi!

Can anyone please give me an idea on how to configure(slack? slack-ruby-bot-server?) so that it ignores messages sent by the bot itself so that those are not attempted to be interpreted as slack-ruby-bot-server commands?

RSpec fabricator conflict

Because of this, you cannot define fabricators in the project using slack-ruby-bot-server. I think we should remove fabrication and faker from this project's runtime/test dependencies.

Docs on scaling with Unicorn

Are there any docs or guidance on scaling out a bot server to use more than one worker proc? This seems like it would be needed for any bot with a web server component that needs to handle multiple concurrent requests.

Turn slack-bot-server into a reusable framework

We tell users to fork this project and build on top. There're probably a few things that can be done to turn this into a framework, maybe extract a set of gems.

  • slack-bot-service: just the service parts that starts/stops/restarts/manages a set of teams and bots
  • slack-bot-store: a set of models that give a team storage
  • slack-bot-api: an API for slack button integration and teams
  • slack-bot-web: a Web UI and API to register teams

Question: Why Unicorn instead of Puma?

Or perhaps more generally, why is Unicorn a runtime dependency? It seems like it could be moved to a development_dependency. My app is using Puma, so it seems unnecessary to have to have Unicorn in the bundle as well.

@dblock

Install bot to a team event

I need to send initial message to the user after adding my application to his team.
I solve this problem with is monkey patching of the file https://github.com/dblock/slack-bot-server/blob/22a215eec2/slack-bot-server/api/endpoints/teams_endpoint.rb after team activating

# == My code start ==
SlackBotServer::Service.start!(team)

client.token = rc['access_token']
information = client.auth_test({token: rc['access_token']})

client2 = Slack::Web::Client.new(token: token)
# always try to create new DM
new_dm = client2.im_open(user: information[:user_id])
channel_id = new_dm.channel.id

# send message
client2.chat_postMessage(
  channel: channel_id,
  text: "Hello <@#{information[:user_id]}>. Nice to meet you! Type 'help'",
  as_user: true
)

client2 = nil
# == My code end ==

Is there right way, to send message to user immediately after he install the bot? Can you give me advice on how to do better, or leave like that?

thanks

slack-ruby-bot-server works but randomly

Hi @dblock ,

This is Huy,
I tried your tutorial and able to run 'slack-ruby-bot-server-sample' locally.
However, it work randomly as in attached image.
Do you have any suggestion?

screen shot 2016-10-14 at 15 06 15

Best Regards,
Huy Dang

Should add an API method for ensuring all active teams are started

Maybe this isn't the best way to do this. But when I authenticate/add a new team from my own custom integration, the service doesn't start. I solved this by adding an API method that starts all teams with a flag of "active".

Another related issue is that there's no checking that an instance already has a thread running that's connected to it, which would help with this issue, I filed separately for that:
#39

Running service in a distinct process on heroku

I'm integrating the concepts from this repository into an existing Rails app that's hosted on heroku.

My first approach was to start the service in an initializer (config/initializers/slack_bot.rb). This worked, sort of, but was not very stable. Out of memory errors, mostly.

My next approach was to isolate the service into its own process using a Procfile:

# Procfile
web: bundle exec passenger start -p $PORT --max-pool-size 3
worker: bundle exec rake jobs:work
bot: bundle exec rake slack:bot

and a rake task:

# lib/tasks/slack.rb
namespace :slack do
  desc 'Run the bot service'
  task bot: :environment do
    require Rails.root.join('lib', 'slack-ruby-bot-server', 'server')
    require Rails.root.join('lib', 'slack-ruby-bot-server', 'service')
    require Rails.root.join('lib', 'slack-commands', 'commands')

    SlackRubyBotServer::Service.start!
  end
end

It crashes immediately after the call to server.start_async.

There's no error in the logs, just this:

Jun 04 07:26:21 app/bot.1:  I, [2016-06-04T14:26:20.759318 #3]  INFO -- : about to start_async 
Jun 04 07:26:21 heroku/bot.1:  Process exited with status 0 
Jun 04 07:26:21 heroku/bot.1:  State changed from up to crashed 

Any ideas?

remove all mongoid dependencies from gemspec

Hi all - Great work on getting PG in the mix!

Can we put the icing on the cake and remove kaminari-mongoid and mongoid-scroll from the gemspec so we can remove mongoid as a dependency altogether for those of us on PG?

https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/slack-ruby-bot-server.gemspec#L25
https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/slack-ruby-bot-server.gemspec#L27

Sorry for just an issue and no PR but just no time right now.

Thanks!

Init new team when server already run

Hi @dblock . I tried to init new slack bot server instance when the new team joined in my system and my server already run. I'm using active record and my teams stored in team table. Please, can you provide me solution for that?

(exception raised in app.rb) MongoLab rebranded as mLab and now sets MONGODB_URI as its ENV variable.

MongoLab rebranded as mLab and now sets MONGODB_URI as its environment variable on heroku.

BOT_ENV:                  production
LANG:                     en_US.UTF-8
MONGODB_URI:              mongodb://dummy:[email protected]:integer/dummy
SLACK_CLIENT_ID:          111111.111111
SLACK_CLIENT_SECRET:      42ef1142ef41ef1ef421

Would you accept a pull request to add that to the list of acceptable environment variables in config/mongo.yml and in app.rb? If so, would you prefer adding it or replacing the current variable for mongolab?

This is the line that is causing the problem:

    def check_mongodb_provider!
      return unless ENV['RACK_ENV'] == 'production'
      raise "Missing ENV['MONGO_URL'], ENV['MONGOHQ_URI'] or ENV['MONGOLAB_URI']." unless ENV['MONGO_URL'] || ENV['MONGOHQ_URI'] || ENV['MONGOLAB_URI']
    end

Recover from undetected slack-side disconnects

It seems that there're server-side disconnects that aren't detected. Probably need a monitoring thread to recover from that.

Team.active.each do |team|
  ping = team.ping! rescue nil
  online = ping[:presence].online if ping
  puts "#{team}, #{online ? 'OK' : 'DEAD'}"
end

Add new teams on the fly

If a Team is added while the service is running, it won't be started until the next time the service is started.

listen loop error: unknown connection: 3 (EventMachine::ConnectionNotBound)

Hello.

When run slack-bot-server i get error.

For reproduce, run with command:
RACK_ENV=production bundle exec unicorn -p 8080

The strange thing is that error happens sometimes, and i can't understand why.
It happens often when i'm trying to restart server (Ctrl+C and run unicorn again, for example).

Log:

ERROR -- : listen loop error: unknown connection: 3 (EventMachine::ConnectionNotBound)
ERROR -- : /usr/local/rvm/gems/ruby-2.2.4@slack-bot-server/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:194:in `run_machine'
ERROR -- : /usr/local/rvm/gems/ruby-2.2.4@slack-bot-server/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:194:in `run'
ERROR -- : config.ru:19:in `block (2 levels) in <main>'

Has someone the same problem?

undefined method `call' for nil:NilClass

When serving static pages:

     Failure/Error: server.call(env)

     NoMethodError:
       undefined method `call' for nil:NilClass
       Did you mean?  caller
     # /Users/dblock/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/file.rb:31:in `call'
     # ./lib/rack/server_pages.rb:48:in `serving'
     # ./lib/rack/server_pages.rb:36:in `call'
     # /Users/dblock/.rvm/gems/ruby-2.3.1/gems/capybara-2.10.1/lib/capybara/server.rb:43:in `call'
     # /Users/dblock/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/handler/webrick.rb:86:in `service'

Current workaround is:

gem 'rack-server-pages', github: 'dblock/rack-server-pages', branch: 'next'

Store access token, scope, incoming webhook info, etc.

See dblock/slack-sup@3a497b4, there're two tokens returned via OAuth, one for the bot user and the other that has other requested oauth permissions. We need to store both in order to provide a token with other scopes than default bot scope.

https://api.slack.com/docs/oauth

{
    "access_token": "xoxp-XXXXXXXX-XXXXXXXX-XXXXX",
    "scope": "incoming-webhook,commands,bot",
    "team_name": "Team Installing Your Hook",
    "team_id": "XXXXXXXXXX",
    "incoming_webhook": {
        "url": "https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX",
        "channel": "#channel-it-will-post-to",
        "configuration_url": "https://teamname.slack.com/services/BXXXXX"
    },
    "bot":{
        "bot_user_id":"UTTTTTTTTTTR",
        "bot_access_token":"xoxb-XXXXXXXXXXXX-TTTTTTTTTTTTTT"
    }
}

Extract storage, api and web layers into pluggable components

From #3, we probably want:

  • slack-ruby-bot-service: just the service parts that starts/stops/restarts/manages a set of teams and bots
  • slack-ruby-bot-store: a set of models that give a team storage
  • slack-ruby-bot-api: an API for slack button integration and teams
  • slack-ruby-bot-web: a Web UI and API to register teams

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.