Skip to content

Commit a01bd41

Browse files
committed
Fix examples
1 parent 02487e2 commit a01bd41

17 files changed

Lines changed: 139 additions & 31 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ add_library(TgBot
2020
src/Bot.cpp
2121
src/EventBroadcaster.cpp
2222
src/EventHandler.cpp
23+
src/HttpClient.cpp
2324
src/TgException.cpp
2425
src/CurlHttpClient.cpp
2526
src/TgLongPoll.cpp

examples/echobot-proxy/src/main.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// Example of using an array of proxies with tgbot-cpp.
2-
// Based on original code (c) Oleg Morozenkov [reo7sp] https://github.com/reo7sp
3-
// https://github.com/reo7sp/tgbot-cpp/blob/master/examples/echobot/src/main.cpp
4-
51
#include <array>
62
#include <cstdlib>
73
#include <exception>
@@ -24,7 +20,6 @@ int main() {
2420
std::size_t proxyIndex = 0;
2521

2622
const auto token = std::string(std::getenv("TOKEN"));
27-
std::cout << "Token: " << token << std::endl;
2823

2924
TgBot::CurlHttpClient curlHttpClient;
3025
TgBot::Bot bot(token, curlHttpClient);

examples/echobot-setmycommands/src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
int main() {
1111
const auto token = std::string(std::getenv("TOKEN"));
12-
std::cout << "Token: " << token << std::endl;
1312

1413
TgBot::Bot bot(token);
1514

examples/echobot-submodule/src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
int main() {
1010
const auto token = std::string(std::getenv("TOKEN"));
11-
std::cout << "Token: " << token << std::endl;
1211

1312
TgBot::Bot bot(token);
1413
bot.getEvents().onCommand("start", [&bot](std::shared_ptr<TgBot::Message> message) {

examples/echobot-webhook-server/src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
int main() {
1010
const auto token = std::string(std::getenv("TOKEN"));
11-
std::cout << "Token: " << token << std::endl;
1211
const auto webhookUrl = std::string(std::getenv("WEBHOOK_URL"));
1312
std::cout << "Webhook URL: " << webhookUrl << std::endl;
1413

examples/echobot/src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
int main() {
1010
const auto token = std::string(std::getenv("TOKEN"));
11-
std::cout << "Token: " << token << std::endl;
1211

1312
TgBot::Bot bot(token);
1413
bot.getEvents().onCommand("start", [&bot](std::shared_ptr<TgBot::Message> message) {

examples/inline-keyboard/src/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99

1010
int main() {
1111
const auto token = std::string(std::getenv("TOKEN"));
12-
std::cout << "Token: " << token << std::endl;
1312

1413
TgBot::Bot bot(token);
1514

16-
// Thanks Pietro Falessi for code
1715
auto keyboard = std::make_shared<TgBot::InlineKeyboardMarkup>();
1816
std::vector<std::shared_ptr<TgBot::InlineKeyboardButton>> row0;
1917
auto checkButton = std::make_shared<TgBot::InlineKeyboardButton>();

examples/photo/src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
int main() {
1010
const auto token = std::string(std::getenv("TOKEN"));
11-
std::cout << "Token: " << token << std::endl;
1211

1312
const auto photoFilePath = std::string("example.jpg");
1413
const auto photoMimeType = std::string("image/jpeg");

examples/receive-file/src/main.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
int main() {
1010
const auto token = std::string(std::getenv("TOKEN"));
11-
std::cout << "Token: " << token << std::endl;
1211

1312
TgBot::Bot bot(token);
1413
bot.getEvents().onCommand("start", [&bot](std::shared_ptr<TgBot::Message> message) {
@@ -22,9 +21,19 @@ int main() {
2221
return;
2322
}
2423

24+
if (!message->document) {
25+
bot.getApi().sendMessage(message->chat->id, "Please send a file.");
26+
return;
27+
}
28+
2529
const auto file = bot.getApi().getFile(message->document->fileId);
2630
const auto fileContent = bot.getApi().downloadFile(file->filePath.value_or(""));
2731

32+
if (fileContent.size() > 4000) {
33+
bot.getApi().sendMessage(message->chat->id, "The file is too large to send as a message.");
34+
return;
35+
}
36+
2837
bot.getApi().sendMessage(message->chat->id, "Your file content: " + fileContent);
2938
});
3039

examples/received-text-processing/src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const std::vector<std::string> botCommands { "start", "test" };
1111

1212
int main() {
1313
const auto token = std::string(std::getenv("TOKEN"));
14-
std::cout << "Token: " << token << std::endl;
1514

1615
bool isWaitingForText = false;
1716

0 commit comments

Comments
 (0)