什么是InputMediaPhoto,以及如何将此类资源的数组发送到Telegram API? [英] What is InputMediaPhoto and how to send an array of such resources to Telegram API?
问题描述
我正在尝试一些用于电报Bot API的Google Apps脚本.
I'm trying some Google Apps Script script for telegram bot API.
var token = "BOT:TOKEN";
var telegramUrl = "https://api.telegram.org/bot" + token;
var chat_id = "CHAT_ID";
var image1 = "https://telegram.org/img/t_logo.png";
var image2 = "https://www.gstatic.com/images/branding/product/2x/apps_script_48dp.png";
var data = {
method: "post",
payload: {
"method": "sendMediaGroup",
"chat_id": chat_id,
"media": [
{"type": "photo", "media": image1},
{"type": "photo", "media": image2},
]
}
}
UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/', data);
}
Telegram Bot API文档说,媒体类型是 InputMediaPhoto
的数组.但是我不明白.谁能帮我一个使用sendMediaGroup方法发送照片组的 inputMediaPhoto
示例吗?
Telegram Bot API Docs said that media type is an Array of InputMediaPhoto
. But I dont understand. Could anyone help me an example of inputMediaPhoto
for sending group of photos use sendMediaGroup method?
我确实尝试了方法 sendPhoto
https://core.telegram.org/bots/api#sendphoto ,它起作用了.现在我需要发送一组照片.
I did try method sendPhoto
https://core.telegram.org/bots/api#sendphoto, it worked. Now i need to send group of photos.
推荐答案
最近,我需要使用Telegram Bot API将集体照片发送到Telegram中,但想不通,因此无法在此页面上登陆.从@Tanaike获得一些想法并通过@pyTelegramBotAPI进行调试,我已经完成了一些Python代码,这些代码会将本地文件作为集体照片发送到Telegram.因此,我只想在这里分享它,以使面临相同问题的人们受益.
Recently, I need to send group photos into Telegram using Telegram Bot API and couldn't figure out much and have land on this page. Getting some idea from @Tanaike and debug through @pyTelegramBotAPI, I have done some Python code that will send local files to Telegram as group photos. So, I just wanted to share it here to benefit people who facing the same problem.
#!/usr/bin/python
import requests
TOKEN = "random-number:random-alpha-numeric"
CHAT_ID = "-random-number"
request_url = "https://api.telegram.org/bot" + TOKEN + "/sendMediaGroup"
params = {
"chat_id": CHAT_ID
, "media":
"""[
{
"type": "photo"
, "media": "attach://random-name-1"},
{
"type": "photo"
, "media": "attach://random-name-2"}
]"""
}
files = {
"random-name-1": open("/home/pc/Desktop/watermark/data.png", "rb")
, "random-name-2": open("/home/pc/Desktop/watermark/data.png", "rb")
}
result = requests.post(request_url, params= params, files= files)
print(result.text)
这篇关于什么是InputMediaPhoto,以及如何将此类资源的数组发送到Telegram API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!