slack-ruby-bot icon indicating copy to clipboard operation
slack-ruby-bot copied to clipboard

Match doesn't allow bot to be addressed by name

Open olingern opened this issue 6 years ago • 4 comments

match should still allow a bot to be addressed by name in a channel or by private message:

  • @bot ping should be possible, however even updating the regex does not fix, i.e.

    match(/^@botname ping$/)

Example Code:

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

PongBot.run

olingern avatar Jul 11 '18 07:07 olingern

Not sure why that doesn't work. Try something like match(/^(?<bot>\S*)[\s]*(?<expression>.*)$/), which is the matcher for unknown commands?

dblock avatar Jul 11 '18 15:07 dblock

@dblock Thanks for the suggestion! That indeed worked.

I also noticed that using match do not populate the bot's help command. If using match and I want to provide syntax / all the commands for a bot -- will I need to manually do that?

olingern avatar Jul 13 '18 01:07 olingern

I think so and we should document how to do that. Maybe take a look at how that's implemented and we can move the code from command to match so that it can document all commands?

dblock avatar Jul 13 '18 03:07 dblock

@dblock I see. I have a long weekend coming up, so I'll give this a look and see if I can open an PR.

olingern avatar Jul 13 '18 04:07 olingern