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:

caridina/connection.cr

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) : Nil edit_message, send_message(room_id : String, message : String, html : String | Nil = nil) : String send_message

Constructor Detail

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

Create a new connection object using an access_token.


[View source]

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


[View source]

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


[View source]
def edit_message(room_id : String, event_id : String, message : String, html : String | Nil = nil) : Nil #

Edits a message.

Only m.text messages are supported for now.


[View source]
def join(room_id) : Nil #

Joins a room.

Matrix API


[View source]
def send_message(room_id : String, message : String, html : String | Nil = nil) : String #

Sends a message to a given room.

Only m.text messages are supported for now.


[View source]
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


[View source]
def user_id : String #

Returns the connected account's user_id.


[View source]
def whoami : String #

Returns the connected account's user_id.

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

Matrix API


[View source]