Skip to content
This repository was archived by the owner on Sep 22, 2025. It is now read-only.
This repository was archived by the owner on Sep 22, 2025. It is now read-only.

Order of command requirement matters  #225

@cabello

Description

@cabello

Hi,

Thanks for this project, it's been 9 months since I've been using it for my bot.

I am now turning the bot into a Slack app which requires a web server and I chose Rails, Rails has auto loading and eager loading mechanisms and usually load files in alphabetical order.

Looking at the implementation of match, scan and routes, it seems (and this is how the app behave in production) that the order of command registration matters.

Meaning, requiring a file that matches all first, e.g. match(/^(?<answer>.*)$/m) would prevent other files from matching at all. (This is our "unknown" command, it has "did you mean" and implements our conversation logic)

We also want to guarantee help to be available at all times, so that one would need to be the first route that is checked when routes.each_pair.

It would be nice if there was a way to specify where a command should be put in the ordered list of routes. At this moment the I named the command zzz_unknown to get the correct behaviour.

My suggestion is to draw inspiration from Ruby Array insert method, so our commands for example:

# catch all
match(/^(?<answer>.*)$/m, insert: -1) do |client, data, match|
  client.say "I was the last match"
end

command('help', insert: 0) do |client, data, match|
  client.say "No one can ever match help before me"
end

The obvious problem with this solution is that if another command used insert: 0 and it was required after help, then that command would be first.

The other potential idea is to separate the matches/commands into a separate file like Rails routes, I haven't thought much about this approach but it could be a nice looking one.

Thanks for taking the time to read and consider this issue / feature request.
💜

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions