Builder

Suppgram application can be constructed programmatically within a Python script with Builder component which implements traditional Builder pattern. For example, code doing the same as CLI call from Quickstart would look like this:

import asyncio

from suppgram.builder import Builder

builder = (
    Builder()
    .with_sqlalchemy_storage("sqlite+aiosqlite:///test.db")
    .with_telegram_manager_frontend("<secret token of Manager bot>", your_Telegram_user_ID)
    .with_telegram_customer_frontend("<secret token of Customer bot>")
    .with_telegram_agent_frontend(["<secret token of Agent bot>"])
    .build()
)
loop = asyncio.get_event_loop()
loop.run_until_complete(builder.start())
loop.run_forever()

suppgram.builder.Builder

Provides a simple interface for building functional Suppgram application from separate components.

__init__()

build()

Instantiate all configured components and raise exception if misconfigured.

start() async

Start all configured components.

with_storage(storage)

Configure arbitrary Storage instance.

with_sqlalchemy_storage(sqlalchemy_uri)

Configure SQLAlchemyStorage.

with_mongodb_storage(mongodb_uri, mongodb_database_name)

Configure MongoDBStorage.

with_texts(texts)

Configure arbitrary TextProvider instance.

with_texts_class_path(texts_class_path)

Create TextProvider instance of given class.

Assumes that its __init__ method doesn't require any arguments.

with_telegram_manager_frontend(telegram_manager_bot_token, telegram_owner_id=None)

Configure Telegram manager frontend.

Parameters:
  • telegram_manager_bot_token (str) –

    Telegram bot token for manager bot

  • telegram_owner_id (Optional[int], default: None ) –

    Telegram user ID of system administrator/owner

with_telegram_customer_frontend(telegram_customer_bot_token)

Configure Telegram customer frontend.

Parameters:
  • telegram_customer_bot_token (str) –

    Telegram bot token for customer bot

with_shell_customer_frontend(uuid=None)

Configure shell customer frontend. Allows to chat with an agent directly in the shell. Useful for debug purposes.

with_pubnub_customer_frontend(pubnub_user_id, pubnub_channel_group, pubnub_message_converter_class_path='suppgram.frontends.pubnub.DefaultMessageConverter')

Configure PubNub customer frontend.

Parameters:
  • pubnub_user_id (str) –

    PubNub user ID of the support user, on whose behalf agent messages will be sent to users

  • pubnub_channel_group (str) –

    ID of Pubnub channel group which includes all customers' chats with support

  • pubnub_message_converter_class_path (str, default: 'suppgram.frontends.pubnub.DefaultMessageConverter' ) –

    allows to customize conversion between Suppgram dataclasses and PubNub message JSONs

with_telegram_agent_frontend(telegram_agent_bot_tokens)

Configure Telegram agent frontend.

Parameters:
  • telegram_agent_bot_tokens (List[str]) –

    list of Telegram bot tokens for agent bots. More tokens — more simultaneous chats with customers per agent