Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot doesn't understand its command #113

Closed
andyfo opened this issue Feb 11, 2017 · 12 comments
Closed

Bot doesn't understand its command #113

andyfo opened this issue Feb 11, 2017 · 12 comments
Labels

Comments

@andyfo
Copy link

andyfo commented Feb 11, 2017

Hi!

I run a simple pong bot but it doesn't understand its commands:

andy> pongbot ping
pongbot> Sorry @andy, I don't understand that command!

I am using this example code:

require 'slack-ruby-bot'

class PongBot < SlackRubyBot::Bot
  command 'ping' do |client, data, _|
    client.say(channel: data.channel, text: 'pong')
  end
end

PongBot.run

I registered the bot and I am running it with:

SLACK_API_TOKEN=CfDl12... bundle exec ruby pongbot.rb

Is there something basic that I am doing wrong?

Thanks!

@andyfo andyfo changed the title Bot doesn't understand any custom command Bot doesn't understand its command Feb 11, 2017
@dblock
Copy link
Collaborator

dblock commented Feb 11, 2017

Are you DMing the bot or sending a message to the bot in a channel? When you DM the bot you don't need to say pongbot.

@andyfo
Copy link
Author

andyfo commented Feb 11, 2017

I am sending a message to the bot in a channel.

@dblock
Copy link
Collaborator

dblock commented Feb 11, 2017

There's one more thing, something about the bot user, does addressing the bot with @pongbot instead of just pongbot change anything?

@andyfo
Copy link
Author

andyfo commented Feb 11, 2017

It's the same.

This is what the log shows:

