Dementia
Small rust library for the Matrix protocol
Status
Right now, only the following are supported:
- joining rooms
- sending text messages and
- receiving text messages
Support for room creation and receiving other kinds of messages are planned for the near time. Also, image upload is on my personal to-do list. :)
Usage
First, add this to your Cargo.toml
:
[]
= "*"
In order to connect to a Matrix homeserver and join a room, you need a user on that homeserver and an access token for that user.
let server_url = "https://matrix.org"; // The Matrix homeserver
let access_token = "DAx…3wo"; // The Matrix user access token
With that, you can create a Homeserver object
let connection = new
.access_token
.connect;
or alternatively
let connection = connect;
and use this object to join rooms:
let mut room = connection.join;
(You need to join a room you want to interact with even if you are already joined. This is for the library to obtain the room id.)
You receive new messages with connection.get_new_messages()
(which returns a Vector<String>
of all messages since last called) and send messages with connection.send_message()
(which takes a String
).
Example
extern crate dementia;
use ;
use ;
If you don't have an access token (yet) but the server supports password authentication, you can let the library generate its own access token:
let connection = new
.username
.password
.login
.connect;
Subsequentlty, you can retrieve the access token for future connections using
access_token = connection.get_access_token;