slack_command v1.0.0 SlackCommand.Router behaviour View Source
Provides a primary macro defcommand
to enable building a Plug that can route inbound requests from Slack with a familiar interface (functions).
Since SlackCommand.Router
is just a builder for a Plug, it can be integrated into either a Plug.Router
or a Phoenix application.
Example Usage
defmodule SlackBot.SlackRouter do
use SlackCommand.Router
defcommand hello(_, name) do
"Greetings #{name}!"
end
end
defmodule SlackBot.Router do
use Plug.Router
plug :match
plug Plug.Parsers, parsers: [:json],
pass: ["application/json"],
json_decoder: Jason
plug :dispatch
forward "/slack", to: SlackBot.SlackRouter
end
Link to this section Summary
Functions
Defines a Slack command by decomposing the function head. The first argument
is the %Plug.Conn{}
struct and is always required
Handle the %Plug.Conn{}
with router
, which is
expected to be a module that has called use SlackCommand.Router
Callbacks
Authenticates the connection, the default implementation just verifies that the received token in the payload matches the configured value
Process the command given from slack
Link to this section Functions
Defines a Slack command by decomposing the function head. The first argument
is the %Plug.Conn{}
struct and is always required.
For example:
defcommand ping(_) do
"pong"
end
Which will then translate to then slash command in Slack /bot ping
.
handle(SlackCommand.Router, Plug.Conn.t()) :: Plug.Conn.t()
Handle the %Plug.Conn{}
with router
, which is
expected to be a module that has called use SlackCommand.Router
Matches on the root route when path_info == []
Link to this section Callbacks
Authenticates the connection, the default implementation just verifies that the received token in the payload matches the configured value.
do_command(String.t(), Plug.Conn.t(), [String.t()]) :: SlackCommand.Message.t() | {:ok, SlackCommand.Message.t()} | {:ok, String.t() | {:error, String.t()}}
Process the command given from slack.