0

The flow of my bot is as it follows:

  1. /conv -> command that trigger the conversation, my bot sends a random question saved in
    my db
  2. The user inputs the answer
  3. the bot says if it's correct or not

when used in a private chat works like a charm, but when used in group chats it only reads strings that start with '/'.

Here's my code:

 import syms as _syms
    from telegram import Update
    from telegram.ext import (
      Updater,
      CommandHandler,
      MessageHandler,
      Filters,
      ConversationHandler,
      CallbackContext,
    )
    from telegram import Update
    from telegram.ext import (
      Updater,
      CommandHandler,
      MessageHandler,
      Filters,
      ConversationHandler,
      CallbackContext,
    )
EXPECT_NAME = range(1)

def question(update: Update, context: CallbackContext):
  question = random.choice(_syms.QUESTION_LIST)
  question = question.split(')')
  question_text = question[1] 
  bot = telegram.Bot(token = _syms.APY_KEY)
  from_user = update.message.from_user
  current_chat_id = update.message.chat_id
  bot.send_message(chat_id = current_chat_id, text = question_text)
  context.user_data['question_number'] = question[0]


  return EXPECT_NAME

def get_answer(update: Update, context: CallbackContext):
  bot = telegram.Bot(token = _syms.APY_KEY)
  from_user = update.message.from_user
  current_chat_id = update.message.chat_id
  full_name = from_user.full_name
  userid = from_user.id

  user_answer = update.message.text
  real_answer = _syms.ANSWERS[context.user_data['question_number']]
  if user_answer == real_answer:
    bot.send_message(chat_id = currenct_chat_id, text = 'grats' + full_name)
    return ConversationHandler.END
  else:
    bot.send_message(chat_id = currenct_chat_id, text = 'I\'m sorry wrong answer, try again')
       
 
conv_handler = ConversationHandler(
  entry_points=[CommandHandler('question', question)],
  states={
    EXPECT_NAME:[MessageHandler(Filters.text, get_answer)]
  },
  fallbacks=[CommandHandler('tip', give_tip)]
)

updater.dispatcher.add_handler(conv_handler)
updater.start_polling()
updater.idle()

The issue is that in private chat with the bot is working fine, but if I use the same comand in a group chat it only reads text input that starts with'/'.

Sorry for the bad formatting, I'm not used to use StackOverflow.

0 Answers0