slash v2.0.0-rc.3 Slash.Builder View Source

Slash.Builder is responsible for building the actual plug that can be used in a Plug pipeline.

The main macro provided when using the module is command/2, which allows you to declare commands for your Slash plug.

Basic Usage

defmodule Bot.SlackRouter do
  use Slash.Builder

  command :greet, fn %{args: args} ->
    case args do
      [name] ->
        "Hello #{name}!"
      _ ->
        "Please pass name to greet"
    end
  end
end

Link to this section Summary

Types

Valid return values for a before handler function. See Slash.Builder.before/1 for more information

Valid return types from command handler functions. See Slash.Builder.command/2 for more information

Functions

Defines a function to be executed before the command is routed to the appropriate handler function

Defines a command for the Slack router, the first argument is always a Slash.Command struct

Handle a command block return value

Verify the request according to the Slack documentation

Link to this section Types

Link to this type

before_response() View Source
before_response() :: {:ok, Slash.Command.t()} | {:error, String.t()}

Valid return values for a before handler function. See Slash.Builder.before/1 for more information.

Link to this type

command_response() View Source
command_response() :: binary() | map() | :async

Valid return types from command handler functions. See Slash.Builder.command/2 for more information.

Link to this section Functions

Link to this macro

before(function_name) View Source (macro)
before(atom()) :: Macro.t()

Defines a function to be executed before the command is routed to the appropriate handler function.

The function_name should be a reference to the name of the function on the current module. Values returned from a before function should match the before_response/0 type.

Link to this macro

command(name, func) View Source (macro)
command(atom(), (Slash.Command.t() -> command_response())) :: Macro.t()

Defines a command for the Slack router, the first argument is always a Slash.Command struct.

The name argument should be the command name you would like to define, this should be an internal name, for example greet_user. This will then ran through SlackCommand.Formatter.Dasherized by default, creating the Slack command greet-user.

The func argument will be your function which is invoked on command route match, this function will always receive the %Slash.Command{} struct as an argument.

TODO: This needs to verify the arity of func.

Link to this function

handle_command(module, conn, command) View Source
handle_command(module(), Plug.Conn.t(), Slash.Command.t()) :: Plug.Conn.t()

Handle a command block return value.

Link to this function

verify_request(module, conn) View Source
verify_request(module(), Plug.Conn.t()) :: boolean()

Verify the request according to the Slack documentation.

See the Slack documentation for additional details.