如何使用带Flask的Telethon?

2024-04-19 02:07:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个功能齐全的telethon应用程序,在控制台上运行得很好。 但我想将其转换为web版本并添加更多功能。 但我是新来的。 问题是:

from flask import Flask, render_template, Response
import asyncio
from telethon import TelegramClient
from telethon.tl.functions.messages import GetHistoryRequest
from telethon.utils import get_input_peer

app = Flask(__name__)
api_id = "xxxxx"
api_hash = "xxxxxxxxxxxxxx"
app_short_name = "xxxxxxxxxxxxxxxxxxxx"
client = TelegramClient(app_short_name, api_id, api_hash)

@app.route("/")
def index():
    async def main():
        me = await client.get_me()
        return(me.stringify())
    with client:
        client.loop.run_until_complete(main())
if __name__ == '__main__':
    app.run(debug = True)

这是到目前为止我的代码

我的问题是,此代码在Console视图中显示类似“输入您的电话号码”的消息。 但我不知道在flask上该怎么做,我希望能够在输入中输入我的号码,或者使用get请求发送它,比如/phone/123213,然后它发送代码,我希望能够输入验证代码

在控制台上很容易,但我被flusk卡住了。 有人能帮我吗


Tags: 代码namefromimportclientapiidapp