class Caridina::Connection

Overview

A Matrix connection.

This is the main entrypoint for this library. You will find here all methods to interact with the Matrix API.

Those methods handle retrying when the connection is being rate limited. If there is another error, an ExecError while be returned.

Included Modules

Defined in:

Constant Summary

Log = Caridina::Log.for(self)

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Caridina::Modules::Typing

send_typing(room_id : String, timeout = 3000, typing = true) : Nil send_typing, typing(room_id : String, &) typing

Instance methods inherited from module Caridina::Modules::Receipts

send_receipt(room_id : String, event_id : String, type = Type::Read) : Nil send_receipt

Instance methods inherited from module Caridina::ConnectionInterface

edit_message(room_id : String, event_id : String, message : String, html : String? = nil) : Nil edit_message, send_message(room_id : String, message : String, html : String? = nil) : String send_message

Constructor Detail

def self.new(hs_url : String, access_token : String) #

Create a new connection object using an access_token.


Class Method Detail

def self.login(hs_url : String, user_id : String, password : String) : String #

Logs in using to a given homeserver and returns the access token.

Matrix API


Instance Method Detail

def create_filter(filter) : String #

Creates a sync filter and returns its id.

The filter parameter must be a JSON serializable object.

TODO This should be implement with a proper model object.

Matrix API


def edit_message(room_id : String, event_id : String, message : String, html : String? = nil) : Nil #

Edits a message.

Only m.text messages are supported for now.


def join(room_id) : Nil #

Joins a room.

Matrix API


def send_message(room_id : String, message : String, html : String? = nil) : String #

Sends a message to a given room.

Only m.text messages are supported for now.


def sync(channel : Channel(Responses::Sync)) #

Starts syncing.

This method starts a new fiber wich will run sync queries, and send received events in channel.

It uses a filter to limit the received events to supported ones.

When called, it will first do an inital sync. This first sync may return events you already seen in a previous sync. You should handle this in your code, either by skipping the first sync or by storing the id of the events you processed.

TODO accept an next_batch parameter to skip the initial sync.

Matrix API


def user_id : String #

Returns the connected account's user_id.


def whoami : String #

Returns the connected account's user_id.

You probably should use #user_id which already store that information.

Matrix API