Bridges

Bridges are components designed to connect different storages and frontends. For example, Telegram frontend may require storing something in a persistent storage; since the data is frontend-specific, we shouldn't add corresponding methods to Storage interface, but rather create a separate component using the same database.

suppgram.frontends.telegram.TelegramStorage

Persistent storage for data specific to Telegram frontend.

Currently, two entities are stored: Telegram chats and messages within chats. We need these data to track group roles and edit messages sent by bots if needed.

get_chat(telegram_chat_id) abstractmethod async

Fetch Telegram chat by Telegram chat ID.

create_or_update_chat(telegram_chat_id) abstractmethod async

Create or update Telegram chat by Telegram chat ID.

add_chat_roles(telegram_chat_id, *roles) abstractmethod async

Assign roles to a Telegram chat.

get_chats_by_role(role) abstractmethod async

Fetch all Telegram chats which have been assigned a role.

insert_message(telegram_bot_id, chat, telegram_message_id, kind, *, agent_id=None, customer_id=None, conversation_id=None, telegram_bot_username=None) abstractmethod async

Store information about a Telegram message.

get_message(chat, telegram_message_id) abstractmethod async

Fetch a Telegram message.

get_messages(kind, *, agent_id=None, conversation_id=None, telegram_bot_username=None) abstractmethod async

Fetch all Telegram messages satisfying condition(s).

delete_messages(messages) abstractmethod async

Delete given Telegram messages.

get_newer_messages_of_kind(messages) abstractmethod async

For all given messages, find all newer messages in the corresponding chats.

"Newer" here means "with greater Telegram message ID".


suppgram.bridges.sqlalchemy_telegram.SQLAlchemyTelegramBridge

Bases: TelegramStorage

Implementation of TelegramStorage for SQLAlchemy.

__init__(engine, chat_model=TelegramChat, message_model=TelegramMessage)

Parameters:
  • engine (AsyncEngine) –

    asynchronous SQLAlchemy engine

  • chat_model (Any, default: TelegramChat ) –

    SQLAlchemy model for Telegram chats

  • message_model (Any, default: TelegramMessage ) –

    SQLAlchemy model for Telegram messages


suppgram.bridges.mongodb_telegram.MongoDBTelegramBridge

Bases: TelegramStorage

Implementation of Storage for MongoDB via Motor library.

__init__(database, chat_collection_name='suppgram_telegram_chats', messages_collection_name='suppgram_telegram_messages')

Parameters:
  • database (AgnosticDatabase) –

    asyncio-compatible Motor MongoDB database to store data in

  • chat_collection_name (str, default: 'suppgram_telegram_chats' ) –

    name of MongoDB collection to store data on Telegram chats in

  • messages_collection_name (str, default: 'suppgram_telegram_messages' ) –

    name of MongoDB collection to store references to Telegram messages in