errbot.backends.telegram_messenger module¶
-
class
errbot.backends.telegram_messenger.
TelegramBackend
(config)[source]¶ Bases:
errbot.core.ErrBot
-
build_identifier
(txtrep)[source]¶ Convert a textual representation into a
TelegramPerson
orTelegramRoom
.
-
build_reply
(msg, text=None, private=False, threaded=False)[source]¶ Should be implemented by the backend
-
change_presence
(status: str = 'online', message: str = '') → None[source]¶ Signal a presence change for the bot. Should be overridden by backends with a super().send_message() call.
-
mode
¶
-
prefix_groupchat_reply
(message, identifier)[source]¶ Patches message with the conventional prefix to ping the specific contact For example: @gbin, you forgot the milk !
-
query_room
(room)[source]¶ Not supported on Telegram.
Raises: RoomsNotSupportedError
-
rooms
()[source]¶ Not supported on Telegram.
Raises: RoomsNotSupportedError
-
send_message
(msg)[source]¶ This needs to be overridden by the backends with a super() call.
Parameters: msg – the message to send. Returns: None
-
send_stream_request
(identifier, fsource, name='file', size=None, stream_type=None)[source]¶ Starts a file transfer.
Parameters: - identifier – TelegramPerson or TelegramMUCOccupant Identifier of the Person or Room to send the stream to.
- fsource – str, dict or binary data File URL or binary content from a local file. Optionally a dict with binary content plus metadata can be given. See stream_type for more details.
- name (
str
) – str, optional Name of the file. Not sure if this works always. - size – str, optional Size of the file obtained with os.path.getsize. This is only used for debug logging purposes.
- stream_type –
str, optional Type of the stream. Choices: ‘document’, ‘photo’, ‘audio’, ‘video’, ‘sticker’, ‘location’.
If ‘video’, a dict is optional as {‘content’: fsource, ‘duration’: str}. If ‘voice’, a dict is optional as {‘content’: fsource, ‘duration’: str}. If ‘audio’, a dict is optional as {‘content’: fsource, ‘duration’: str, ‘performer’: str, ‘title’: str}.
For ‘location’ a dict is mandatory as {‘latitude’: str, ‘longitude’: str}. For ‘venue’: TODO # see: https://core.telegram.org/bots/api#sendvenue
Return stream: str or Stream If fsource is str will return str, else return Stream.
-
serve_once
()[source]¶ Connect the back-end to the server and serve a connection once (meaning until disconnected for any reason).
Back-ends MAY choose not to implement this method, IF they implement a custom
serve_forever()
.This function SHOULD raise an exception or return a value that evaluates to False in order to signal something went wrong. A return value that evaluates to True will signal the bot that serving is done and a shut-down is requested.
-
-
class
errbot.backends.telegram_messenger.
TelegramBotFilter
[source]¶ Bases:
object
This is a filter for the logging library that filters the “No new updates found.” log message generated by telegram.bot.
This is an INFO-level log message that gets logged for every getUpdates() call where there are no new messages, so is way too verbose.
-
class
errbot.backends.telegram_messenger.
TelegramIdentifier
(id)[source]¶ Bases:
errbot.backends.base.Identifier
-
aclattr
¶
-
id
¶
-
-
class
errbot.backends.telegram_messenger.
TelegramMUCOccupant
(id, room, first_name=None, last_name=None, username=None)[source]¶ Bases:
errbot.backends.telegram_messenger.TelegramPerson
,errbot.backends.base.RoomOccupant
This class represents a person inside a MUC.
-
__init__
(id, room, first_name=None, last_name=None, username=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
room
¶ Some backends have the full name of a user.
Returns: the fullname of this user if available.
-
username
¶
-
-
class
errbot.backends.telegram_messenger.
TelegramPerson
(id, first_name=None, last_name=None, username=None)[source]¶ Bases:
errbot.backends.telegram_messenger.TelegramIdentifier
,errbot.backends.base.Person
-
__init__
(id, first_name=None, last_name=None, username=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
client
¶ Returns: a backend specific unique identifier representing the device or client the person is using to talk.
-
first_name
¶
-
fullname
¶ Some backends have the full name of a user.
Returns: the fullname of this user if available.
-
id
¶
-
last_name
¶
-
nick
¶
-
person
¶
-
username
¶
-
-
class
errbot.backends.telegram_messenger.
TelegramRoom
(id, title=None)[source]¶ Bases:
errbot.backends.telegram_messenger.TelegramIdentifier
,errbot.backends.base.Room
-
exists
¶ Boolean indicating whether this room already exists or not.
Getter: Returns True if the room exists, False otherwise.
-
id
¶
-
invite
(*args)[source]¶ Invite one or more people into the room.
*argsargs: One or more identifiers to invite into the room.
-
join
(username: str = None, password: str = None)[source]¶ Join the room.
If the room does not exist yet, this will automatically call
create()
on it first.
-
joined
¶ Boolean indicating whether this room has already been joined.
Getter: Returns True if the room has been joined, False otherwise.
-
leave
(reason: str = None)[source]¶ Leave the room.
Parameters: reason ( str
) – An optional string explaining the reason for leaving the room.
-
occupants
¶ The room’s occupants.
Getter: Returns a list of occupant identities. Raises: MUCNotJoinedError
if the room has not yet been joined.
-
title
¶ Return the groupchat title (only applies to groupchats)
-
topic
¶ The room topic.
Getter: Returns the topic (a string) if one is set, None if no topic has been set at all.
Note
Back-ends may return an empty string rather than None when no topic has been set as a network may not differentiate between no topic and an empty topic.
Raises: MUCNotJoinedError
if the room has not yet been joined.
-