AsyncHTTPAPI¶
-
class
appservice_framework.matrix_api.
AsyncHTTPAPI
(base_url, client_session, token=None)¶ Bases:
matrix_client.api.MatrixHttpApi
Contains all raw matrix HTTP client-server API calls using asyncio and coroutines.
Examples
Methods Summary
add_user_tag
(user_id, room_id, tag[, order, …])ban_user
(room_id, user_id[, reason])Perform POST /rooms/$room_id/ban :param room_id: The room ID :type room_id: str :param user_id: The user ID of the banee(sic) :type user_id: str :param reason: The reason for this ban :type reason: str create_filter
(user_id, filter_params)create_room
([alias, is_public, invitees, …])Perform /createRoom. event_stream
(from_token[, timeout, query_params])Deprecated. forget_room
(room_id[, query_params])Perform POST /rooms/$room_id/forget get_download_url
(mxcurl)get_emote_body
(text)get_filter
(user_id, filter_id)get_membership
(room_id, user_id[, query_params])Perform GET /rooms/$room_id/state/m.room.member/$user_id :param room_id: The room ID :type room_id: str :param user_id: The user ID :type user_id: str get_power_levels
(room_id)Perform GET /rooms/$room_id/state/m.room.power_levels get_room_members
(room_id[, query_params])Get the list of members for this room. get_room_messages
(room_id, token, direction)Perform GET /rooms/{roomId}/messages. get_room_name
(room_id[, query_params])Perform GET /rooms/$room_id/state/m.room.name :param room_id: The room ID :type room_id: str :param query_params: Extra parameters to be sent in the HTTP request, get_room_state
(room_id[, query_params])Perform GET /rooms/$room_id/state :param room_id: The room ID :type room_id: str :param query_params: Extra parameters to be sent in the HTTP request, get_room_topic
(room_id[, query_params])Perform GET /rooms/$room_id/state/m.room.topic :param room_id: The room ID :type room_id: str :param query_params: Extra parameters to be sent in the HTTP request, get_text_body
(text[, msgtype])get_user_tags
(user_id, room_id)initial_sync
([limit, query_params])Deprecated. invite_user
(room_id, user_id[, query_params])Perform POST /rooms/$room_id/invite :param room_id: The room ID :type room_id: str :param user_id: The user ID of the invitee :type user_id: str join_room
(room_id_or_alias[, query_params])Performs /join/$room_id kick_user
(room_id, user_id[, reason, …])Calls set_membership with membership=”leave” for the user_id provided leave_room
(room_id[, query_params])Perform POST /rooms/$room_id/leave :param room_id: The room ID :type room_id: str :param query_params: Extra parameters to be sent in the HTTP request, login
(login_type, **kwargs)Perform /login. logout
([query_params])Perform /logout. media_upload
(content, content_type[, …])redact_event
(room_id, event_id[, reason, …])Perform PUT /rooms/$room_id/redact/$event_id/$txn_id/ register
([content, kind, query_params])Performs /register. remove_room_alias
(room_alias[, query_params])Remove mapping of an alias remove_user_tag
(user_id, room_id, tag)send_content
(room_id, item_url, item_name, …)send_emote
(room_id, text_content[, query_params])Perform PUT /rooms/$room_id/send/m.room.message with m.emote msgtype send_location
(room_id, geo_uri, name[, …])Send m.location message event send_message
(room_id, text_content[, …])Perform PUT /rooms/$room_id/send/m.room.message send_message_event
(room_id, event_type, content)Perform PUT /rooms/$room_id/send/$event_type send_notice
(room_id, text_content[, …])Perform PUT /rooms/$room_id/send/m.room.message with m.notice msgtype send_state_event
(room_id, event_type, content)Perform PUT /rooms/$room_id/state/$event_type set_account_data
(user_id, type, account_data)set_avatar_url
(user_id, avatar_url[, …])set_display_name
(user_id, display_name[, …])set_membership
(room_id, user_id, membership)Perform PUT /rooms/$room_id/state/m.room.member/$user_id :param room_id: The room ID :type room_id: str :param user_id: The user ID :type user_id: str :param membership: New membership value :type membership: str :param reason: The reason :type reason: str set_power_levels
(room_id, content)Perform PUT /rooms/$room_id/state/m.room.power_levels set_room_account_data
(user_id, room_id, …)set_room_alias
(room_id, room_alias[, …])Set alias to room id set_room_name
(room_id, name[, query_params])Perform PUT /rooms/$room_id/state/m.room.name :param room_id: The room ID :type room_id: str :param name: The new room name :type name: str :param query_params: Extra parameters to be sent in the HTTP request, set_room_topic
(room_id, topic[, query_params])Perform PUT /rooms/$room_id/state/m.room.topic :param room_id: The room ID :type room_id: str :param topic: The new room topic :type topic: str :param query_params: Extra parameters to be sent in the HTTP request, sync
([since, timeout_ms, filter, …])Perform a sync request. unban_user
(room_id, user_id)Perform POST /rooms/$room_id/unban :param room_id: The room ID :type room_id: str :param user_id: The user ID of the banee(sic) :type user_id: str validate_certificate
(valid)Methods Documentation
-
add_user_tag
(user_id, room_id, tag, order=None, body=None)¶
-
ban_user
(room_id, user_id, reason='')¶ Perform POST /rooms/$room_id/ban :param room_id: The room ID :type room_id: str :param user_id: The user ID of the banee(sic) :type user_id: str :param reason: The reason for this ban :type reason: str
-
create_filter
(user_id, filter_params)¶
-
create_room
(alias=None, is_public=False, invitees=(), query_params={})¶ Perform /createRoom.
Parameters: - alias (str) – Optional. The room alias name to set for this room.
- is_public (bool) – Optional. The public/private visibility.
- invitees (list<str>) – Optional. The list of user IDs to invite.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
event_stream
(from_token, timeout=30000, query_params={})¶ Deprecated. Use sync instead. Performs /events
Parameters: - from_token (str) – The ‘from’ query parameter.
- timeout (int) – Optional. The ‘timeout’ query parameter.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
forget_room
(room_id, query_params={})¶ Perform POST /rooms/$room_id/forget
Parameters: room_id (str) – The room ID
-
get_download_url
(mxcurl)¶
-
get_emote_body
(text)¶
-
get_filter
(user_id, filter_id)¶
-
get_membership
(room_id, user_id, query_params={})¶ Perform GET /rooms/$room_id/state/m.room.member/$user_id :param room_id: The room ID :type room_id: str :param user_id: The user ID :type user_id: str
-
get_power_levels
(room_id)¶ Perform GET /rooms/$room_id/state/m.room.power_levels
Parameters: room_id (str) – The room ID
-
get_room_members
(room_id, query_params={})¶ Get the list of members for this room.
Parameters: room_id (str) – The room to get the member events for.
-
get_room_messages
(room_id, token, direction, limit=10, to=None, query_params={})¶ Perform GET /rooms/{roomId}/messages.
Parameters: - room_id (str) – The room’s id.
- token (str) – The token to start returning events from.
- direction (str) – The direction to return events from. One of: [“b”, “f”].
- limit (int) – The maximum number of events to return.
- to (str) – The token to stop returning events at.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
get_room_name
(room_id, query_params={})¶ Perform GET /rooms/$room_id/state/m.room.name :param room_id: The room ID :type room_id: str :param query_params: Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
get_room_state
(room_id, query_params={})¶ Perform GET /rooms/$room_id/state :param room_id: The room ID :type room_id: str :param query_params: Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
get_room_topic
(room_id, query_params={})¶ Perform GET /rooms/$room_id/state/m.room.topic :param room_id: The room ID :type room_id: str :param query_params: Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
get_text_body
(text, msgtype='m.text')¶
-
initial_sync
(limit=1, query_params={})¶ Deprecated. Use sync instead. Perform /initialSync.
Parameters: - limit (int) – The limit= param to provide.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:user_id: user id for transaction.
-
invite_user
(room_id, user_id, query_params={})¶ Perform POST /rooms/$room_id/invite :param room_id: The room ID :type room_id: str :param user_id: The user ID of the invitee :type user_id: str
-
join_room
(room_id_or_alias, query_params={})¶ Performs /join/$room_id
Parameters: - room_id_or_alias (str) – The room ID or room alias to join.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
kick_user
(room_id, user_id, reason='', query_params={})¶ Calls set_membership with membership=”leave” for the user_id provided
-
leave_room
(room_id, query_params={})¶ Perform POST /rooms/$room_id/leave :param room_id: The room ID :type room_id: str :param query_params: Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
login
(login_type, **kwargs)¶ Perform /login.
Parameters: - login_type (str) – The value for the ‘type’ key.
- **kwargs – Additional key/values to add to the JSON submitted.
-
logout
(query_params={})¶ Perform /logout.
Parameters: query_params – Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
media_upload
(content, content_type, query_params={})¶
-
redact_event
(room_id, event_id, reason=None, txn_id=None, timestamp=None)¶ Perform PUT /rooms/$room_id/redact/$event_id/$txn_id/
Parameters:
-
register
(content={}, kind='user', query_params={})¶ Performs /register.
Parameters: - content (dict) –
The request payload. Should be specified for all non-guest registrations.
- username(string): The local part of the desired Matrix ID.
- If omitted, the homeserver MUST generate a Matrix ID local part.
- bind_email(boolean): If true, the server binds the email used for
- authentication to the Matrix ID with the ID Server. Email Registration not currently supported
password(string): Required. The desired password for the account.
- auth(dict): Authentication Data
- session(string): The value of the session key given by the
- homeserver.
- type(string): Required. The login type that the client is attempting
- to complete. “m.login.dummy” is the only non-interactive type.
- kind (str) – Specify kind=”guest” to register as guest.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:user_id: user id for transaction.
- content (dict) –
-
remove_room_alias
(room_alias, query_params={})¶ Remove mapping of an alias
Parameters: room_alias (str) – The alias to be removed. Raises: MatrixRequestError
-
remove_user_tag
(user_id, room_id, tag)¶
-
send_content
(room_id, item_url, item_name, msg_type, extra_information=None, query_params={})¶
-
send_emote
(room_id, text_content, query_params={})¶ Perform PUT /rooms/$room_id/send/m.room.message with m.emote msgtype
Parameters: - room_id (str) – The room ID to send the event in.
- text_content (str) – The m.emote body to send.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
send_location
(room_id, geo_uri, name, thumb_url=None, thumb_info=None, query_params={})¶ Send m.location message event
Parameters: - room_id (str) – The room ID to send the event in.
- geo_uri (str) – The geo uri representing the location.
- name (str) – Description for the location.
- thumb_url (str) – URL to the thumbnail of the location.
- thumb_info (dict) – Metadata about the thumbnail, type ImageInfo.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
send_message
(room_id, text_content, msgtype='m.text', query_params={})¶ Perform PUT /rooms/$room_id/send/m.room.message
Parameters: - room_id (str) – The room ID to send the event in.
- text_content (str) – The m.text body to send.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
send_message_event
(room_id, event_type, content, txn_id=None, query_params={})¶ Perform PUT /rooms/$room_id/send/$event_type
Parameters: - room_id (str) – The room ID to send the message event in.
- event_type (str) – The event type to send.
- content (dict) – The JSON content to send.
- txn_id (int) – Optional. The transaction ID to use.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
send_notice
(room_id, text_content, query_params={})¶ Perform PUT /rooms/$room_id/send/m.room.message with m.notice msgtype
Parameters: - room_id (str) – The room ID to send the event in.
- text_content (str) – The m.notice body to send.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
send_state_event
(room_id, event_type, content, state_key='', query_params={})¶ Perform PUT /rooms/$room_id/state/$event_type
Parameters: - room_id (str) – The room ID to send the state event in.
- event_type (str) – The state event type to send.
- content (dict) – The JSON content to send.
- state_key (str) – Optional. The state key for the event.
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
set_account_data
(user_id, type, account_data)¶
-
set_avatar_url
(user_id, avatar_url, query_params={})¶
-
set_display_name
(user_id, display_name, query_params={})¶
-
set_membership
(room_id, user_id, membership, reason='', profile={}, query_params={})¶ Perform PUT /rooms/$room_id/state/m.room.member/$user_id :param room_id: The room ID :type room_id: str :param user_id: The user ID :type user_id: str :param membership: New membership value :type membership: str :param reason: The reason :type reason: str
-
set_power_levels
(room_id, content)¶ Perform PUT /rooms/$room_id/state/m.room.power_levels
Note that any power levels which are not explicitly specified in the content arg are reset to default values.
Parameters: - Usage:
api = MatrixHttpApi(“http://example.com”, token=”foobar”) api.set_power_levels(“!exampleroom:example.com”,
- {
“ban”: 50, # defaults to 50 if unspecified “events”: {
“m.room.name”: 100, # must have PL 100 to change room name “m.room.power_levels”: 100 # must have PL 100 to change PLs}, “events_default”: 0, # defaults to 0 “invite”: 50, # defaults to 50 “kick”: 50, # defaults to 50 “redact”: 50, # defaults to 50 “state_default”: 50, # defaults to 50 if m.room.power_levels exists “users”: {
“@someguy:example.com”: 100 # defaults to 0}, “users_default”: 0 # defaults to 0
}
)
-
set_room_account_data
(user_id, room_id, type, account_data)¶
-
set_room_alias
(room_id, room_alias, query_params={})¶ Set alias to room id
Parameters:
-
set_room_name
(room_id, name, query_params={})¶ Perform PUT /rooms/$room_id/state/m.room.name :param room_id: The room ID :type room_id: str :param name: The new room name :type name: str :param query_params: Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
set_room_topic
(room_id, topic, query_params={})¶ Perform PUT /rooms/$room_id/state/m.room.topic :param room_id: The room ID :type room_id: str :param topic: The new room topic :type topic: str :param query_params: Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
sync
(since=None, timeout_ms=30000, filter=None, full_state=None, set_presence=None, query_params={})¶ Perform a sync request.
Parameters: - since (str) – Optional. A token which specifies where to continue a sync from.
- timeout_ms (int) – Optional. The time in milliseconds to wait.
- filter (int|str) – Either a Filter ID or a JSON string.
- full_state (bool) – Return the full state for every room the user has joined Defaults to false.
- set_presence (str) – Should the client be marked as “online” or” offline”
- query_params –
Extra parameters to be sent in the HTTP request,
These parameters are normally only used for application services. Common values for
query_params
are:ts: timestamp for eventuser_id: user id for transaction.
-
unban_user
(room_id, user_id)¶ Perform POST /rooms/$room_id/unban :param room_id: The room ID :type room_id: str :param user_id: The user ID of the banee(sic) :type user_id: str
-
validate_certificate
(valid)¶
-