Skip to main content

django-bot-faq

FAQ module

Installation:

pip install django-bot-faq

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

# import your storage
from tbot.storage import storage

# Define your storage for user states & data
BOT_STORAGE = storage


# Add this application definition to INSTALLED_APPS
INSTALLED_APPS = [
    'mptt',
    'django_cleanup',
    'faq.faq_admin',
    'django.contrib.postgres',
    ...
]


# Specify the ELASTICSEARCH host if you want use ElasticSearch, otherwise 
# the search will be done by default using PostgreSQL TrigramSimilarity
ELASTICSEARCH = getenv('ELASTIC_DB', 'http://localhost:9200')

Install and run Redis

More information about installing and running Redis on your system on this page.

Install and run ElasticSearch

More information about installing and running ElasticSearch on your system on this page.

Create and apply migrations

python manage.py makemigrations faq_admin tbot_base
python manage.py migrate

Usage

Handlers

YourProject/tbot/handlers.py

from telebot import types
from telebot.apihelper import ApiTelegramException

from tbot_base.bot import tbot  # install faq_tbot-base lib or make your own faq_tbot instance
from faq.faq_tbot.dispatcher import FAQDispatcher

from .storage import storage as st  # your storage for users data

dp = FAQDispatcher(tbot=tbot, storage=st)


@tbot.message_handler(func=lambda msg: msg.text in (dp.FAQ_BTN.text, '/start'))
def send_faq(msg: types.Message):
    dp.send_faq(user_id=msg.from_user.id)


@tbot.message_handler(
    func=lambda msg: st.get_user_state(msg.from_user.id) == 'faq_search#'
)
def send_faq_search(msg: types.Message):
    dp.send_faq_search(user_id=msg.from_user.id, text=msg.text)


@tbot.callback_query_handler(func=lambda call: True)
def callback_inline(call: types.CallbackQuery):
    key, article_id = call.data.split('#')

    if key == 'tree_article':
        dp.send_faq(user_id=call.from_user.id, article_id=article_id)

    elif key == 'show_article':
        dp.send_article(user_id=call.from_user.id, article_id=article_id)

    elif key == 'faq_search':
        dp.send_faq_search(user_id=call.from_user.id)

    # remove the "clock" on the inline button
    try:
        tbot.answer_callback_query(callback_query_id=call.id, text='')
    except ApiTelegramException:
        pass

Release files for django-bot-faq 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-bot-faq 0.2.1
File Size Uploaded
django-bot-faq-0.2.1.tar.gz 11.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-bot-faq 0.2.1
File Interpreter ABI Platform
django_bot_faq-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.0 kB

Release files / django-bot-faq-0.2.1.tar.gz

Download URL django-bot-faq-0.2.1.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d54dfffbbd51211a8adfeb1c2a3b87b14ef1ae82326c00e6198c3cecdc79190f
BLAKE2b-256 checksum
How to use checksums
0b6dcfe29c3376b0aac7c71b7aa561a6db6ff03220c8cdb8349add09629c462f
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / django_bot_faq-0.2.1-py3-none-any.whl

Download URL django_bot_faq-0.2.1-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b18d2f54fe66fb34f162a358b889f9e50ba7ff7db931785e12e3fb1f1ec09f7
BLAKE2b-256 checksum
How to use checksums
d882758541c19a2353e2181ebe3a6da04e2026412b0430985fab4f0123154ed2
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page