From 3a230798be1bc63b363cf75b8b1cae3a508cca84 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Mon, 20 Feb 2023 01:55:20 -0800 Subject: 4sq: add query poi example --- bot.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'bot.py') diff --git a/bot.py b/bot.py index 517f810..e010516 100644 --- a/bot.py +++ b/bot.py @@ -22,7 +22,11 @@ if __version_info__ < (20, 0, 0, "alpha", 1): f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html" ) from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update -from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes +from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters + +from config import BOT_TOKEN +from foursquare.query_poi import query_poi + # Enable logging logging.basicConfig( @@ -46,6 +50,13 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: await update.message.reply_text("Please choose:", reply_markup=reply_markup) +async def checkin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + print(update.message.location.latitude) + print(update.message.location.longitude) + poi = query_poi(update.message.location.latitude, update.message.location.longitude) + await update.message.reply_text("Your location received: {}".format(poi)) + + async def button(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: """Parses the CallbackQuery and updates the message text.""" query = update.callback_query @@ -65,10 +76,13 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No def main() -> None: """Run the bot.""" # Create the Application and pass it your bot's token. - application = Application.builder().token("TOKEN").build() + application = Application.builder().token(BOT_TOKEN).build() application.add_handler(CommandHandler("start", start)) + application.add_handler(CommandHandler("checkin", checkin)) application.add_handler(CallbackQueryHandler(button)) + # on non command i.e message - echo the message on Telegram + application.add_handler(MessageHandler(filters.LOCATION & ~filters.COMMAND, checkin)) application.add_handler(CommandHandler("help", help_command)) # Run the bot until the user presses Ctrl-C -- cgit v1.2.3