#!/usr/bin/env python # pylint: disable=unused-argument # This program is dedicated to the public domain under the CC0 license. """ Simple Bot to reply to Telegram messages. First, a few handler functions are defined. Then, those functions are passed to the Application and registered at their respective places. Then, the bot is started and runs until we press Ctrl-C on the command line. Usage: Basic Echobot example, repeats messages. Press Ctrl-C on the command line or send a signal to the process to stop the bot. """ from translate import Translator # type: ignore import logging from telegram import ForceReply, InlineKeyboardButton, Update from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters, CallbackContext # Enable logging logging.basicConfig( format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO ) # set higher logging level for httpx to avoid all GET and POST requests being logged logging.getLogger("httpx").setLevel(logging.WARNING) logger = logging.getLogger(__name__) [KeyboardInterrupt] keyboard = [ [InlineKeyboardButton(text="9",callback_data="9")] ] # Define a few command handlers. These usually take the two arguments update and # context. async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: """Send a message when the command /start is issued.""" user = update.effective_user await update.message.reply_html( rf"Hi {user.mention_html()}!", reply_markup=ForceReply(selective=True), ) async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: """Send a message when the command /help is issued.""" await update.message.reply_text("привет я пицца бот ") # async def history_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: # await update.message.reply_text(context.chat_data.items()) async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: """Echo the user message.""" translator = Translator(to_lang="ru") context.chat_data['12021'] = update.message.text print(context.chat_data) await update.message.reply_text(translator.translate(update.message.text)) async def start(update: Update, context: CallbackContext) -> None: # translator = Translator(to_lang="ru") # context.chat_data['12021'] = update.message.text await update.message.reply_text("Текст") def main() -> None: """Start the bot .""" # Create the Application and pass it your bot's token. application = Application.builder().token("8017323089:AAGm0m8HuSvSokv5kkXD8nNMCsdYGoDZEjA").build() # on different commands - answer in Telegram application.add_handler(CommandHandler("start", start)) application.add_handler(CommandHandler("help", help_command)) # application.add_handler(CommandHandler("history", history_command)) # on non command i.e message - echo the message on Telegram application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) # Run the bot until the user presses Ctrl-C application.run_polling(allowed_updates=Update.ALL_TYPES) if __name__ == "__main__": main() [KeyboardInterrupt]