summaryrefslogtreecommitdiff
path: root/lib/matrix_app_service
diff options
context:
space:
mode:
Diffstat (limited to 'lib/matrix_app_service')
-rw-r--r--lib/matrix_app_service/adapter/room.ex2
-rw-r--r--lib/matrix_app_service/adapter/transaction.ex5
-rw-r--r--lib/matrix_app_service/adapter/user.ex4
-rw-r--r--lib/matrix_app_service/client.ex46
-rw-r--r--lib/matrix_app_service/event.ex4
5 files changed, 56 insertions, 5 deletions
diff --git a/lib/matrix_app_service/adapter/room.ex b/lib/matrix_app_service/adapter/room.ex
index 4c1cafc..1601094 100644
--- a/lib/matrix_app_service/adapter/room.ex
+++ b/lib/matrix_app_service/adapter/room.ex
@@ -8,7 +8,7 @@ defmodule MatrixAppService.Adapter.Room do
Responds to a room query by alias. If the room exists, implementations should
create the room (for instance by using
`MatrixAppService.Client.create_room/1`) then return `:ok`. If the room
- doesn't exist, they sould return anything else.
+ doesn't exist, they should return anything else.
"""
@callback query_alias(String.t()) :: :ok | Any
end
diff --git a/lib/matrix_app_service/adapter/transaction.ex b/lib/matrix_app_service/adapter/transaction.ex
index a6ff750..22a2fe4 100644
--- a/lib/matrix_app_service/adapter/transaction.ex
+++ b/lib/matrix_app_service/adapter/transaction.ex
@@ -1,10 +1,11 @@
defmodule MatrixAppService.Adapter.Transaction do
@moduledoc """
-
+ Behaviour for a module that handles transactions involving registered users
+ and rooms.
"""
@doc """
-
+ Called when the application service receives an event.
"""
@callback new_event(MatrixAppService.Event.t()) :: any()
end
diff --git a/lib/matrix_app_service/adapter/user.ex b/lib/matrix_app_service/adapter/user.ex
index 92b9d96..cd3c2aa 100644
--- a/lib/matrix_app_service/adapter/user.ex
+++ b/lib/matrix_app_service/adapter/user.ex
@@ -7,8 +7,8 @@ defmodule MatrixAppService.Adapter.User do
@doc """
Responds to a user query by Matrix ID. If the user exists, implementations
should create the user (for instance by using
- `MatrixAppService.Client.register/1`) then return `:ok`. If the user
- doesn't exist, they sould return anything else.
+ `MatrixAppService.Client.register/2`) then return `:ok`. If the user
+ doesn't exist, they should return anything else.
"""
@callback query_user(String.t()) :: :ok | Any
end
diff --git a/lib/matrix_app_service/client.ex b/lib/matrix_app_service/client.ex
index 998b377..c32cf00 100644
--- a/lib/matrix_app_service/client.ex
+++ b/lib/matrix_app_service/client.ex
@@ -1,12 +1,25 @@
defmodule MatrixAppService.Client do
@moduledoc """
+ Convenience wrapper around `Polyjuice.Client.LowLevel`.
+ Library users can use the wrapped functions or call `user/1` and pass the
+ returned struct to Polyjuice functions.
"""
@type client_options :: {:base_url, String.t()} | MatrixAppService.Client.LowLevel.create_opts()
@doc """
+ Returns a client for the application service.
+ The client gets its homeserver URL and access token from configuration, by
+ default.
+ Different options can be provided to override the defaults, those are:
+
+ * `:base_url`: homerver URL
+ * `:acces_token`: access token
+ * `:device_id`: device ID
+ * `:user_id`: user ID
+ * `:storage`: a `t:Polyjuice.Client.Storage.t/0`
"""
@spec client([client_options()]) ::
Polyjuice.Client.LowLevel.t()
@@ -25,7 +38,11 @@ defmodule MatrixAppService.Client do
end
@doc """
+ Creates a Matrix room.
+ Arguments:
+ 1. `options`: see `Polyjuice.Client.Room.create_room/2`
+ 2. `client_options`: see `client/1`
"""
@spec create_room(Keyword.t()) :: {:ok, String.t()} | Any
def create_room(options \\ [], client_options \\ []) do
@@ -34,7 +51,12 @@ defmodule MatrixAppService.Client do
end
@doc """
+ Creates a new alias for a Matrix room.
+ Arguments:
+ 1. `room_id`: room ID
+ 2. `room_alias`: room alias
+ 3. `client_options`: see `client/1`
"""
@spec create_alias(String.t(), String.t(), client_options()) :: {:ok, String.t()} | Any
def create_alias(room_id, room_alias, client_options \\ []) do
@@ -43,7 +65,31 @@ defmodule MatrixAppService.Client do
end
@doc """
+ Sends a message to a Matrix room.
+
+ Arguments:
+ 1. `room_id`: room ID
+ 2. `msg`: see `Polyjuice.Client.Room.send_message/3`
+ 3. `client_options`: see `client/1`
+ """
+ @spec send_message(String.t(), String.t(), client_options()) :: {:ok, String.t()} | Any
+ def send_message(room_id, msg, client_options \\ []) do
+ client(client_options)
+ |> Polyjuice.Client.Room.send_message(room_id, msg)
+ end
+
+ @doc """
+ Registers a new Matrix user.
+ Arguments:
+ 1. `opts`: a keyword list that can contain these keys:
+ * `:inhibit_login`: true
+ * `:device_id`: device ID, defaults to `"APP_SERVICE"`
+ * `:initial_device_display_name`: device name, defaults to
+ `"ApplicationService"`
+ * `:kind`: kind of account to register, defaults to `"user"`, can also be
+ `"guest"`
+ 2. `client_options`: see `client/1`
"""
@spec register(Polyjuice.Client.LowLevel.register_opts(), client_options()) ::
{:ok, String.t()} | Any
diff --git a/lib/matrix_app_service/event.ex b/lib/matrix_app_service/event.ex
index 06d26a1..23abc38 100644
--- a/lib/matrix_app_service/event.ex
+++ b/lib/matrix_app_service/event.ex
@@ -1,4 +1,8 @@
defmodule MatrixAppService.Event do
+ @moduledoc """
+ Struct for a Matrix event.
+ """
+
@type t :: %__MODULE__{
age: integer(),
content: map(),