From 3f2b2379fed35eacfb0e798953acecd5acf0e177 Mon Sep 17 00:00:00 2001 From: NormalParameter Date: Sat, 12 Mar 2022 19:24:25 +0100 Subject: [PATCH] Return User ID --- bot.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index 094c8fd..ce1de98 100644 --- a/bot.py +++ b/bot.py @@ -3,20 +3,43 @@ # text bot at t.me/projektaktienbot # API Documentation https://core.telegram.org/bots/api # Code examples https://github.com/eternnoir/pyTelegramBotAPI#getting-started -import os import telebot +import time +import sys +import logging +from telebot import types -bot = telebot.TeleBot(os.getenv('BOT_API_KEY')) - +bot = telebot.TeleBot("5228016873:AAGFrh0P6brag7oD3gxXjCh5gnLLE8JMvMs") @bot.message_handler(commands=['start', 'help']) def send_welcome(message): - bot.reply_to(message, "Thank you for using this bot") - + bot.reply_to(message, "Thank you for using this bot") @bot.message_handler(func=lambda message: True) def echo_all(message): - bot.reply_to(message, message.text) + answer = message.text + ' ID: ' + str(message.from_user.id) + bot.reply_to(message, answer) + +telebot.logger.setLevel(logging.DEBUG) + +@bot.inline_handler(lambda query: query.query == 'text') +def query_text(inline_query): + try: + r = types.InlineQueryResultArticle('1', 'Result1', types.InputTextMessageContent('hi')) + r2 = types.InlineQueryResultArticle('2', 'Result2', types.InputTextMessageContent('hi')) + bot.answer_inline_query(inline_query.id, [r, r2]) + except Exception as e: + print(e) + +def main_loop(): + bot.infinity_polling() + while 1: + time.sleep(3) -bot.infinity_polling() +if __name__ == '__main__': + try: + main_loop() + except KeyboardInterrupt: + print('\nExiting by user request.\n') + sys.exit(0)