summaryrefslogtreecommitdiff
path: root/tutorial_echo.md
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2020-09-17 23:03:28 -0400
committerHubert Chathi <hubert@uhoreg.ca>2020-09-18 08:48:53 -0400
commit13d238f798b570bddf79aa117c294fe1e4414881 (patch)
treea992b91d3e57976f27e9845afb683bad8e13c4af /tutorial_echo.md
parentdoc improvements (diff)
update example and tutorials to new API
Diffstat (limited to 'tutorial_echo.md')
-rw-r--r--tutorial_echo.md26
1 files changed, 17 insertions, 9 deletions
diff --git a/tutorial_echo.md b/tutorial_echo.md
index 27e7565..f1e7857 100644
--- a/tutorial_echo.md
+++ b/tutorial_echo.md
@@ -10,31 +10,39 @@ produce a working bot.
## Creating a client
-We begin by starting a client:
+We begin by starting a client process and obtaining a struct:
- iex> client = Polyjuice.Client.start_link(
+ iex> {:ok, pid} = Polyjuice.Client.start_link(
...> "http://localhost:8008",
...> access_token: "access_token",
...> user_id: "@echobot:localhost",
...> storage: Polyjuice.Client.Storage.Ets.open(),
...> handler: self()
...> )
+ iex> client = Polyjuice.Client.get_client(pid)
The first parameter is the base URL to the homeserver that the bot will be
using. `access_token` is an access token for the bot to use. The access token
can be obtained by using `curl` to call the
[login](https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login)
-endpoint on the homeserver, or by retrieving it from an already logged-in
-client. `user_id` is the Matrix user ID of the bot. And `storage` provides
-some persistent storage for the client library. In the example above, it is
-using the [Erlang Term Storage](http://erlang.org/doc/man/ets.html), which does
-not actually provide any persistence. This means that, for example, the bot
-will forget where it was in the sync, and so it may produce duplicate responses
-when it is restarted. If you wish to have persistence, you can use the
+endpoint on the homeserver, by retrieving it from an already logged-in client,
+or by using `mix polyjuice.login`. `user_id` is the Matrix user ID of the bot.
+And `storage` provides some persistent storage for the client library. In the
+example above, it is using the [Erlang Term
+Storage](http://erlang.org/doc/man/ets.html), which does not actually provide
+any persistence. This means that, for example, the bot will forget where it
+was in the sync, and so it may produce duplicate responses when it is
+restarted. If you wish to have persistence, you can use the
`Polyjuice.Client.Storage.Dets` module instead, which will persist the term
storage to disk. To use it, call `Polyjuice.Client.Storage.Dets.open/1` with
the name of a file to use for storage.
+If you use `Polyjuice.Client.Storage.Dets`, then you only need to specify he
+`access_token` and `user_id` the first time the client is run. This
+information will be stored in dets and will be retrieved on subsequent runs.
+Alternatively, you can use `mix polyjuice.login` to log in and store the access
+token and user ID.
+
The `handler` parameter tells the client how client events (such as Matrix
messages) should be handled. By passing a PID (`self()`), Erlang messages will
be sent to the given PID.