var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/javascript");
var data = {
chat_id: 11111,
media: [
{
type: "photo",
media: "https://picsum.photos/200",
caption: "It's picture",
},
{
type: "photo",
media: "https://picsum.photos/200",
},
],
};
var requestOptions = {
method: "POST",
headers: myHeaders,
body: data,
redirect: "follow",
};
fetch(
`https://api.telegram.org/${botToken}/sendMediaGroup`,
requestOptions
)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));
},
let media = []
files.forEach(file => {
media.push({
type: "photo",
caption: formText,
media: `http://site.ru/files/${user}/${file.name}`
})
})
config = {
method: 'post',
url: `https://api.telegram.org/${botToken}/sendMediaGroup?chat_id=${chatId}`,
data: {media}
}
axios(config)
.then(function (response) {
res.status(200).json({message: response.data})
})
.catch(function (error) {
res.status(400).json({message: error})
})
TOKEN = "1234646854fdghdfhfghfghssfhhgh"
def send_group_img(chat_id, text):
temp_files_list = list()
media = list()
files = dict()
for filename in os.listdir("temp"):
temp_files_list.append(f'{os.getcwd()}\\temp\\{filename}')
for f in enumerate(temp_files_list):
files[f"random-name-{f[0]}"] = open(f[1], "rb")
if f[0] == 0:
media.append({"type": "photo",
"media": f"attach://random-name-{f[0]}",
"caption": text}
)
else:
media.append({"type": "photo",
"media": f"attach://random-name-{f[0]}"})
params = {
"chat_id": chat_id, "media": str(media).replace("'", '"')}
request_url = "https://api.telegram.org/bot" + TOKEN + "/sendMediaGroup"
result = requests.post(request_url, params=params, files=files)
if result.status_code == 200:
return True
else:
return False
var media = JSON.stringify([{
"type": "photo",
"media": "https://site.ru/uploads/image1.jpg",
"caption": "Текст к группе фотографий"
}, {
"type": "photo",
"media": "https://site.ru/uploads/image2.jpg"
}, {
"type": "photo",
"media": "https://site.ru/uploads/image3.png"
}]);
jQuery.ajax({
type: "POST",
url: "https://api.telegram.org/bot" + token + "/sendMediaGroup?chat_id=" + chatid,
data: "media=" + media,
});