如何在 Azure 上部署 Python Telegram 机器人?

问题描述 投票:0回答:1

我有基于 Python 的电报机器人代码,我想将其部署在 azure 中。

from pyrogram import Client, filters

app = Client("abc_bot", api_id=api_id, api_hash=api_hash, bot_token=bot_token)

# Define a function to handle the /start command
@app.on_message(filters.command("start"))
def start_command(client, message):
    # Send "Hello" as a response to the /start command
    message.reply_text("Hello!")

# Run the bot
app.run()

我已经尝试了多种方法,但无法部署它,请引导我找到正确的方向,以便我可以在 azure 中部署 Python telegram bot 代码。我已经使用热解图库来构建我的机器人。

python azure telegram-bot pyrogram
1个回答
0
投票

我使用你的 python 代码创建了一个简单的 Telegram 聊天机器人。

  • Bot Token 设置为 环境变量:
set BOT_TOKEN= <bot_token>
import os

from pyrogram import Client, filters

BOT_TOKEN = os.getenv('BOT_TOKEN')
app = Client("kpvrhello_bot", api_id=277XXXX18, api_hash="2d85ec95c014fXXXXXXe6269d", bot_token=BOT_TOKEN)

@app.on_message(filters.command("start"))
def start_command(client, message):

    message.reply_text("Hello Pravallika, Welcome!!!")

app.run()
  • 使用 Visual Studio Code 部署到 Azure:

enter image description here

  • 转到环境变量(或配置=>常规设置),添加新的应用程序设置
    BOT_TOKEN

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.