Reputation: 8586
I have a bot in Python that prompts the user to pick from a list of IDs to change and the idea is that the user will select the ID and then supply the ID they want to change to.
Here is my code:
def build_menu(buttons, n_cols):
menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)]
return menu
def change_process(bot, update):
global action
query = update.callback_query
NAME = query.data
if action == 'Change':
# Prompt user for new value
# run sql query to update
def change(bot, update, args):
global action
action = 'Change'
sql = sqlite3.connect('SQL_FILE.db',detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cur = sql.cursor()
button_list = [InlineKeyboardButton(s[0], callback_data=s[0]) for s in cur.execute('SELECT Name FROM ID ORDER BY Name ASC')]
reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=3))
update.message.reply_text('ID to change:', reply_markup=reply_markup)
action = None
updater = Updater(token='XXXX:XXXX')
dispatcher = updater.dispatcher
dispatcher.add_handler(CallbackQueryHandler(change_process))
arg_handler = CommandHandler('change', change, pass_args=True)
dispatcher.add_handler(arg_handler)
Here is how I want the program to work:
User runs /change
Bot returns list of IDs that are able to be changed (using InlineKeyboardMarkup()
and build_menu()
User picks one of the ids
Bot prompts user for new value
The next message that the user sends to the bot will be the value to use
Bot will use the ID the user selected as well as new value and run query to update in database
Bot comments that it updated ID with new value of 'USER VALUE'
The problem I am having is that I can prompt the user to pick the ID and I can prompt the user for input, but I do not know how to do both and use both values in a single function.
Upvotes: 3
Views: 1818
Reputation: 6355
I believe you need to look to conversation examples that python-telegram-bot
library provides:
There are also diagrams that explains the flow of asking data from user.
Upvotes: 1