), start),\n MessageHandler(filters.Regex('^Question-Answering ), pre_query_handler),\n ],\n QUESTION_STATE: [\n MessageHandler(filters.Regex('^Back ), start),\n MessageHandler(filters.TEXT, pre_query_answer_handler),\n ],\n },\n fallbacks=[],\n )\n \n application.add_handler(conv_handler)\n\n print(\"Bot is running ...\")\n application.run_polling()","lang":""}},{"type":"text","cover":false,"hidden":false,"anchor":"","data":{"text":"\u003Cp\u003EДавайте создадим функцию, которую можно будет повторно использовать:\u003C/p\u003E"}},{"type":"code","cover":false,"hidden":false,"anchor":"","data":{"text":"def _generate_copilot(prompt: str):\n \"\"\"Gets answer from copilot\"\"\"\n \n copilot = Copilot()\n c = copilot.get_answer(prompt)\n\n return c","lang":""}},{"type":"text","cover":false,"hidden":false,"anchor":"","data":{"text":"\u003Cp\u003EДобавление команды /start:\u003C/p\u003E"}},{"type":"code","cover":false,"hidden":false,"anchor":"","data":{"text":"async def start(update: Update, context: ContextTypes):\n \"\"\"Start the conversation and ask user for an option.\"\"\"\n\n button = [[KeyboardButton(text=\"Question-Answering\")]]\n reply_markup = ReplyKeyboardMarkup(\n button, resize_keyboard=True\n )\n\n await update.message.reply_text(\n \"Choose an option: 👇🏻\",\n reply_markup=reply_markup,\n )\n\n return ENTRY_STATE","lang":""}},{"type":"text","cover":false,"hidden":false,"anchor":"","data":{"text":"\u003Cp\u003EСоздайте функцию для пользовательского ввода (текста):\u003C/p\u003E"}},{"type":"code","cover":false,"hidden":false,"anchor":"","data":{"text":"#Handling the question\nasync def pre_query_handler(update: Update, context: ContextTypes):\n \"\"\"Ask the user for a query.\"\"\"\n\n button = [[KeyboardButton(text=\"Back\")]]\n reply_markup = ReplyKeyboardMarkup(\n button, resize_keyboard=True\n )\n\n await update.message.reply_text(\n \"Enter your text: 👇🏻\",\n reply_markup=reply_markup,\n )\n\n return QUESTION_STATE","lang":""}},{"type":"text","cover":false,"hidden":false,"anchor":"","data":{"text":"\u003Cp\u003EОбработка пользовательского ввода (text) и генерация текста (answer):\u003C/p\u003E"}},{"type":"code","cover":false,"hidden":false,"anchor":"","data":{"text":"#Handling the answer\nasync def pre_query_answer_handler(update: Update, context: ContextTypes):\n \"\"\"Display the answer to the user.\"\"\"\n\n button = [[KeyboardButton(text=\"Back\")]]\n reply_markup = ReplyKeyboardMarkup(\n button, resize_keyboard=True\n )\n\n question = update.message.text\n\n answer = _generate_copilot(question)\n context.user_data['answer'] = answer\n\n await update.message.reply_text(\n answer, \n reply_markup=reply_markup,\n )\n\n return QUESTION_STATE","lang":""}},{"type":"text","cover":false,"hidden":false,"anchor":"","data":{"text":"\u003Cp\u003EНа этом ваш первый Telegram-бот готов! Теперь вы можете экспериментировать с ним, добавлять ему какой-либо функционал, развивать его.\u003C/p\u003E"}},{"type":"header","cover":false,"hidden":false,"anchor":"","data":{"style":"h2","text":"Полезные ссылки"}},{"type":"list","cover":false,"hidden":false,"anchor":"","data":{"items":["Получите полный код на \u003Ca href=\"https://api.vc.ru/v2.8/redirect?to=https%3A%2F%2Fgithub.com%2Fabdibrokhim%2FUzNLP-Hackathon-Website&postId=600167\" rel=\"nofollow noreferrer noopener\" target=\"_blank\"\u003EGithub\u003C/a\u003E","\u003Ca href=\"https://api.vc.ru/v2.8/redirect?to=https%3A%2F%2Fdocs.python-telegram-bot.org%2Fen%2Fstable%2F&postId=600167\" rel=\"nofollow noreferrer noopener\" target=\"_blank\"\u003EPython Telegram Bot\u003C/a\u003E","\u003Ca href=\"https://api.vc.ru/v2.8/redirect?to=https%3A%2F%2Fopenai.com%2F&postId=600167\" rel=\"nofollow noreferrer noopener\" target=\"_blank\"\u003EOpenAI\u003C/a\u003E","\u003Ca href=\"https://api.vc.ru/v2.8/redirect?to=https%3A%2F%2Fpython.org%2F&postId=600167\" rel=\"nofollow noreferrer noopener\" target=\"_blank\"\u003EPython\u003C/a\u003E"],"type":"UL"}},{"type":"text","cover":false,"hidden":false,"anchor":"","data":{"text":"\u003Cp\u003EСтатья была взята из этого источника:\u003C/p\u003E"}},{"type":"link","cover":false,"hidden":false,"anchor":"","data":{"link":{"type":"link","data":{"url":"https://api.vc.ru/v2.8/redirect?to=https%3A%2F%2Fuproger.com%2Fsozdajte-svoego-pervogo-telegram-bota-na-baze-chatgpt%2F%3Fref%3Dvc.ru&postId=600167","title":"Создайте своего первого Telegram-бота на базе ChatGPT: Пошаговое руководство 2023","description":"Вступление Хотели бы вы создать чат-бота, который мог бы вести интеллектуальные беседы с вашими пользователями? В этом пошаговом руководстве мы покажем вам, как создать Telegram-бота, который использует ChatGPT для генерации ответов, похожих на человеческие. К концу этой статьи у вас будет пол","image":{"type":"image","data":{"uuid":"c08b6843-a55d-5378-ae43-2bcd90cdbb8c","width":270,"height":270,"size":20765,"type":"png","color":"050505","hash":"","external_service":[]}},"v":1,"hostname":"uproger.com"}}}}],"summaryContent":null,"isExistSummaryContent":false,"warningFromEditor":null,"warningFromEditorTitle":null,"counters":{"comments":22,"favorites":48,"reposts":0,"views":81,"hits":40047,"reads":null,"online":0},"dateFavorite":0,"hitsCount":40047,"isCommentsEnabled":true,"isLikesEnabled":true,"isRemovedByUserRequest":false,"isFavorited":false,"isPinned":false,"repostId":null,"repostData":null,"subscribedToTreads":false,"isEditorial":false,"isAudioAvailable":false,"audioUrl":null,"isAudioAvailableToGenerate":false,"commentEditor":{"enabled":true,"who":null,"text":"","until":null,"reason":null,"type":"everybody"},"isBlur":false,"isPublished":true,"isDisabledAd":false,"withheld":[],"ogTitle":null,"ogDescription":null,"url":"https://vc.ru/id1389654/600167-sozdaite-svoego-pervogo-telegram-bota-na-baze-chatgpt-poshagovoe-rukovodstvo-2023","author":{"id":1389654,"name":"Machine learning","nickname":null,"description":"Самая актуальная информация из мира ИТ, мл, нейронных сетей, t.me/ai_machinelearning_big_data","uri":"","avatar":{"type":"image","data":{"uuid":"a78c7151-4c19-5bca-9f1e-9857305ee8e1","width":640,"height":640,"size":32754,"type":"jpg","color":"043b54","hash":"","external_service":[]}},"cover":{"cover":{"type":"image","data":{"uuid":"a78c7151-4c19-5bca-9f1e-9857305ee8e1","width":640,"height":640,"size":32754,"type":"jpg","color":"043b54","hash":"","external_service":[]}},"cover_y":0},"achievements":[{"title":"3 года на vc.ru","code":"registration_3_years","description":"Провёл 3 года вместе с vc.ru. Получена 26 декабря 2025.","previewUuid":"d9d72ac5-bcb5-55e0-8c72-b99251e5cdd9","formats":{"glb":"https://static.vc.ru/achievements/shark.glb","usdz":"https://static.vc.ru/achievements/shark.usdz"},"viewData":{"contentColor":"#8E6F09","textMaxWidth":0.66796875,"textX":0.5205078125,"textY":0.341796875,"logoX":0.5205078125,"logoY":0.4609375,"logoXNoText":0.5,"logoYNoText":0.3662109375},"id":6335621,"userId":1389654,"count":0,"shareImage":"https://api.vc.ru/achievements/share/6335621"},{"title":"Год на vc.ru","code":"registration_1_year","description":"Первый год с vc.ru. Получена 24 июля 2025.","previewUuid":"0d11c244-49de-50e7-894e-b9b27945d42b","formats":{"glb":"https://static.vc.ru/achievements/fish.glb","usdz":"https://static.vc.ru/achievements/fish.usdz"},"viewData":{"contentColor":"#C67AA3","textMaxWidth":0.634765625,"textX":0.5888671875,"textY":0.54296875,"logoX":0.5859375,"logoY":0.6669921875,"logoXNoText":0.6044921875,"logoYNoText":0.5439453125},"id":4062297,"userId":1389654,"count":0,"shareImage":"https://api.vc.ru/achievements/share/4062297"}],"lastModificationDate":1768361225,"isSubscribed":false,"isSubscribedToNewPosts":false,"isMuted":false,"isAvailableForMessenger":true,"badgeId":null,"isDonationsEnabled":false,"isPlusGiftEnabled":true,"isUnverifiedBlogForCompanyWithoutPro":true,"isRemovedByUserRequest":false,"isFrozen":false,"isDisabledAd":false,"isPlus":false,"isVerified":false,"isPro":false,"yandexMetricaId":null,"badge":null,"isOnline":false,"tgChannelShortname":null,"isUnsubscribable":true,"type":1,"subtype":"personal_blog"},"subsite":{"id":1389654,"name":"Machine learning","nickname":null,"description":"Самая актуальная информация из мира ИТ, мл, нейронных сетей, t.me/ai_machinelearning_big_data","uri":"","avatar":{"type":"image","data":{"uuid":"a78c7151-4c19-5bca-9f1e-9857305ee8e1","width":640,"height":640,"size":32754,"type":"jpg","color":"043b54","hash":"","external_service":[]}},"cover":{"cover":{"type":"image","data":{"uuid":"a78c7151-4c19-5bca-9f1e-9857305ee8e1","width":640,"height":640,"size":32754,"type":"jpg","color":"043b54","hash":"","external_service":[]}},"cover_y":0},"achievements":[{"title":"3 года на vc.ru","code":"registration_3_years","description":"Провёл 3 года вместе с vc.ru. Получена 26 декабря 2025.","previewUuid":"d9d72ac5-bcb5-55e0-8c72-b99251e5cdd9","formats":{"glb":"https://static.vc.ru/achievements/shark.glb","usdz":"https://static.vc.ru/achievements/shark.usdz"},"viewData":{"contentColor":"#8E6F09","textMaxWidth":0.66796875,"textX":0.5205078125,"textY":0.341796875,"logoX":0.5205078125,"logoY":0.4609375,"logoXNoText":0.5,"logoYNoText":0.3662109375},"id":6335621,"userId":1389654,"count":0,"shareImage":"https://api.vc.ru/achievements/share/6335621"},{"title":"Год на vc.ru","code":"registration_1_year","description":"Первый год с vc.ru. Получена 24 июля 2025.","previewUuid":"0d11c244-49de-50e7-894e-b9b27945d42b","formats":{"glb":"https://static.vc.ru/achievements/fish.glb","usdz":"https://static.vc.ru/achievements/fish.usdz"},"viewData":{"contentColor":"#C67AA3","textMaxWidth":0.634765625,"textX":0.5888671875,"textY":0.54296875,"logoX":0.5859375,"logoY":0.6669921875,"logoXNoText":0.6044921875,"logoYNoText":0.5439453125},"id":4062297,"userId":1389654,"count":0,"shareImage":"https://api.vc.ru/achievements/share/4062297"}],"lastModificationDate":1768361225,"isSubscribed":false,"isSubscribedToNewPosts":false,"isMuted":false,"isAvailableForMessenger":true,"badgeId":null,"isDonationsEnabled":false,"isPlusGiftEnabled":true,"isUnverifiedBlogForCompanyWithoutPro":true,"isRemovedByUserRequest":false,"isFrozen":false,"isDisabledAd":false,"isPlus":false,"isVerified":false,"isPro":false,"yandexMetricaId":null,"badge":null,"isOnline":false,"tgChannelShortname":null,"isUnsubscribable":true,"type":1,"subtype":"personal_blog"},"reactions":{"counters":[{"id":1,"count":11}],"reactionId":0},"isNews":false,"source":null,"clusters":[],"donations":{"amount":0,"isDonated":false},"commentsSeenCount":null}}],"ogTitle":null,"ogDescription":null,"isAnonymized":true}};