如何使用Telegram bot API发送文本图像?

发布于 2025-01-22 02:52:01 字数 445 浏览 1 评论 0原文

我正在尝试使用Telegram API机器人发送消息。

我想提出一个get请求,这同时将文本和图像发送到我的电报频道。

现在取出看起来像这样:

telegram_msg = requests.get('https://api.telegram.org/<botname>:botAPI/sendMessage?chat_id=<chat_id>=some text')

我如何包括一个位于并在一条消息中同时发送文本和图像?

感谢您的帮助。

UPD:我可以使用SendPhoto发送图像,但是如何将这两个请求组合到一个请求中?这样我可以发送图像和文字?

I'm trying to send a message to telegram using Telegram API bot.

I want to make a GET request, that will send both text and image to my telegram channel.

Now fetch looks like that:

telegram_msg = requests.get('https://api.telegram.org/<botname>:botAPI/sendMessage?chat_id=<chat_id>=some text')

How can I include an image that is located here and send both text and image in one message?

Thank you for your help.

UPD: I can send image using sendPhoto, but how can I combine these two requests into one? So that I can send both image and text?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仙女山的月亮 2025-01-29 02:52:01

使用@botfather 获得您的api token

import requests
chat_id = '<chat_id>'
token = '<token>'
msg = "Send text with photo

After using @BotFather to get your API token

import requests
chat_id = '<chat_id>'
token = '<token>'
msg = "Send text with photo ????"
img_uri = "https://www.ixbt.com/img/n1/news/2022/3/1/62342d1404eb2_large.jpg"
telegram_msg = requests.get(f'https://api.telegram.org/bot{token}/sendPhoto?chat_id={chat_id}&caption={msg}&photo={img_uri}')
print(telegram_msg)
print(telegram_msg.content)

Post result with text and image in Telegram

一桥轻雨一伞开 2025-01-29 02:52:01

telegram_msg = requests.get('https://api.telegram.org/bot<botAPI>/sendPhoto?chat_id=<chat_id>&caption=some text')

use caption parameter in sendPhoto method

telegram_msg = requests.get('https://api.telegram.org/bot<botAPI>/sendPhoto?chat_id=<chat_id>&caption=some text')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文