mautrix.client.api.modules package

Submodules

mautrix.client.api.modules.media_repository module

class mautrix.client.api.modules.media_repository.MediaRepositoryMethods(mxid: NewType.<locals>.new_type, api: mautrix.api.http.HTTPAPI = None, loop: Optional[asyncio.events.AbstractEventLoop] = None, *args, **kwargs)[source]

Bases: mautrix.client.api.base.BaseClientAPI

Methods in section 13.8 Content Repository of the spec. These methods are used for uploading and downloading content from the media repository and for getting URL previews without leaking client IPs.

See also: API reference

download_media(url: NewType.<locals>.new_type) → bytes[source]

Download a file from the content repository.

See also: API reference

Parameters:url (ContentURI[str]) – The MXC URI to download.
Return type:bytes
Returns:The raw downloaded data.
download_thumbnail(url: NewType.<locals>.new_type, width: Optional[int] = None, height: Optional[int] = None, resize_method: Optional[str] = None, allow_remote: bool = True)[source]

Download a thumbnail for a file in the content repository.

See also: API reference

Parameters:
  • url (ContentURI[str]) – The MXC URI to download.
  • width (Optional[int]) – The _desired_ width of the thumbnail. The actual thumbnail may not match the size specified.
  • height (Optional[int]) – The _desired_ height of the thumbnail. The actual thumbnail may not match the size specified.
  • resize_method (Optional[str]) – The desired resizing method. Either crop or scale.
  • allow_remote (bool) – Indicates to the server that it should not attempt to fetch the media if it is deemed remote. This is to prevent routing loops where the server contacts itself.
Returns:

The raw downloaded data.

get_media_repo_config() → mautrix.client.api.types.media.MediaRepoConfig[source]

This endpoint allows clients to retrieve the configuration of the content repository, such as upload limitations. Clients SHOULD use this as a guide when using content repository endpoints. All values are intentionally left optional. Clients SHOULD follow the advice given in the field description when the field is not available.

NOTE: Both clients and server administrators should be aware that proxies between the client and the server may affect the apparent behaviour of content repository APIs, for example, proxies may enforce a lower upload size limit than is advertised by the server on this endpoint.

See also: API reference

Return type:MediaRepoConfig
Returns:The media repository config.
get_url_preview(url: str, timestamp: Optional[int] = None) → mautrix.client.api.types.media.MXOpenGraph[source]

Get information about a URL for a client.

See also: API reference

Parameters:
  • url (str) – The URL to get a preview of.
  • timestamp (Optional[int]) – The preferred point in time to return a preview for. The server may return a newer version if it does not have the requested version available.
Return type:

MXOpenGraph

upload_media(data: bytes, mime_type: Optional[str] = None, filename: Optional[str] = None) → NewType.<locals>.new_type[source]

Upload a file to the content repository.

See also: API reference

Parameters:
  • data (bytes) – The data to upload.
  • mime_type (Optional[str]) – The MIME type to send with the upload request.
  • filename (Optional[str]) – The filename to send with the upload request.
Return type:

ContentURI[str]

Returns:

The MXC URI to the uploaded file.

Raises:

MatrixResponseError – If the response does not contain a content_uri field.

mautrix.client.api.modules.misc module

class mautrix.client.api.modules.misc.MiscModuleMethods(mxid: NewType.<locals>.new_type, api: mautrix.api.http.HTTPAPI = None, loop: Optional[asyncio.events.AbstractEventLoop] = None, *args, **kwargs)[source]

Bases: mautrix.client.api.base.BaseClientAPI

Miscellaneous subsections in the Modules section of the API spec.

Currently included subsections:

get_presence(user_id: NewType.<locals>.new_type) → mautrix.client.api.types.event.ephemeral.PresenceEventContent[source]

Get the presence info of a user.

See also: API reference

Parameters:user_id (UserID[str]) – The ID of the user whose presence info to get.
Return type:PresenceEventContent
Returns:The presence info of the given user.
send_receipt(room_id: NewType.<locals>.new_type, event_id: NewType.<locals>.new_type, receipt_type: str = 'm.read') → None[source]

Update the marker for the given receipt type to the event ID specified.

See also: API reference

Parameters:
  • room_id (RoomID[str]) – The ID of the room which to send the receipt to.
  • event_id (EventID[str]) – The last event ID to acknowledge.
  • receipt_type (str) – The type of receipt to send. Currently only m.read is supported.
Return type:

None

set_fully_read_marker(room_id: NewType.<locals>.new_type, fully_read: NewType.<locals>.new_type, read_receipt: Optional[NewType.<locals>.new_type] = None) → None[source]

Set the position of the read marker for the given room, and optionally send a new read receipt.

See also: API reference

Parameters:
  • room_id (RoomID[str]) – The ID of the room which to set the read marker in.
  • fully_read (EventID[str]) – The last event up to which the user has either read all events or is not interested in reading the events.
  • read_receipt (Optional[EventID[str]]) – The new position for the user’s normal read receipt, i.e. the last event the user has seen.
Return type:

None

set_presence(presence: <unknown>.PresenceState = online, status: Optional[str] = None) → None[source]

Set the current user’s presence state. When setting the status, the activity time is updated to reflect that activity; the client does not need to specify Presence.last_active_ago.

See also: API reference

Parameters:
  • presence (PresenceState) – The new presence state to set.
  • status (Optional[str]) – The status message to attach to this state.
Return type:

None

set_typing(room_id: NewType.<locals>.new_type, timeout: int = 0) → None[source]

This tells the server that the user is typing for the next N milliseconds where N is the value specified in the timeout key. If the timeout is equal to or less than zero, it tells the server that the user has stopped typing.

See also: API reference

Parameters:
  • room_id (RoomID[str]) – The ID of the room in which the user is typing.
  • timeout (int) – The length of time in seconds to mark this user as typing.
Return type:

None

Module contents

class mautrix.client.api.modules.ModuleMethods(mxid: NewType.<locals>.new_type, api: mautrix.api.http.HTTPAPI = None, loop: Optional[asyncio.events.AbstractEventLoop] = None, *args, **kwargs)[source]

Bases: mautrix.client.api.modules.media_repository.MediaRepositoryMethods, mautrix.client.api.modules.misc.MiscModuleMethods

Methods in section 13 Modules of the spec.

See also: API reference