matrigram¶
The bridge between matrix and telegram.
Contents:
Quick start¶
After the server is running, switch to your telegram app and add the bot to your contact list.
First login with your matrix account:
/login username password
The bot will reply with information.
Use
/join room_id_or_alias
to join rooms, or/leave
to leave them.Once you have joined rooms, use
/focus
to choose what room you are interested at the moment.
Focus¶
When communicating with our telegram bot, you only have one conversation windows open while you may have joined many matrix rooms. Showing all messages from all different rooms in one conversation is confusing and a big mess, hence the focus feature.
If you send a message, the message will be relayed to your focused room only. When messages are being sent in your focused rooms, they will be relayed to your telegram client. Messages from other rooms you have joined will not be sent to you while not focused.
Usage¶
To set your focus room simply write down /focus
, which will prompt you for the rooms you have joined.
In order to view status regarding the rooms you have joined and focused room use the /status
command.
Bot commands¶
/login <username> <password>
Log in with your matrix username and password.
/logout
Log out of your matrix user.
/join <room_name>
Join to the given room.
/leave
Get a list of the rooms you have joined.
/discover_rooms
Get a list of public rooms on the server.
This may not work on big servers with many public rooms
/focus
Interactive command. Prompt the user for the room he wants to “focus” right now.
/setname <new_name>
Sets matrix display name.
/status
Return general information regarding the user status.
/create_room <room_alias> [invitees]
Create a room with room_alias and invite invitees to it. Room alias should be provided without the homeserver suffix. Invitees is an optional space seperated list of matrix ids to be invited.
/me <text>
Send an emote to the room.
Every other message (text, photos, videos) which is sent while logged in and focused to a room will be propagated to the room, and vice versa for the room messages being sent from other users.
Matrigram code¶
Bot¶
-
class
matrigram.bot.
MatrigramBot
(*args, **kwargs)[source]¶ -
_get_chat_id
(client)[source]¶ Get telegram id associated with client.
Parameters: client (MatrigramClient) – The client to be queried. Returns: The chat_id associated to the client. Return type: str
-
_get_client
(chat_id)[source]¶ Get matrigram client.
Parameters: chat_id – Telegram user id. Returns: The client associated to the telegram user with chat_id. Return type: MatrigramClient
-
login
(msg, match)[source]¶ Perform login.
Parameters: - msg – The message object received from telegram user.
- match – Match object containing extracted data.
-
on_callback_query
(msg)[source]¶ Handle callback queries.
Route queries using
self.callback_query_routes
.Parameters: msg – The message object received from telegram user.
-
on_chat_message
(msg)[source]¶ Main entry point.
This function is our main entry point to the bot. Messages will be routed according to their content type.
Parameters: msg – The message object received from telegram user.
-
on_text_message
(msg)[source]¶ Handle text messages.
Route text messages using
self.routes
.Parameters: msg – The message object received from telegram user.
-
send_message
(sender, msg, client)[source]¶ Send message to telegram user.
Parameters: - sender (str) – Name of the sender.
- msg (str) – Text message.
- client (MatrigramClient) – The client the message is originated in.
Returns:
-
Client¶
-
class
matrigram.client.
MatrigramClient
(server, tb, username)[source]¶ -
_get_rooms_updated
()[source]¶ Return rooms dictionary with updated aliases.
Returns (dict): Return rooms dictionary with updated aliases.
-
_room_alias_to_id
(alias)[source]¶ Convert room alias to id.
Parameters: alias (str) – Room alias. Returns (str): Room id.
-
Helper¶
-
matrigram.helper.
config_filled
()[source]¶ Check if the user filled the config file.
Returns: True if config is filled, else False. Return type: bool
-
matrigram.helper.
get_config
()[source]¶ Query config file.
Returns: The config dictionary. Return type: dict
-
matrigram.helper.
list_to_nice_lines
(l)[source]¶ Convert a string list to lines ready to printed.
Parameters: l (list) – List of strings to be printed Returns: A line separated string that can be printed. Return type: str