In my code when the bot is triggered the function user_exist()
is triggered. If returns False, the function new_account()
is triggered and works perfectly, instead, when returns True, it should trigger the function wallet_handler()
, but it can't. The code is running in a Conversation Handler. I thought I did everything fine, but I can't figure out why the function wallet_handler()
is not triggered. Anyone can help me? This is my code:
import logging
import data
from web3 import Web3
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, ReplyKeyboardMarkup
from telegram.ext import (
Updater,
CommandHandler,
MessageHandler,
Filters,
ConversationHandler,
CallbackContext,
CallbackQueryHandler,
)
NEW_ACCOUNT, WALLET_HANDLER= range(2)
def start(update: Update, context: CallbackContext) -> int:
chatid = update.message.chat_id
if data.user_exist(chatid) == True:
print('s')
return WALLET_HANDLER
if data.user_exist(chatid) == False:
update.message.reply_text('This is your first time with us! Please insert a wallet')
return NEW_ACCOUNT
def new_account(update: Update, context: CallbackContext) -> int:
chatid = update.message.chat_id
wallet = update.message.text
if Web3.isAddress(wallet) == True:
data.new_account(chatid, wallet)
update.message.reply_text('New account succesfully created.\nWelcome to Tarsier. Enjoy it!')
return WALLET_HANDLER
else:
update.message.reply_text('Wallet Address invalid.\nPlease insert a valid Wallet Address.')
return NEW_ACCOUNT
def wallet_handler(update: Update, context: CallbackContext) -> int:
update.message.reply_text('aaa')
return ConversationHandler.END
def cancel(update: Update, context: CallbackContext) -> int:
"""Cancels and ends the conversation."""
user = update.message.from_user
update.message.reply_text(
'Bye! I hope we can talk again some day.', reply_markup=ReplyKeyboardRemove()
)
return ConversationHandler.END
def main() -> None:
"""Run the bot."""
# Create the Updater and pass it your bot's token.
updater = Updater("TOKEN")
# Get the dispatcher to register handlers
dispatcher = updater.dispatcher
# Add conversation handler with the states GENDER, PHOTO, LOCATION and BIO
conv_handler = ConversationHandler(
entry_points=[CommandHandler('start', start)],
states={
NEW_ACCOUNT: [MessageHandler(Filters.text & ~Filters.command, new_account)],
WALLET_HANDLER: [MessageHandler(Filters.text & ~Filters.command, wallet_handler)],
},
fallbacks=[CommandHandler('cancel', cancel)],
)
dispatcher.add_handler(conv_handler)
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()