alice v0.1.2 Alice.Router.Helpers

Summary

Functions

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

Indicate typing

Replies with a random element of the list provided

Reply to a message in a handler

Macros

Adds a command to the handler

Adds a route to the handler

Functions

chance_reply(chance, positive, negative \\ :noreply, conn)

Reply with random chance.

Examples

> chance_reply(0.5, "this will be sent half the time, otherwise nothing will be sent")
> chance_reply(0.25, "this will be sent 25% of the time", "sent 75% of the time")
delayed_reply(message, milliseconds, conn)

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

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 handle(conn, :hello) do
  "hello" |> delayed_reply(1000, conn)
  conn
end

def handle(conn, :hello) do
  task = delayed_reply("hello", 1000, conn)
  # other work...
  Task.await(task)
end
indicate_typing(map)

Indicate typing.

random_reply(list, conn)

Replies with a random element of the list provided.

reply(response, map)

Reply to a message in a handler.

Sends response back to the channel that triggered the handler.

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

Macros

command(pattern, name)

Adds a command to the handler

route(pattern, name)

Adds a route to the handler