summaryrefslogtreecommitdiff
path: root/lib/matrix_app_service.ex
blob: 424ff2dd24b11a6f4d977dd275791d5a00a5f13b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
defmodule MatrixAppService do
  @moduledoc """
  Library that adds Matrix Application Service functionalities to Phoenix
  applications.

  ## Installation

  Add this library to your dependencies in `mix.exs`

  ```
  defp deps do
    [...]
    {:matrix_app_service, "~> 0.1.0"}
  end
  ```

  ## Usage

  ### Inject routes

  In your Phoenix Router:

  ```
  require MatrixAppServiceWeb.Router
  MatrixAppServiceWeb.Router.routes()
  ```

  ### Write adapters

  Create one or multiple modules that implement the following modules:
  `MatrixAppService.Adapter.Room`, `MatrixAppService.Adapter.User`,
  `MatrixAppService.Adapter.Transaction`.

  For instance:

  ```
  @behaviour MatrixAppService.Adapter.Room

  @impl MatrixAppService.Adapter.Room
  def query_alias(room_alias) do
    # Do something with the room alias
    # If the room exists, return :ok
  end

  @behaviour MatrixAppService.Adapter.User

  @impl MatrixAppService.Adapter.User
  def query_user(user_id) do
    # Do something with the user ID
    # If the user exists, return :ok
  end

  @behaviour MatrixAppService.Adapter.Transaction

  @impl MatrixAppService.Adapter.Transaction
  def new_event(%MatrixAppService.Event{type: type, content: content}) do
    # Do something with the event
  end
  ```

  ### Write configuration

  ```
  config :matrix_app_service,
    transaction_adapter: App.Matrix.Transaction,
    room_adapter: App.Matrix.Room,
    user_adapter: App.Matrix.User,
    path: "/matrix"
    base_url: "http://synapse:8008",
    access_token: "access token",
    homeserver_token: "homeserver token"
  ```

  ### Use the Client-Server API

  You can use the functions in `MatrixAppService.Client`
  """
end