summaryrefslogtreecommitdiff
path: root/tutorial_echo.md
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2019-10-15 19:06:10 +0200
committerHubert Chathi <hubert@uhoreg.ca>2019-10-15 19:06:10 +0200
commita87975ca316c452509f1aa7bf80ecc54e2dba4fe (patch)
treea691757a296254344ab0fcbc4006b4546b99fe04 /tutorial_echo.md
parentmake update and put in Polyjuice.Client.Filter public (diff)
add another tutorial
Diffstat (limited to 'tutorial_echo.md')
-rw-r--r--tutorial_echo.md15
1 files changed, 10 insertions, 5 deletions
diff --git a/tutorial_echo.md b/tutorial_echo.md
index 9d01326..69cbfca 100644
--- a/tutorial_echo.md
+++ b/tutorial_echo.md
@@ -1,9 +1,12 @@
-Tutorial: Echo bot
-==================
+Tutorial #1: Echo bot
+=====================
In this tutorial, we will construct a simple echo bot: for every message that
-the echo bot sees, it will repeat that message. The commands in this tutorial
-can be entered interactively into `iex -S mix` to produce a working bot.
+the echo bot sees, it will repeat that message. This tutorial provides a brief
+introduction to using the library.
+
+The commands in this tutorial can be entered interactively into `iex -S mix` to
+produce a working bot.
## Creating a client
@@ -58,7 +61,9 @@ When we receive such a message, we can use the
`Polyjuice.Client.Room.send_message/3` function to respond to the message. We
will use pattern matching to make sure to only respond to `m.text` messages,
and respond with a `m.notice` message, so that we don't create a message loop.
-A `receive` statement to do this would look something like this:
+We can simply take the message contents from the incoming message, change the
+`msgtype`, and pass that to `Polyjuice.Client.Room.send_message/3` to send the
+echo. A `receive` statement to do this would look something like this:
receive do
{:message, room_id, %{"content" => %{"msgtype" => "m.text"} = content}} ->