Photo and Sticker Messages
You can provide the source file for almost all multimedia messages (e.g. photo, video) in 3 ways:
- Uploading a file with the HTTP request
- HTTP URL for Telegram to get a file from the internet
file_id
of an existing file on Telegram servers (recommended)
Examples in this section show all three. You will learn more about them later on when we discuss file upload and download.
Photo
Sending a photo is simple. Here is an example:
var message = await bot.SendPhoto(chatId, "https://telegrambots.github.io/book/docs/photo-ara.jpg",
"<b>Ara bird</b>. <i>Source</i>: <a href=\"https://pixabay.com\">Pixabay</a>", ParseMode.Html);
Caption
Multimedia messages can optionally have a caption attached to them. Here we sent a caption in HTML format. A user can click on Pixabay in the caption to open its URL in the browser.
Similar to message entities discussed before, caption entities on Message
object are the result of
parsing formatted(Markdown or HTML) caption text.
Try inspecting these properties in debug mode:
message.Caption
: caption in plain text without formattingmessage.CaptionEntities
: info about special entities in the captionmessage.CaptionEntityValues
: text values of mentioned entities
Photo Message
The message
returned from this method represents a photo message because message.Photo
has a value.
Its value is a PhotoSize
array with each element representing the same photo in different dimensions.
If your bot needs to send this photo again at some point, it is recommended to store this array
so you can reuse the file_id
value.
Here is how message.Photo
array looks like in JSON:
[
{
"file_id": "AgADBAADDqgxG-QDDVCm5JVvld7MN0z6kBkABCQawlb-dBXqBZUEAAEC",
"file_size": 1254,
"width": 90,
"height": 60
},
{
"file_id": "AgADBAADDqgxG-QDDVCm5JVvld7MN0z6kBkABAKByRnc22RmBpUEAAEC",
"file_size": 16419,
"width": 320,
"height": 213
},
{
"file_id": "AgADBAADDqgxG-QDDVCm5JVvld7MN0z6kBkABHezqGiNOz9yB5UEAAEC",
"file_size": 57865,
"width": 640,
"height": 426
}
]
Sticker
Telegram stickers are fun and our bot is about to send its very first sticker. Sticker files should be in WebP format.
This code sends the same sticker twice. First by passing HTTP URL to a WebP sticker file and
second by reusing FileId
of the same sticker on Telegram servers.
var message1 = await bot.SendSticker(chatId, "https://telegrambots.github.io/book/docs/sticker-fred.webp");
var message2 = await bot.SendSticker(chatId, message1.Sticker!.FileId);
Try inspecting the sticker1.Sticker
property. It is of type Sticker
and its schema looks similar to a photo.
There is more to stickers and we will talk about them in greater details later.