diff options
Diffstat (limited to 'lib/matrix_app_service.ex')
-rw-r--r-- | lib/matrix_app_service.ex | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/lib/matrix_app_service.ex b/lib/matrix_app_service.ex index 769a9f0..49acd1b 100644 --- a/lib/matrix_app_service.ex +++ b/lib/matrix_app_service.ex @@ -1,9 +1,71 @@ defmodule MatrixAppService do @moduledoc """ - MatrixAppService keeps the contexts that define your domain - and business logic. + Library that adds Matrix Application Service functionalities to Phoenix + applications. - Contexts are also responsible for managing your data, regardless - if it comes from the database, an external API or others. + ## 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: + + ``` + MatrixAppServiceWeb.Router.routes() + ``` + + ### Write adapters + + Create one or multiple modules that implements the following modules: + `MatrixAppService.Adapter.Room`, `MatrixAppService.Adapter.User`, + `MatrixAppService.Adapter.Transaction`. + + For instance: + + ``` + @impl MatrixAppService.Adapter.Room + def query_alias(room_alias) do + # Do something with the room alias + # If the room exists, return :ok + end + + @impl MatrixAppService.Adapter.User + def query_user(user_id) do + # Do something with the user ID + # If the user exists, return :ok + end + + @impl MatrixAppService.Adapter.Transaction + def new_event(%MatrixAppService.Event{type: type, content: content}) + # 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 |