errbot.backends.telegram_messenger module

exception errbot.backends.telegram_messenger.RoomsNotSupportedError(message: str | None = None)[source]

Bases: RoomError

__init__(message: str | None = None)[source]
class errbot.backends.telegram_messenger.TelegramBackend(config)[source]

Bases: ErrBot

__init__(config)[source]

Those arguments will be directly those put in BOT_IDENTITY

build_identifier(txtrep: str) TelegramPerson | TelegramRoom[source]

Convert a textual representation into a TelegramPerson or TelegramRoom.

build_reply(msg: Message, text: str | None = None, private: bool = False, threaded: bool = False) Message[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.

property mode: text
prefix_groupchat_reply(message: Message, identifier: Identifier)[source]

Patches message with the conventional prefix to ping the specific contact For example: @gbin, you forgot the milk !

query_room(room: TelegramRoom) None[source]

Not supported on Telegram.

Raises:

RoomsNotSupportedError

rooms() None[source]

Not supported on Telegram.

Raises:

RoomsNotSupportedError

send_message(msg: Message) None[source]

This needs to be overridden by the backends with a super() call.

Parameters:

msg (Message) – the message to send.

Returns:

None

send_stream_request(identifier: TelegramPerson | TelegramMUCOccupant, fsource: str | dict | BinaryIO, name: str | None = 'file', size: int | None = None, stream_type: str | None = None) str | Stream[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, 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() None[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.

set_message_size_limit(limit: int = 1024, hard_limit: int = 1024) None[source]

Telegram message size limit

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.

static filter(record)[source]
class errbot.backends.telegram_messenger.TelegramIdentifier(id)[source]

Bases: Identifier

__init__(id)[source]
property aclattr: str
property id: str
class errbot.backends.telegram_messenger.TelegramMUCOccupant(id, room: TelegramRoom, first_name=None, last_name=None, username=None)[source]

Bases: TelegramPerson, RoomOccupant

This class represents a person inside a MUC.

__init__(id, room: TelegramRoom, first_name=None, last_name=None, username=None)[source]
property room: TelegramRoom

Some backends have the full name of a user.

Returns:

the fullname of this user if available.

property username: str
class errbot.backends.telegram_messenger.TelegramPerson(id, first_name=None, last_name=None, username=None)[source]

Bases: TelegramIdentifier, Person

__init__(id, first_name=None, last_name=None, username=None)[source]
property client: None
Returns:

a backend specific unique identifier representing the device or client the person is using to talk.

property first_name: str
property fullname: str

Some backends have the full name of a user.

Returns:

the fullname of this user if available.

property id: str
property last_name: str
property nick: str
Returns:

a backend specific nick returning the nickname of this person if available.

property person: str
Returns:

a backend specific unique identifier representing the person you are talking to.

property username: str
class errbot.backends.telegram_messenger.TelegramRoom(id, title=None)[source]

Bases: TelegramIdentifier, Room

__init__(id, title=None)[source]
create() None[source]

Create the room.

Calling this on an already existing room is a no-op.

destroy() None[source]

Destroy the room.

Calling this on a non-existing room is a no-op.

property exists: None

Boolean indicating whether this room already exists or not.

Getter:

Returns True if the room exists, False otherwise.

property id: str
invite(*args) None[source]

Invite one or more people into the room.

Parameters:

*args

One or more identifiers to invite into the room.

join(username: str = None, password: str = None) None[source]

Join the room.

If the room does not exist yet, this will automatically call create() on it first.

property joined: None

Boolean indicating whether this room has already been joined.

Getter:

Returns True if the room has been joined, False otherwise.

leave(reason: str = None) None[source]

Leave the room.

Parameters:

reason (str) – An optional string explaining the reason for leaving the room.

property occupants: None

The room’s occupants.

Getter:

Returns a list of occupant identities.

Raises:

MUCNotJoinedError if the room has not yet been joined.

property title

Return the groupchat title (only applies to groupchats)

property topic: None

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.