Skip to main content

Storage for bots that allows you to save the states and data of users.

Project description

bot-storage

Storage - an object that allows you to save the states and data of users.
The storage.py file describes the abstract class BaseStorage, inheriting from which, you can implement your own storage (eg DBStorage or JSONStorage).
Such storages, however, will obviously not be more efficient than the already implemented RedisStorage.

Installation:

pip install bot-storage

Setting up

YourProject/tbot/storage.py

from os import getenv

from bot_storage.storage import RedisStorage


storage = RedisStorage(
    host=getenv('REDIS_HOST', 'localhost'),
    username=getenv('REDIS_USER', None),
    password=getenv('REDIS_PASSWORD', None)
)

YourProject/settings.py

from tbot.storage import storage


# Your storage for user states & data
BOT_STORAGE = storage

Start Redis

redis-server

Usage

For example YourProject/tbot/handlers.py

from telebot import types
from telebot.apihelper import ApiTelegramException
from tbot_base.bot import tbot

from .storage import storage as st


@tbot.message_handler(
    func=lambda msg: st.get_user_state(msg.from_user.id) == 'some_state#'
)
def send_faq_search(msg: types.Message):
    tbot.send_message(chat_id=msg.from_user.id, text='Hello!')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bot-storage-1.0.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

bot_storage-1.0.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file bot-storage-1.0.1.tar.gz.

File metadata

  • Download URL: bot-storage-1.0.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for bot-storage-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9eab0a36a4e7903822133567d3b2ae7b4a789c551773d45cc2977739e4cd2aac
MD5 e52993db6187dc8fe3cb8bd71f8c657d
BLAKE2b-256 e66cfac7d50ab227fa45e6ee4d4739342b1613273d56ed1bd62f182412897f7d

See more details on using hashes here.

File details

Details for the file bot_storage-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: bot_storage-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for bot_storage-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cadf76d22cd341bb1b23e8f4df9b3bc5bdbe715b9e3f4420a8dd7cf55480912c
MD5 e6b777c914805138dba9ce80086bd286
BLAKE2b-256 e7d67e7c9af87017e9141ebca88124848ea18ef6a541566dd1f5acd8c252f138

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page