The whole function should instruct the user after executing the support command, then accept the text from the user and send it to the Chat (SUP_CHAT_ID) and give an answer that his message has been sent.
Before creating this entire file, the bot worked correctly. Now this error is falling. What could this be related to? Where did you make a mistake ?
from telegram import Update
from telegram.constants import ParseMode
from telegram.ext import ConversationHandler, CommandHandler, ContextTypes, MessageHandler, filters
from core.helpers.text import Message
from lawyer_bot import settings
from django.conf import settings
COLLECT_MESSAGE = 1
async def support_handler(update: Update, _) -> int:
text_message = await Message('support_message').agenerate()
await update.effective_chat.send_message(
text=text_message,
parse_mode=ParseMode.HTML,
)
return COLLECT_MESSAGE
support_command = CommandHandler('support', support_handler)
async def support_text(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Log the error and send a telegram message to notify the developer."""
if settings.SUP_CHAT_ID:
await context.bot.send_message(
chat_id=settings.SUP_CHAT_ID, text=update.message.text, parse_mode=ParseMode.HTML
)
text_user = await context.bot.send_message('support_collected_message').agenerate()
await update.effective_chat.send_message(
text=text_user,
parse_mode=ParseMode.HTML,
)
# TODO implement stop creation
async def stop(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
"""Stop process."""
return ConversationHandler.END
create_support = ConversationHandler(
entry_points=[
CommandHandler('support', support_handler)
],
states={
COLLECT_MESSAGE: [
MessageHandler(filters.TEXT & ~filters.COMMAND, support_text)
],
},
allow_reentry=True,
fallbacks=[
CommandHandler('stop', stop)
],
)
After starting python manage.py tg_polling the following error occurs
File "C:UsersUserAppDataLocalProgramsPythonPython38libsite-packagestelegramext_application.py", line 1162, in add_handler
raise TypeError(f"handler is not an instance of {BaseHandler.__name__}")
TypeError: handler is not an instance of BaseHandler`
I was looking for information at the docks.
I want the bot to start and function
The whole function should instruct the user after executing the support command, then accept the text from the user and send it to the Chat (SUP_CHAT_ID) and give an answer that his message has been sent.