From 360eeec8df66ca0402739463ac0fdf9b5d5910f3 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Tue, 21 Feb 2023 21:27:20 -0800 Subject: update conversation flow --- bot.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/bot.py b/bot.py index d49aaa5..f9a664a 100644 --- a/bot.py +++ b/bot.py @@ -20,7 +20,8 @@ if __version_info__ < (20, 0, 0, "alpha", 1): ) from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, ReplyKeyboardMarkup, KeyboardButton -from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters, ConversationHandler, CallbackContext +from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters, \ + ConversationHandler, CallbackContext from config import BOT_TOKEN from foursquare.poi import query_poi from dbstore.dbm_store import get_loc @@ -39,9 +40,9 @@ logging.basicConfig( logger = logging.getLogger(__name__) MAIN_MENU = ReplyKeyboardMarkup([ - [KeyboardButton(text="Check-in here", request_location=True)], - # [KeyboardButton(text="/cancel")], - # [KeyboardButton(text="/setting")] + [KeyboardButton(text="Check-in here", request_location=True)], + # [KeyboardButton(text="/cancel")], + # [KeyboardButton(text="/setting")] ]) SKIP_LOCATION_SEARCH = "skip_location_search" @@ -50,6 +51,7 @@ SKIP_MENU = InlineKeyboardMarkup([ [telegram.InlineKeyboardButton("Skip", callback_data=SKIP_LOCATION_SEARCH)] ]) + # SETTING_MENU = InlineKeyboardMarkup( # [ # [InlineKeyboardButton(text="/tos")], @@ -77,9 +79,10 @@ async def checkin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: context.user_data["longitude"] = update.message.location.longitude await update.message.reply_text("Searching...", reply_markup=telegram.ReplyKeyboardRemove()) - await update.message.reply_text("You can input location search keywords or press skip", - reply_markup=SKIP_MENU) + prompt_msg = await update.message.reply_text("You can input location search keywords or press skip", + reply_markup=SKIP_MENU) + context.user_data["prompt_msg_id"] = prompt_msg.message_id return LOCATION_SEARCH @@ -110,11 +113,18 @@ async def process_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) - # reply_markup=MAIN_MENU ) - await query.message.reply_text("You can continue attaching photos, or press skip to finish", reply_markup=SKIP_MENU) + prompt_attach_photo_msg = await query.message.reply_text( + "You can continue attaching photos, or press skip to finish", reply_markup=SKIP_MENU) + context.user_data["prompt_attach_photo_msg_id"] = prompt_attach_photo_msg.message_id + return PHOTO async def location_search_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: + await context.bot.delete_message(update.effective_chat.id, context.user_data["prompt_msg_id"]) + # query = update.callback_query + # await query.message.delete() + location_search = update.effective_message.text latitude = context.user_data["latitude"] longitude = context.user_data["longitude"] @@ -265,9 +275,10 @@ async def media_group_sender(context: CallbackContext): async def photo(update: Update, context: CallbackContext): """Stores the photo and asks for a location.""" - global scheduler await update.message.reply_chat_action(telegram.constants.ChatAction.TYPING) + await context.bot.delete_message(chat_id=update.message.chat_id, message_id=context.user_data["prompt_attach_photo_msg_id"]) + status_id = context.user_data["status_id"] status_content = context.user_data["status_content"] @@ -308,9 +319,7 @@ async def photo(update: Update, context: CallbackContext): async def skip_photo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: query = update.callback_query await query.answer() - print("skip photo: ", query.data) - print(context.user_data) await query.delete_message() await query.message.reply_text( text="Done.", reply_markup=MAIN_MENU @@ -330,11 +339,12 @@ def main() -> None: LOCATION: [ MessageHandler(filters.LOCATION, checkin), ], - WAIT_LOC: [CallbackQueryHandler(process_callback)], LOCATION_SEARCH: [ MessageHandler(filters.TEXT, location_search_callback), CallbackQueryHandler(skip_location_search), ], + WAIT_LOC: [CallbackQueryHandler(process_callback)], + PHOTO: [MessageHandler(filters.PHOTO, photo), CallbackQueryHandler(skip_photo)], }, -- cgit v1.2.3