我有一个关于在我运行的两个应用程序之间实现数据传递的问题。
我有一个 Flask 后端,它通过 POST 请求接收用户电子邮件并将其存储在一个变量中。我需要将此变量传递给 TelegramBotAPI。
我需要做的是,当 Flask 收到一封新的用户电子邮件时,它会将数据传递到 TelegramBotAPI 并触发一个函数,该函数会将其以消息的形式发送给用户。
我该如何实施呢?
我有一个关于在我运行的两个应用程序之间实现数据传递的问题。
我有一个 Flask 后端,它通过 POST 请求接收用户电子邮件并将其存储在一个变量中。我需要将此变量传递给 TelegramBotAPI。
我需要做的是,当 Flask 收到一封新的用户电子邮件时,它会将数据传递到 TelegramBotAPI 并触发一个函数,该函数会将其以消息的形式发送给用户。
我该如何实施呢?
Assuming your architecture separates the TelegramBot from the Flask server, you would treat your flask server as the client
for your Telegram Bot which is the server
in this scenario.
Armed with this information there are numerous ways to go about this. TelegramBot could provide an http server
through which clients could send requests. Another option which requires less availability from the Bot but ensures eventual consistency
is using a message broker
like RabbitMQ.
Lastly, if you wish to store the email permanently you should consider using a storage like a Database (for robustness) or a File system (if you have only one server)