alice v0.3.7 Alice.Router.Helpers

Helpers to make replying easier in handlers

Link to this section Summary

Functions

Delay a reply. Alice will show to be typing while the message is delayed

Indicate typing

Takes a conn and a list of possible response in any order. Replies with a random element of the list provided

Reply to a message in a handler

Link to this section Functions

Link to this function chance_reply(conn, chance, positive, negative \\ :noreply)
chance_reply(Alice.Conn.t, float, String.t, String.t) :: Alice.Conn.t

Reply with random chance.

Examples

> chance_reply(conn, 0.5, "sent half the time")
> chance_reply(conn, 0.25, "sent 25% of the time", "sent 75% of the time")
Link to this function delayed_reply(msg, ms, conn)
delayed_reply(Alice.Conn.t, String.t, integer) :: Task.t
delayed_reply(String.t, integer, Alice.Conn.t) :: Task.t

Delay a reply. Alice will show to be typing while the message is delayed.

The conn can be passed in first or last.

Returns the task, not a conn. If you need to get the conn, you can use Task.await(task), but this will block the handle process until the delay finishes. If you don’t need the updated conn, simply return the conn that was passed to delayed_reply.

Examples

def hello(conn) do
  "hello" |> delayed_reply(1000, conn)
  conn
end

def hello(conn) do
  task = delayed_reply(conn, "hello", 1000)
  # other work...
  Task.await(task)
end
Link to this function indicate_typing(conn)
indicate_typing(Alice.Conn.t) :: Alice.Conn.t

Indicate typing.

Link to this function random_reply(list, conn)
random_reply(list, Alice.Conn.t) :: Alice.Conn.t
random_reply(Alice.Conn.t, list) :: Alice.Conn.t

Takes a conn and a list of possible response in any order. Replies with a random element of the list provided.

Link to this function reply(resp, conn)
reply(String.t, %Alice.Conn{message: term, slack: term, state: term}) :: Alice.Conn.t
reply(%Alice.Conn{message: term, slack: term, state: term}, String.t) :: Alice.Conn.t
reply([String.t, ...], %Alice.Conn{message: term, slack: term, state: term}) :: Alice.Conn.t
reply(%Alice.Conn{message: term, slack: term, state: term}, [String.t, ...]) :: Alice.Conn.t

Reply to a message in a handler.

Takes a conn and a response string in any order. Sends response back to the channel that triggered the handler.

Adds random tag to end of image urls to break Slack’s img cache.