-
Notifications
You must be signed in to change notification settings - Fork 19
Alice 0.2.0 Changes
Adam Zaninovich edited this page Mar 5, 2016
·
4 revisions
- better help text
- new format for writing handler functions
- more flexible
reply
function
Completely changes the way that help documentation is provided for handlers. Now you use Elixir's built-in documentation features to provide help text.
This allows for better formatting and better help information.
Instead of writing a handle(conn, :name)
function, you now write a name(conn)
function
Together these two features look like this:
route ~r/\Aping\z/i, :ping
command ~r/\bping\z/i, :ping
@doc "`ping` - responds with signs of life"
def ping(conn) do
["PONG!", "Can I help you?", "Yes...I'm still here.", "I'm alive!"]
|> random_reply(conn)
end
The reply/2
function can now take its arguments in any order (reply(conn, text)
, or reply(text, conn)
). This allows chaining on conn
for sending multiple replies.
conn
|> reply("_Sure thing!_")
|> reply("_Commands require you @ mention me, Routes do not_")
|> reply("_Here are all the routes and commands I know about…_")
Of course, you can still call reply/2
in the original way by passing the text first.
"text" |> reply(conn)