Added Usage section

This commit is contained in:
Kirill Kirilenko 2016-11-12 03:13:22 +04:00 committed by GitHub
parent 0315344af0
commit b56eb9e71b

View file

@ -17,3 +17,39 @@ git submodule update --init --recursive
./configure
make
```
## Usage
### Sending text message
Here is a simple example of how to send text message:
```cpp
#include <telebotxx/BotApi.hpp>
std::string token = "YOUR:BOT:TOKEN";
int main()
{
using namespace telebotxx;
BotApi bot(token);
Message answer = bot.sendMessage(ChatId{"@chat_name"},
Text{"Hello, world!"}
);
return 0;
}
```
Member function ```BotApi::sendMessage()``` returns information about sent message on success or throws an exception.
You can pass additional options in any combination and order:
```cpp
int messageId = ...; // ID of the original message to reply
Message answer = bot.sendMessage(ChatId{"@chat_name"},
Text{"Hello, world!"},
ReplyTo{messageId},
ParseMode::Markdown,
DisableNotification(),
DisableWebPagePreview()
);
```
Note, that ```ChatId``` argument can be specified with its name or id:
```cpp
ChatId{"@chat_name"}
ChatId{123456}
```