AppService¶
-
class
appservice_framework.AppService(matrix_server, server_domain, access_token, user_namespace, room_namespace, sender_localpart, database_url, loop=None, invite_only_rooms=False)¶ Bases:
objectRun the Matrix Appservice.
This needs to maintain state of matrix rooms and bridged users in those rooms.
Attributes Summary
apiThe matrix API object for the appservice. http_sessionThe HTTP session object. Methods Summary
add_authenticated_user(matrixid, auth_token)Add an authenticated user to the appservice. get_connection([serviceid, wait_for_connect])Get the connection object for a given user. get_room([matrixid, serviceid])Get a appservice_framework.database.Roomobject based on IDs.get_user([matrixid, serviceid, user_type])Get a appservice_framework.database.Userobject based on IDs.matrix_recieve_image(coro)A matrix ‘m.room.message’ event with ‘m.image’ type. matrix_recieve_message(coro)A matrix ‘m.room.message’ event with ‘m.text’ type. matrix_user_join(coro)coro(appservice, event) matrix_user_part(coro)coro(appservice, event) matrix_user_typing(coro)coro(appservice, event) run([host, port])Run the appservice. service_change_profile_image(coro)Decorator for when an authenticated user changes profile picture service_connect(coro)A decorator to register the connection function. service_join_room(coro)This function is called when an authenticated user joins a new service room, i.e. service_part_room(coro)This is called when a matrix user leaves a room. service_room_exists(coro)Decorator to query if a service room exists. Attributes Documentation
-
api¶ The matrix API object for the appservice.
Note
This is only acceible inside the
runcontext manager.
Methods Documentation
-
add_authenticated_user(matrixid, auth_token, serviceid=None, nick=None)¶ Add an authenticated user to the appservice.
This user will connect when the appservice is run, if serviceid was not specified it must be returned by the connect decorator.
Parameters: Returns: connection (
object) – A connection object, as returned by the@appservice.service_connectdecorator.
-
get_connection(serviceid=None, wait_for_connect=False)¶ Get the connection object for a given user.
Parameters: Returns: connection (
objectorasyncio.Task) – The connection object as returned by@appservice.service_connect.
-
get_room(matrixid=None, serviceid=None)¶ Get a
appservice_framework.database.Roomobject based on IDs.Parameters: Returns: user (
appservice_framework.database.RoomorNone) – The user in the database orNoneif the room was not found.
-
get_user(matrixid=None, serviceid=None, user_type='service')¶ Get a
appservice_framework.database.Userobject based on IDs.Parameters: Returns: user (
appservice_framework.database.UserorNone) – The user in the database orNoneif the user was not found.
-
matrix_recieve_image(coro)¶ A matrix ‘m.room.message’ event with ‘m.image’ type.
coro(appservice, auth_user, room, content)
-
matrix_recieve_message(coro)¶ A matrix ‘m.room.message’ event with ‘m.text’ type.
coro(appservice, auth_user, room, content)
-
matrix_user_join(coro)¶ coro(appservice, event)
-
matrix_user_part(coro)¶ coro(appservice, event)
-
matrix_user_typing(coro)¶ coro(appservice, event)
-
run(host='127.0.0.1', port=5000)¶ Run the appservice.
Example
>>> apps = AppService(...) >>> with apps.run() as run_forever: ... run_forever()
-
service_change_profile_image(coro)¶ Decorator for when an authenticated user changes profile picture
coro(appservice)
Returns: mxid image_url force_update
-
service_connect(coro)¶ A decorator to register the connection function.
This function is called for every
AuthenticatedUseronrun().Function Signature
coro(appservice, serviceid, auth_token)Returns
-
service_join_room(coro)¶ This function is called when an authenticated user joins a new service room, i.e. a room that exists but the service account is not currently a member of.
coro(appservice, service_userid, service_roomid)
-
service_part_room(coro)¶ This is called when a matrix user leaves a room.
coro(appservice, user, room)
-
service_room_exists(coro)¶ Decorator to query if a service room exists.
coro(appservice, service_roomid)
-