Polyjuice Client v0.4.4 Polyjuice.Client View Source
Matrix client functions.
The client created by this module, or any client that implements the
Polyjuice.Client.API
protocol, can be used to connect to a Matrix server
using the functions from submodules.
Polyjuice.Client.Filter
: build filters for use with syncPolyjuice.Client.Room
: interact with rooms, such as sending messagesPolyjuice.Client.Media
: use the media repositoryPolyjuice.Client.MsgBuilder
: build message contents
The client defined in this module should work for most cases. If you want
more control, you can use Polyjuice.Client.LowLevel
instead.
To start a client with this module, create a process using start/2
or
start_link/2
, and then call get_client/1
to get a struct that can be used
with the above modules. To stop the client, use
Polyjuice.Client.API.stop/3
.
Link to this section Summary
Functions
Returns a specification to start this under a supervisor.
Get a struct that implements Polyjuice.Client.API
from the pid given by
start/2
or start_link/2
.
Log in with a password.
Log out an existing session.
Register a user.
Start a client.
Start a client.
Start the client process and return both the PID and the client struct.
Synchronize messages from the server.
Get the spec versions supported by the server.
Link to this section Types
Matrix client.
This struct can be obtained by calling get_client/1
after the client
process has been started with start/2
or start_link/2
, and implements
Polyjuice.Client.API
protocol.
Link to this section Functions
Returns a specification to start this under a supervisor.
arg
is a list where the first element is the server's base URL, and the
remainder of the list are options as document in start_link/2
.
Get a struct that implements Polyjuice.Client.API
from the pid given by
start/2
or start_link/2
.
Log in with a password.
identifier
may be a single string (in which case it represents a username
-- either just the localpart or the full MXID), a tuple of the form
{:email, "email@address"}
, a tuple of the form {:phone, "country_code", "phone_number"}
, or a map that is passed directly to the login endpoint.
opts
is a keyword list of options:
device_id:
(string) the device ID to useinitial_device_display_name:
(string) the display name to use for the device
Log out an existing session.
Register a user.
opts
is a keyword list of options:
username:
(string) the basis for the localpart of the desired Matrix IDauth
is the authentication map containing the type of authentication type and sometime the session keypassword:
(string) the desired password for the accountdevice_id:
(string) the device ID to useinitial_device_display_name:
(string) the display name to use for the deviceinhibit_login:
(boolean) don't login after successful registerkind:
(atom) kind of account to register. Defaults to user. One of: ["guest", "user"]
Start a client.
See start_link/2
.
Start a client.
opts
may contain:
access_token
: (required to make calls that require authorization, but may be omitted if using astorage
that was previously used when logging in and contains the access token) the access token to use.user_id
: (required by some endpoints, but may be omitted if using astorage
that was previously used when logging in and contains the user ID) the ID of the userdevice_id
: (required by some endpoints, but may be omitted if using astorage
that was previously used when logging in and contains the device ID) the device IDstorage
: (required for sync) the storage backend to use (seePolyjuice.Client.Storage
)handler
: (required for sync) an event handler (seePolyjuice.Client.Handler
)sync
: whether to start a sync process (defaults to true). The sync process will not start if there is nostorage
orhandler
provided.sync_filter
: the filter to use for the sync. Defaults to no filter.proxy
: use a proxy to connect to the homeserver. This may be of the form{:http, host, port}
or{:http, host, port, user, pass}
for HTTP proxies, or{:socks5, host, port}
or{:socks5, host, port, user, pass}
for SOCKS5 proxies.ssl_options
: SSL/TLS options. This is a list oftls_client_option
s as defined at https://erlang.org/doc/man/ssl.htmlfollow_redirect
: whether redirects should be automatically followed. May either a number indicating the maximum number of redirects to follow, ortrue
, meaning that redirects should be followed up to a default maximum number.
Start the client process and return both the PID and the client struct.
The return value of this function is compatible with
DynamicSupervisor.start_child/1
.
sync(client_api, opts \\ [])
View Sourcesync(client_api :: Polyjuice.Client.API.t(), opts :: list()) :: {:ok, map()} | any()
Synchronize messages from the server.
Normally, you should use Polyjuice.Client
's built-in sync process rather
than calling this function, but this function may be used where more control
is needed.
opts
is a keyword list of options:
filter:
(string or map) a filter to apply to the sync. May be either the ID of a previously uploaded filter, or a new filter.since:
(string) where to start the sync from. Should be a token obtained from thenext_batch
of a previous sync.full_state:
(boolean) whether to return the full room state instead of just the state that has changed since the last syncset_presence:
(one of:online
,:offline
, or:unavailable
) the user's presence to set with this synctimeout:
(integer) the number of milliseconds to wait before the server returns
versions(client_api)
View Sourceversions(client_api :: Polyjuice.Client.API.t()) :: {:ok, map()} | any()
Get the spec versions supported by the server.