Added examples of sending photos

This commit is contained in:
Kirill Kirilenko 2016-11-13 00:52:27 +04:00 committed by GitHub
parent b56eb9e71b
commit 7599c99113

View file

@ -45,7 +45,7 @@ Message answer = bot.sendMessage(ChatId{"@chat_name"},
ReplyTo{messageId}, ReplyTo{messageId},
ParseMode::Markdown, ParseMode::Markdown,
DisableNotification(), DisableNotification(),
DisableWebPagePreview() DisableWebPagePreview()
); );
``` ```
Note, that ```ChatId``` argument can be specified with its name or id: Note, that ```ChatId``` argument can be specified with its name or id:
@ -53,3 +53,38 @@ Note, that ```ChatId``` argument can be specified with its name or id:
ChatId{"@chat_name"} ChatId{"@chat_name"}
ChatId{123456} ChatId{123456}
``` ```
### Sending images
To send a photo use any of the folowing variants depending of image source:
```cpp
// for local file
Message answer = bot.sendPhoto(ChatId{"@chat_name"}, Photo{File{"photo.jpg"}});
// for in-memory image stored in std::vector
std::vector<char> photo = ...;
Message answer = bot.sendPhoto(ChatId{"@chat_name"},
Photo{Buffer{photo, "photo.jpg"}}
);
// for in-memory image stored in C-array
Message answer = bot.sendPhoto(ChatId{"@chat_name"},
Photo{Buffer{photo.data(), photo.size(), "photo.jpg"}}
);
// for image available by URL
Message answer = bot.sendPhoto(ChatId{"@chat_name"},
Photo{Url{"http://sample.com/sample.jpg"}}
);
// for already uploaded photo you can send it by id
Message answer = bot.sendPhoto(ChatId{"@chat_name"}, Photo{123456});
```
As in the case of messages, you can pass additional options:
```cpp
Message answer = bot.sendPhoto(ChatId{"@chat_name"},
Photo{File{"photo.jpg"}}
Caption{"Sample photo"},
ReplyTo(messageId),
DisableNotification()
);
```