D, [2017-02-11T18:29:58.097650 #52325] DEBUG -- Slack::RealTime::Concurrency::Celluloid::Socket#handle_read: �~�{"type":"message","channel":"XXXX","user":"U0HTMJFPH","text":"<@U441NM1QS> ping","ts":"1486834197.000002","team":"T0HTMHL58"}
D, [2017-02-11T18:29:58.097792 #52325] DEBUG -- SlackRubyBot::Client#run_loop: WebSocket::Driver::MessageEvent, {"type":"message","channel":"XXXX","user":"U0HTMJFPH","text":"<@U441NM1QS> ping","ts":"1486834197.000002","team":"T0HTMHL58"}
D, [2017-02-11T18:29:58.098877 #52325] DEBUG -- SlackRubyBot::Client#dispatch: channel=XXXX, team=T0HTMHL58, text=<@U441NM1QS> ping, ts=1486834197.000002, type=message, user=U0HTMJFPH
D, [2017-02-11T18:29:58.102470 #52325] DEBUG -- SlackRubyBot::Client#send_json: {:type=>"message", :id=>1, :text=>"Sorry <@U0HTMJFPH>, I don't understand that command!", :channel=>"XXXX"}
D, [2017-02-11T18:29:58.107444 #52325] DEBUG -- Slack::RealTime::Concurrency::Celluloid::Socket#send_data: {"type":"message","id":1,"text":"Sorry \u003c@U0HTMJFPH\u003e, I don't understand that command!","channel":"XXXX"}
D, [2017-02-11T18:29:58.107594 #52325] DEBUG -- Slack::RealTime::Concurrency::Celluloid::Socket#write: ��00�3K�J@U�     ]�@CQ�V�ZT��VHD�        c�ABI�oE�Sp�xd�yv`�oE�U�zT�]D�F^T�ACD�]T�[QD�P_]�R^T��[Q^�V\�w�s�}�
D, [2017-02-11T18:29:58.234879 #52325] DEBUG -- Slack::RealTime::Concurrency::Celluloid::Socket#handle_read: �o{"ok":true,"reply_to":1,"ts":"1486834197.000003","text":"Sorry <@U0HTMJFPH>, I don't understand that command!"}
D, [2017-02-11T18:29:58.235000 #52325] DEBUG -- SlackRubyBot::Client#run_loop: WebSocket::Driver::MessageEvent, {"ok":true,"reply_to":1,"ts":"1486834197.000003","text":"Sorry <@U0HTMJFPH>, I don't understand that command!"}
D, [2017-02-11T18:29:58.311180 #52325] DEBUG -- Slack::RealTime::Concurrency::Celluloid::Socket#handle_read: �~�{"type":"desktop_notification","title":"COMPANY","subtitle":"pongbotdemo","msg":"1486834197.000002","content":"andy: @pongbot ping","channel":"XXXX","launchUri":"slack://channel?id=XXXX&message=1486834197000002&team=XXXX","avatarImage":"https://avatars.slack-edge.com/2016-01-15/18595913235_fa08c5e571c56807d781_192.jpg","ssbFilename":"knock_brush.mp3","imageUri":null,"is_shared":false,"event_ts":"1486834197.980109"}
D, [2017-02-11T18:29:58.311371 #52325] DEBUG -- SlackRubyBot::Client#run_loop: WebSocket::Driver::MessageEvent, {"type":"desktop_notification","title":"Dextronet","subtitle":"pongbotdemo","msg":"1486834197.000002","content":"andy: @pongbot ping","channel":"XXXX","launchUri":"slack://channel?id=XXXX&message=1486834197000002&team=XXXX","avatarImage":"https://avatars.slack-edge.com/2016-01-15/18595913235_fa08c5e571c56807d781_192.jpg","ssbFilename":"knock_brush.mp3","imageUri":null,"is_shared":false,"event_ts":"1486834197.980109"}
D, [2017-02-11T18:29:58.312733 #52325] DEBUG -- SlackRubyBot::Client#dispatch: avatarImage=https://avatars.slack-edge.com/2016-01-15/18595913235_fa08c5e571c56807d781_192.jpg, channel=XXXX, content=andy: @pongbot ping, event_ts=1486834197.980109, imageUri=, is_shared=false, launchUri=slack://channel?id=XXXX&message=1486834197000002&team=XXXX, msg=1486834197.000002, ssbFilename=knock_brush.mp3, subtitle=pongbotdemo, title=Dextronet, type=desktop_notification

@dblock
Copy link
Collaborator

dblock commented Feb 11, 2017

I don't see anything wrong. This is unmodified code? Which version of slack-ruby-bot? You should dig this a bit deeper, try to look inside the dispatch method, it tries to match a command.

@fifiteen82726
Copy link

fifiteen82726 commented Feb 12, 2017

I have the same issue.
screen shot 2017-02-12 at 2 42 21 pm

D, [2017-02-12T14:41:18.135824 #3145] DEBUG -- Slack::RealTime::Concurrency::Celluloid::Socket#handle_read: �~{"type":"desktop_notification","title":"TaiwanDigger","subtitle":"#test","msg":"1486881671.000007","content":"fifiteen82726: @test-bot ping","channel":"C44A6GP26","launchUri":"slack://channel?id=C44A6GP26&message=1486881671000007&team=T3CQFPT7C","avatarImage":"https://secure.gravatar.com/avatar/7c69390748f64982df87bc19af781d6f.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F7fa9%2Fimg%2Favatars%2Fava_0018-192.png","ssbFilename":"knock_brush.mp3","imageUri":null,"is_shared":false,"event_ts":"1486881677.692802"}
D, [2017-02-12T14:41:18.136042 #3145] DEBUG -- SlackRubyBot::Client#run_loop: WebSocket::Driver::MessageEvent, {"type":"desktop_notification","title":"TaiwanDigger","subtitle":"#test","msg":"1486881671.000007","content":"fifiteen82726: @test-bot ping","channel":"C44A6GP26","launchUri":"slack://channel?id=C44A6GP26&message=1486881671000007&team=T3CQFPT7C","avatarImage":"https://secure.gravatar.com/avatar/7c69390748f64982df87bc19af781d6f.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F7fa9%2Fimg%2Favatars%2Fava_0018-192.png","ssbFilename":"knock_brush.mp3","imageUri":null,"is_shared":false,"event_ts":"1486881677.692802"}
D, [2017-02-12T14:41:18.138727 #3145] DEBUG -- SlackRubyBot::Client#dispatch: avatarImage=https://secure.gravatar.com/avatar/7c69390748f64982df87bc19af781d6f.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F7fa9%2Fimg%2Favatars%2Fava_0018-192.png, channel=C44A6GP26, content=fifiteen82726: @test-bot ping, event_ts=1486881677.692802, imageUri=, is_shared=false, launchUri=slack://channel?id=C44A6GP26&message=1486881671000007&team=T3CQFPT7C, msg=1486881671.000007, ssbFilename=knock_brush.mp3, subtitle=#test, title=TaiwanDigger, type=desktop_notification

@tomchipchase
Copy link

I'm having the same issue with version 0.10.0. Adding the command as a subclass does work, but using the DSL syntax doesn't.

I've tried with 0.9.0, and it does work there.

@tomchipchase
Copy link

A failing spec is pretty easy to write too:

bot.rb:

require "slack-ruby-bot"

class Bot < SlackRubyBot::Bot
  command "ping" do |client, data, _|
    client.say(text: "pong", channel: data.channel)
  end
end

bot_spec.rb:

require "bot"
require "rspec-helper"

describe Bot do
  it "responds to ping" do
    expect({ message: "#{SlackBotRuby.config.user} ping")
      .to respond_with_slack_message("pong")
  end
end
Failures:

  1) Bot responds to ping
     Failure/Error: expect(message: "#{SlackRubyBot.config.user} ping").to respond_with_slack_message('pong')
     
       #<SlackRubyBot::Client:0x007fc907830ba8 @callbacks={}, @token=nil, @websocket_ping=30, @websocket_proxy=nil, @concurrency=Slack::RealTime::Concurrency::Celluloid, @start_options={}, @store_class=Slack::RealTime::Store, @logger=#<Slack::Logger:0x007fc9089b2b88 @level=2, @progname=nil, @default_formatter=#<Logger::Formatter:0x007fc9089b2b38 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x007fc9089b2ae8 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x007fc9089b2a98>>>, @web_client=#<Slack::Web::Client:0x007fc9089b28e0 @proxy=nil, @user_agent="Slack Ruby Client/0.7.9", @ca_path="", @ca_file="/ca-certificates.crt", @logger=#<Logger:0x007fc9089b2a20 @level=0, @progname=nil, @default_formatter=#<Logger::Formatter:0x007fc9089b29d0 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x007fc9089b2980 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x007fc9089b2930>>>, @endpoint="https://slack.com/api/", @token=nil>, @aliases=nil, @send_gifs=nil> received :message with unexpected arguments
         expected: ({:channel=>"channel", :text=>"pong"})
              got: ({:text=>"Sorry <@user>, I don't understand that command!", :channel=>"channel"})
       Diff:
       @@ -1,2 +1,3 @@
       -[{:channel=>"channel", :text=>"pong"}]
       +[{:text=>"Sorry <@user>, I don't understand that command!",
       +  :channel=>"channel"}]
       
     # /usr/local/bundle/gems/slack-ruby-bot-0.10.0/lib/slack-ruby-bot/client.rb:58:in `say'
     # /usr/local/bundle/gems/slack-ruby-bot-0.10.0/lib/slack-ruby-bot/commands/unknown.rb:7:in `call'
     # /usr/local/bundle/gems/slack-ruby-bot-0.10.0/lib/slack-ruby-bot/commands/base.rb:73:in `block in invoke'
     # /usr/local/bundle/gems/slack-ruby-bot-0.10.0/lib/slack-ruby-bot/commands/base.rb:56:in `each_pair'
     # /usr/local/bundle/gems/slack-ruby-bot-0.10.0/lib/slack-ruby-bot/commands/base.rb:56:in `invoke'
     # /usr/local/bundle/gems/slack-ruby-bot-0.10.0/lib/slack-ruby-bot/hooks/message.rb:9:in `block in call'
     # /usr/local/bundle/gems/slack-ruby-bot-0.10.0/lib/slack-ruby-bot/hooks/message.rb:9:in `tap'
     # /usr/local/bundle/gems/slack-ruby-bot-0.10.0/lib/slack-ruby-bot/hooks/message.rb:9:in `call'
     # /usr/local/bundle/gems/slack-ruby-bot-0.10.0/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb:17:in `block (2 levels) in <top (required)>'
     # ./spec/bot_spec.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.09301 seconds (files took 0.58219 seconds to load)

@dblock
Copy link
Collaborator

dblock commented Feb 12, 2017

I can confirm this is a problem. We have a spec for this exact scenario, but it only fails if run standalone. I'm looking into it.

@dblock
Copy link
Collaborator

dblock commented Feb 12, 2017

I have a fix in #114. Can @tomchipchase and @fifiteen82726 please confirm that it works? I'll cut a release.

@dblock dblock closed this as completed in c0425da Feb 12, 2017
dblock added a commit that referenced this issue Feb 12, 2017
Fix #113: commands in subclassed SlackRubyBot::Bot.
@dblock
Copy link
Collaborator

dblock commented Feb 12, 2017

Released 0.10.1.

@tomchipchase
Copy link

@dblock That fix works for me.

Thanks for the quick fix, and for your work on this gem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants