Skip to content

shipany.bot.persistency

shipany.bot.persistency package

Submodules

shipany.bot.persistency.handles module

class shipany.bot.persistency.handles.HandleGenerator

Bases: ABC

Generates a handle for a capture given a key and a scope.

abstract generate(key, scope)

Generate a handle for a capture given a key and a scope.

  • Parameters:
    • key (str) — The key to generate the handle for.
    • scope (list[Scope]) — The scope to generate the handle for.
    • self (t.Self)
  • Returns: The generated handle.
  • Return type: str

class shipany.bot.persistency.handles.NoScopeHandleGenerator

Bases: HandleGenerator

Generates a handle for a capture given a key and a scope.

The handle is used to store and retrieve a value from a capture. The handle should be unique for each key and scope.

The implementation should be: : - deterministic and should not depend on the environment or the state of the system

  • thread-safe
  • stateless
  • side-effect free
  • idempotent

By default, the handle is the key itself. It simplifies testing and debugging. However, it is not suitable for production.

generate(key, _)

Generate a handle for a capture given a key and a scope.

  • Parameters:
    • key (str) — The key to generate the handle for.
    • _ (list [Scope ]) — The scope to generate the handle for.
    • self (Self)
  • Returns: The generated handle.
  • Return type: str

class shipany.bot.persistency.handles.HandleGeneratorFactory

Bases: object

The factory to create the handle generator.

create(_)

Create the handle generator.

shipany.bot.persistency.scopes module

class shipany.bot.persistency.scopes.Scope

Bases: StrEnum

State scope.

It is important to note that the state is stored in the concrete scope. The scope can be chat or user, or both.

Chat scope is used to store the state for the current chat. The values stored in chat scope are available for all users in the chat. The values stored in chat scope are not available for other chats.

User scope is used to store the state for the current user. The values stored in user scope are available for the current user across all chats. The values stored in user scope are not available for other users.

Session store is used to store the state between the different steps of the conversation. They are available only for the current user and the current chat.

chat = ‘chat’

user = ‘user’

__new__(value)

Module contents