slash v2.0.4 Slash.Command View Source

Slash.Command stores all command data received from Slack when invoking a command.

The primary user facing functionality provided by this module is async/2.

Link to this section Summary

Functions

Starts an async task under the Slash.Supervisor so the command can automatically be responded to upon completion

Takes keys from the Slack payload and builds the Command struct

Puts a value into the %Command{} under the key, key

Responds to the %Command{} with message

Returns true or false depending on if this command is populated with all required fields

Link to this section Types

Link to this type

t() View Source
t() :: %Slash.Command{
  args: [String.t()],
  channel_id: String.t(),
  channel_name: String.t(),
  command: String.t(),
  data: map(),
  enterprise_id: String.t(),
  enterprise_name: String.t(),
  response_url: String.t(),
  team_domain: String.t(),
  team_id: String.t(),
  text: String.t(),
  trigger_id: String.t(),
  user_id: String.t(),
  user_name: String.t()
}

Link to this section Functions

Link to this function

async(command, func, opts \\ []) View Source
async(t(), (() -> Slash.Builder.command_response()), keyword()) :: :async

Starts an async task under the Slash.Supervisor so the command can automatically be responded to upon completion.

If you intend to use async commands, you MUST have Slash.Supervisor started.

Options

The following are valid options when calling async/3.

  • :timeout - specific the Task.async/2 timeout option to be used.

Examples

command :async_reply, fn command ->
  async command, fn ->
    Process.sleep(5_000)

    "Hello!"
  end
end
Link to this function

from_params(body) View Source
from_params(map()) :: {:ok, t()} | {:error, String.t()}

Takes keys from the Slack payload and builds the Command struct.

Link to this function

put_data(command, key, value) View Source
put_data(t(), atom(), term()) :: t()

Puts a value into the %Command{} under the key, key.

Link to this function

send_response(command, message) View Source
send_response(t(), String.t()) :: :ok | :error

Responds to the %Command{} with message.

Note, this is for internal usage with async commands. Please see Slash.Builder for valid return types from command functions.

Link to this function

valid?(command) View Source
valid?(t()) :: boolean()

Returns true or false depending on if this command is populated with all required fields.

A command struct is considered invalid if any field is nil at this point.