i there i'am doing a medical chatbot project using telegram bot api and Apimedic Api when i
/start
first bot reply(which asks for language selection) works fine after that it as to return to ask Gender after that Age and so on
def start(bot, update):
reply_keyboard = [["English", "हिंदी"], ["मराठी", "বাংলা"]]
lang_pick = "Please select your language.\nअपना भाषा चुनें।\nकृपया तुमची भाषा निवडा\nআপনার ভাষা নির্বাচন করুন"
update.message.reply_text(lang_pick,
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
return LANGUAGE
def language(bot, update, user_data):
reply_keyboard = [['Male', 'Female'], ['Other']]
user = update.message.from_user
text = update.message.text
user_data["lang"] = lang_map[text]
welcome_text = "Hi {}! I will help you with your medical conditions.\nSend /cancel to stop talking to me.\n\nPlease select your Gender.".format(user.first_name)
update.message.reply_text(translate_from_english(welcome_text, user_data["lang"]),
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
return GENDER
def gender(bot, update, user_data):
user = update.message.from_user
text = update.message.text
user_data["gender"] = text
logger.info("Gender of %s: %s", user.first_name, update.message.text)
reply = 'I see! Please tell me about your Age, so I can detect disease easily.'
update.message.reply_text(translate_from_english(reply, user_data["lang"]), reply_markup=ReplyKeyboardRemove())
return AGE
but instead it shows this error.
Starting..!
2021-02-10 07:47:08,728 - __main__ - INFO - Waking Up Bot.
2021-02-10 07:47:08,730 - __main__ - INFO - Bot is polling for sessions.
2021-02-10 07:47:55,224 - telegram.ext.dispatcher - WARNING - A TelegramError was raised while processing the Update
2021-02-10 07:47:55,225 - __main__ - WARNING - Update "{'update_id': 472297741,
'message': {'message_id': 3, 'date': 1612923477, 'chat': {'id': 1680986729, 'typ
e': 'private', 'first_name': 'Gopi'}, 'text': 'English', 'entities': [], 'captio
n_entities': [], 'photo': [], 'new_chat_members': [], 'new_chat_photo': [], 'del
ete_chat_photo': False, 'group_chat_created': False, 'supergroup_chat_created':
False, 'channel_chat_created': False, 'from': {'id': 1680986729, 'first_name': '
Gopi', 'is_bot': False, 'language_code': 'en'}}, '_effective_user': {'id': 16809
86729, 'first_name': 'Gopi', 'is_bot': False, 'language_code': 'en'}, '_effectiv
e_chat': {'id': 1680986729, 'type': 'private', 'first_name': 'Gopi'}, '_effectiv
e_message': {'message_id': 3, 'date': 1612923477, 'chat': {'id': 1680986729, 'ty
pe': 'private', 'first_name': 'Gopi'}, 'text': 'English', 'entities': [], 'capti
on_entities': [], 'photo': [], 'new_chat_members': [], 'new_chat_photo': [], 'de
lete_chat_photo': False, 'group_chat_created': False, 'supergroup_chat_created':
False, 'channel_chat_created': False, 'from': {'id': 1680986729, 'first_name':
'Gopi', 'is_bot': False, 'language_code': 'en'}}}" caused error "Message text is empty"
i'am using python-telegram-bot 11.0.0 which is suitable for my python code. here is that code sample
from telegram import (ReplyKeyboardMarkup, ReplyKeyboardRemove)
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, RegexHandler,
ConversationHandler)
this is my handler the token is just example not actual
def main():
# Create the EventHandler and pass it your bot's token.
print('Starting..!')
logger.info("Waking Up Bot.")
updater = Updater("2483457814:AAHrlCx234_VskzWEJdWjTsdfuwejHyu5mI")
# Get the dispatcher to register handlers
dp = updater.dispatcher
# Add conversation handler with the states GENDER, PHOTO, LOCATION and BIO
conv_handler = ConversationHandler(
entry_points=[CommandHandler('start', start)],
states={
LANGUAGE: [RegexHandler('^(English)$', language, pass_user_data=True)],
GENDER: [RegexHandler('^(Male|Female|Other)$', gender, pass_user_data=True)],
AGE: [RegexHandler('^[1-9][0-9]{0,1}$', age, pass_user_data=True),
CommandHandler('skip', skip_age, pass_user_data=True)],
LOCATION: [MessageHandler(Filters.location, location, pass_user_data=True),
CommandHandler('skip', skip_location, pass_user_data=True)],
BIO: [MessageHandler(Filters.text, bio, pass_user_data=True)]
},
fallbacks=[CommandHandler('cancel', cancel)]
)
dp.add_handler(conv_handler)
# log all errors
dp.add_error_handler(error)
# Start the Bot
logger.info("Bot is polling for sessions.")
updater.start_polling()
updater.idle()