slack-ruby / slack-ruby-bot-server Goto Github PK
View Code? Open in Web Editor NEWA library that enables you to write a complete Slack bot service with Slack button integration, in Ruby.
License: MIT License
A library that enables you to write a complete Slack bot service with Slack button integration, in Ruby.
License: MIT License
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.
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.
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.
Port Stripe integration into either a new gem or something built into slack-ruby-bot-server.
dblock/slack-gamebot@7c2fa2b
dblock/slack-gamebot@261443a
dblock/slack-gamebot@2a31b5e
dblock/slack-gamebot@9214141
dblock/slack-gamebot@422cd63
dblock/slack-gamebot@245ea64
dblock/slack-gamebot@ed1d332
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.
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
.
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?
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.
Sorry, this may not be an issue, but I do not find how to make it works when the bot is added to a new team.
Thank you!
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.
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
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>
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?
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
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:
client.say(channel: data.channel, text: client.owner.inspect)
)team.update_attributes!(thefield: 'testing')
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.
I first type "pb reset " and get the response "No matches have been recorded."
When I then type "pb matches" I see a list of games.
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?
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.
See https://github.com/dblock/slack-amber-alert/blob/use-slack-ruby-bot-server/slack-amber-alert/server.rb, an attempt to convert the slack-amber-alert gem into using slack-ruby-bot-server.
We instantiate SlackRubyBotServer::Server here, so deriving from it doesn't work.
For now monkey patching this.
If i need to run thousands of bot for thousands of teams.
can i use slack-bot-server?
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.
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.
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 Something very strange happening here: https://travis-ci.org/slack-ruby/slack-ruby-bot-server/builds/245005962
activerecord 4.0.0 is resolved to either activesupport 5.1.1 and/or 4.0.0 ??
Is this a bundler issue?
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
Currently monkey patching.
module SlackRubyBotServer
class App
def self.instance
@instance ||= new
end
end
end
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?
Best Regards,
Huy Dang
This may result in duplicate messages or spiked CPU usage.
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
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?
Need a way to load Rake tasks, such as https://github.com/dblock/slack-ruby-bot-server/blob/master/tasks/db.rake. Probably SlackRubyBotServer.load_tasks
.
https://github.com/dblock/slack-ruby-bot-server/blob/master/lib/slack-ruby-bot-server/ext/slack-ruby-bot/client.rb contains a monkey patch that adds a client field to SlackRubyBot::Client
. That shouldn't be necessary, the client instantiated should be a child of SlackRubyBot::Client
.
Currently duplicating this all over the place.
dblock/slack-market@7f1438a
dblock/slack-gamebot@f41add0
etc.
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!
Every time you try to re-register a bot that was de-activated on slack, it thinks it's already started and doesn't do anything.
See https://github.com/dblock/slack-ruby-bot-server/blob/master/lib/slack-ruby-bot-server/server.rb#L10, pass through other options like send_gifs
or aliases
.
hi, I have just deployed the app to heroku
[](https://novahub-slack-bot-server.herokuapp.com)
but when I finish add new bot to slack, it always return to localhost:5000
you can try this by access to the link
https://novahub-slack-bot-server.herokuapp.com
Offer a story after the Slack platform release, https://medium.com/slack-developer-blog/launch-platform-114754258b91#.iormuux85.
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?
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
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
If a Team is added while the service is running, it won't be started until the next time the service is started.
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?
Hi,
I pulled this project and I could run with MongoDB. It worked fine for me.
So How can I use this project with Postgresql ?
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'
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"
}
}
From #3, we probably want:
The documentation is not clear about where to run the start commands -- in the bot directory or the sample app.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.