Storages

suppgram.storage.Storage

Storage encapsulates functionality related to storing data persistently in a database, allowing to integrate Suppgram into systems with various tech stacks.

Basically implements Repository design pattern.

initialize() async

Performs asynchronous initialization if needed.

create_or_update_customer(identification, diff=None) abstractmethod async

Creates or updates customer identified by given identification with new data provided in diff.

Can be used with diff=None to get already existing customer with no changes applied.

Parameters:
  • identification (CustomerIdentification) –

    data necessary to uniquely identify the customer.

  • diff (Optional[CustomerDiff], default: None ) –

    optional metadata to be updated.

get_agent(identification) abstractmethod async

find_all_agents() abstractmethod

create_or_update_agent(identification, diff=None) abstractmethod async

update_agent(identification, diff) abstractmethod async

get_workplace(identification) abstractmethod async

get_agent_workplaces(agent) abstractmethod async

get_or_create_workplace(identification) abstractmethod async

create_tag(name, created_by) abstractmethod async

find_all_tags() abstractmethod async

get_or_create_conversation(customer) abstractmethod async

find_conversations_by_ids(conversation_ids, with_messages=False) abstractmethod async

find_all_conversations(with_messages=False) abstractmethod

count_all_conversations() abstractmethod async

update_conversation(id, diff, unassigned_only=False) abstractmethod async

get_agent_conversation(identification) abstractmethod async

find_customer_conversations(customer, with_messages=False) abstractmethod async

find_agent_conversations(agent, with_messages=False) abstractmethod async

save_message(conversation, message) abstractmethod async

save_event(event) abstractmethod async

find_all_events() abstractmethod

Iterate over all stored events in chronological order.

count_all_events() abstractmethod async


SQLAlchemy

suppgram.storages.sqlalchemy.SQLAlchemyStorage

Bases: Storage

Implementation of Storage for SQLAlchemy.

__init__(engine, models)

Parameters:
  • engine (AsyncEngine) –

    asynchronous SQLAlchemy engine

  • models (Models) –

    collection of SQLAlchemy model types. Allows using custom models, possibly enriched with some business-specific fields or stripped of unnecessary columns (e.g. for frontends you are not going to use).

suppgram.storages.sqlalchemy.Models

Abstraction layer over SQLAlchemy models.

Default models are declared in suppgram.storages.mongodb.collections package.

__init__(engine, customer_model=Customer, agent_model=Agent, workplace_model=Workplace, conversation_model=Conversation, conversation_message_model=ConversationMessage, tag_model=Tag, conversation_tag_association_table=association_table, event_model=Event)

Parameters:
  • engine (AsyncEngine) –

    asynchronous SQLAlchemy engine

  • customer_model (Any, default: Customer ) –

    SQLAlchemy model for customers

  • agent_model (Any, default: Agent ) –

    SQLAlchemy model for agents

  • workplace_model (Any, default: Workplace ) –

    SQLAlchemy model for workplaces

  • conversation_model (Any, default: Conversation ) –

    SQLAlchemy model for conversations

  • conversation_message_model (Any, default: ConversationMessage ) –

    SQLAlchemy model for messages

  • tag_model (Any, default: Tag ) –

    SQLAlchemy model for conversation tags

  • event_model (Any, default: Event ) –

    SQLAlchemy model for events


MongoDB

suppgram.storages.mongodb.MongoDBStorage

Bases: Storage

Implementation of Storage for MongoDB via Motor library.

__init__(collections)

Parameters:
  • collections (Collections) –

    object storing collection names and conversion routines. Allows using custom collection names, can be subclassed to customize BSON documents structure.

suppgram.storages.mongodb.Collections

Abstraction layer over MongoDB database and collection names and BSON documents structure.

__init__(database, customer_collection_name='suppgram_customers', agent_collection_name='suppgram_agents', conversation_collection_name='suppgram_conversations', tag_collection_name='suppgram_tags', event_collection_name='suppgram_events', codec_options=CodecOptions(tz_aware=True, tzinfo=timezone.utc, uuid_representation=UuidRepresentation.STANDARD))

Parameters:
  • database (AgnosticDatabase) –

    asyncio-compatible Motor MongoDB database to store data in

  • customer_collection_name (str, default: 'suppgram_customers' ) –

    name of MongoDB collection to store customers in

  • agent_collection_name (str, default: 'suppgram_agents' ) –

    name of MongoDB collection to store agents and workplaces in

  • conversation_collection_name (str, default: 'suppgram_conversations' ) –

    name of MongoDB collection to store conversations and messages in

  • tag_collection_name (str, default: 'suppgram_tags' ) –

    name of MongoDB collection to store tags in