summaryrefslogtreecommitdiff
path: root/lib/matrix_app_service/client.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/matrix_app_service/client.ex')
-rw-r--r--lib/matrix_app_service/client.ex27
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/matrix_app_service/client.ex b/lib/matrix_app_service/client.ex
index 42ef758..cec1046 100644
--- a/lib/matrix_app_service/client.ex
+++ b/lib/matrix_app_service/client.ex
@@ -24,10 +24,21 @@ defmodule MatrixAppService.Client do
Polyjuice.Client.LowLevel.t()
def client(opts \\ []) do
base_url =
- Keyword.get(opts, :base_url, Application.fetch_env!(:matrix_app_service, :base_url))
+ Keyword.get(opts, :base_url) ||
+ (MatrixAppService.Application.start_endpoint?() &&
+ MatrixAppServiceWeb.Endpoint.config(:base_url)) ||
+ Application.get_env(:matrix_app_service, :app_service)[:base_url] ||
+ raise "MatrixAppService: config key base_url missing"
+
+ access_token =
+ Keyword.get(opts, :access_token) ||
+ (MatrixAppService.Application.start_endpoint?() &&
+ MatrixAppServiceWeb.Endpoint.config(:access_token)) ||
+ Application.get_env(:matrix_app_service, :app_service)[:access_token] ||
+ raise "MatrixAppService: config key access_token missing"
default_opts = [
- access_token: Application.fetch_env!(:matrix_app_service, :access_token),
+ access_token: access_token,
device_id: "APP_SERVICE"
]
@@ -82,12 +93,12 @@ defmodule MatrixAppService.Client do
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"`
+ * `: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()) ::