Skip to main content

FAQ module

Project description

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

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

django-bot-faq-0.2.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

django_bot_faq-0.2.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file django-bot-faq-0.2.1.tar.gz.

File metadata

  • Download URL: django-bot-faq-0.2.1.tar.gz
  • Upload date:
  • Size: 11.9 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 django-bot-faq-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d54dfffbbd51211a8adfeb1c2a3b87b14ef1ae82326c00e6198c3cecdc79190f
MD5 b22e1f7cd16a75c8dadd354f98c6b213
BLAKE2b-256 0b6dcfe29c3376b0aac7c71b7aa561a6db6ff03220c8cdb8349add09629c462f

See more details on using hashes here.

File details

Details for the file django_bot_faq-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: django_bot_faq-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 15.1 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 django_bot_faq-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9b18d2f54fe66fb34f162a358b889f9e50ba7ff7db931785e12e3fb1f1ec09f7
MD5 08d3db64ad4233b6576b6bba6c858206
BLAKE2b-256 d882758541c19a2353e2181ebe3a6da04e2026412b0430985fab4f0123154ed2

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