summaryrefslogblamecommitdiff
path: root/lib/matrix_app_service.ex
blob: 424ff2dd24b11a6f4d977dd275791d5a00a5f13b (plain) (tree)
1
2
3
4
5

                             

                                                                         
 

















                                                    
                                    




                                     
                                                                      





                                                                   

                                          





                                      

                                          





                                     

                                                 
                                            
                                                                         



















                                                        

     
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