Skip to content

Make commands asynchronous by default #2

Open
@chancancode

Description

@chancancode

We want to change the semantics so that commands and interactions are executed synchronously (as opposed to putting it in a queue) by default. It should still be possible to opt into the current asynchronous behavior with something like this:

class MonkeyCommand < Slackathon::Command
  async def call
    {
      response_type: "ephemeral",
      attachments: [{
        callback_id: "monkey",
        text: "Please pick a style",
        actions: [{
          type: "button",
          text: "Click to use :see_no_evil:",
          name: "post_in_channel",
          value: "#{params[:text]} :see_no_evil:"
        }, {
          type: "button",
          text: "Click to use :hear_no_evil:",
          name: "post_in_channel",
          value: "#{params[:text]} :hear_no_evil:"
        }, {
          type: "button",
          text: "Click to use :speak_no_evil:",
          name: "post_in_channel",
          value: "#{params[:text]} :speak_no_evil:"
        }]
      }]
    }
  end

  async def post_in_channel(value)
    {
      response_type: "in_channel",
      delete_original: true,
      text: "<@#{params[:user][:id]}> said #{value}"
    }
  end
end

The async class method can store the symbols in an array on the class instance, and dispatch_* can check whether it should call the method synchronously.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions