Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a00c23f
Upgraded libcpr from v1.11.3 to v1.14.1
baderouaich Nov 29, 2025
464a55c
Update lib version from v1.1.9.2 to v1.2.9.2
baderouaich Nov 29, 2025
5c25016
Updated object ChatMemberUpdated
baderouaich Nov 29, 2025
9289af8
Mark Bot example classes final
baderouaich Nov 29, 2025
fbc770a
Stop getUpdates longpolling on Bot::stop
Dec 16, 2025
79465f8
Merge pull request #7 from 6d61676f/main
baderouaich Dec 16, 2025
b2f8b8a
Added `ErrorCode::REQUEST_CANCELLED` for detecting long polling cance…
baderouaich Dec 16, 2025
653b93b
Merge branch 'v1.2.9.2_dev' of github.com:baderouaich/tgbotxx into v1…
baderouaich Dec 19, 2025
61cec44
Rename cancellationParam flag
baderouaich Dec 19, 2025
bb2c6d2
Remove std::exit() from examples
baderouaich Dec 19, 2025
9bc0a43
Allow users to specify api long polling updates limit
baderouaich Dec 20, 2025
2b2f45b
Added long polling cancellation unit tests
baderouaich Dec 20, 2025
87900ac
Fix MaybeInaccessibleMessage invalid variant index
baderouaich Dec 30, 2025
fb19eab
Using std::monostate for optional variants
baderouaich Dec 30, 2025
c0b51f7
Improved object deserialization hierarchy
baderouaich Dec 30, 2025
75d65a2
Improved StringUtils::join()
baderouaich Dec 30, 2025
9810107
Update InputPaidMedia.hpp
baderouaich Dec 30, 2025
b7edab9
Fix objects default constructor
baderouaich Dec 30, 2025
1da394e
Fix build
baderouaich Dec 30, 2025
f0b4520
Avoid cache refresh at startup
baderouaich Dec 30, 2025
7b7fa18
Remove unnecessary BotCommandScopeDefault request param
baderouaich Dec 30, 2025
c48f548
Improve cache and command handling
baderouaich Dec 31, 2025
24380f0
Expose tgbotxx version macros to user
baderouaich Dec 31, 2025
f78521b
Update cpr options
baderouaich Dec 31, 2025
2996d28
Fix build on Windows
baderouaich Jan 3, 2026
4df3ef3
Fix build on Windows 2/2
baderouaich Jan 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.20)
project(tgbotxx VERSION "1.1.9.2" DESCRIPTION "Telegram Bot C++ Library" LANGUAGES C CXX)
project(tgbotxx VERSION "1.2.9.2" DESCRIPTION "Telegram Bot C++ Library" LANGUAGES C CXX)
# Note: tgbotxx version's patch & build is based on Telegram Bot Api version for compatibility. See https://core.telegram.org/bots/api-changelog
# <OurMajorVersion>.<OurMinorVersion>.<TelegramBotApiMajorVersion>.<TelegramBotApiMinorVersion>

Expand All @@ -12,9 +12,10 @@ option(BUILD_SHARED_LIBS "Build tgbotxx as a shared/static library." OFF)

################## Libraries ##########################
## libcpr curl
set(USE_LIBIDN2 OFF CACHE BOOL "Curl option - Use libidn2 for IDN support" FORCE)
set(CURL_USE_LIBPSL OFF CACHE BOOL "Curl option - Use libpsl" FORCE)
set(BUILD_CURL_EXE OFF CACHE BOOL "Curl option - Build curl executable" FORCE)
#set(USE_LIBIDN2 OFF CACHE BOOL "Curl option - Use libidn2 for IDN support" FORCE)
#set(CURL_USE_LIBPSL OFF CACHE BOOL "Curl option - Use libpsl" FORCE)
#set(BUILD_CURL_EXE OFF CACHE BOOL "Curl option - Build curl executable" FORCE)
set(CPR_CURL_USE_LIBPSL OFF CACHE BOOL "Since curl 8.13 curl depends on libpsl (https://everything.curl.dev/build/deps.html#libpsl). By default cpr keeps this as a secure default enabled wich in turn requires meson as build dependency. If set to OFF, psl support inside curl will be disabled." FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/cpr)
######################################################

Expand All @@ -31,9 +32,15 @@ target_include_directories(${PROJECT_NAME}
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/json/include> # nlohmann json (single include)
${CPR_INCLUDE_DIRS} # libcpr includes
)
)
target_link_libraries(${PROJECT_NAME} PUBLIC ${CPR_LIBRARIES})
add_compile_definitions(TGBOTXX_VERSION="${PROJECT_VERSION}")
target_compile_definitions(${PROJECT_NAME} PUBLIC
TGBOTXX_VERSION="${PROJECT_VERSION}"
TGBOTXX_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
TGBOTXX_VERSION_MINOR=${PROJECT_VERSION_MINOR}
TGBOTXX_VERSION_PATCH=${PROJECT_VERSION_PATCH}
TGBOTXX_VERSION_TWEAK=${PROJECT_VERSION_TWEAK}
)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic -Wno-unused-function -Wno-unused-parameter)
elseif (MSVC)
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Telegram Bot C++ Library
#include <iostream>
using namespace tgbotxx;

class MyBot : public Bot {
class MyBot final : public Bot {
public:
MyBot() : Bot("Bot token here from @BotFather") {}

Expand All @@ -80,8 +80,7 @@ private:
// Called when Bot receives a new message of any kind
// NB: Ptr<T> = std::shared_ptr<T>
void onAnyMessage(const Ptr<Message>& message) override {
std::string reply = "Hi " + message->from->firstName
+ "!, got your message!";
std::string reply = "Hi " + message->from->firstName + ", got your message!";
api()->sendMessage(message->chat->id, reply);
}

Expand Down Expand Up @@ -128,7 +127,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(tgbotxx
GIT_REPOSITORY "https://github.com/baderouaich/tgbotxx"
GIT_TAG "v1.1.9.2" # Compatible with Telegram Api 9.2
GIT_TAG "v1.2.9.2" # Compatible with Telegram Api 9.2
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
Expand Down
3 changes: 1 addition & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ When using **tgbotxx** in your own applications:
- Protect Your Bot Token Treat your **Bot Token** like a password (if leaked), anyone can control your bot.
- Never commit your token to GitHub or other version control systems.
- If you suspect your token was leaked, revoke it immediately via [@BotFather](https://t.me/BotFather).
- Avoid Command Injection and Unsafe Operations** Never use `system()`, `popen()`, or shell commands with untrusted input.
- If you must run system commands, strictly sanitize inputs or use safe alternatives such as `std::filesystem`.
- Avoid Command Injection and Unsafe Operations** Never use `system()`, `popen()`, or shell commands with untrusted input. If you must run system commands, strictly sanitize inputs.
- Avoid deserializing arbitrary JSON from users; validate fields explicitly.
- Do not store private user data unless absolutely required.
- Encrypt sensitive information at rest using CryptoPP, OpenSSL AES, libsodium, or a trusted vault.
Expand Down
2 changes: 1 addition & 1 deletion examples/Buttons/InlineKeyboardButton/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(tgbotxx
GIT_REPOSITORY "https://github.com/baderouaich/tgbotxx"
GIT_TAG "v1.1.9.2"
GIT_TAG "v1.2.9.2"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
Expand Down
6 changes: 3 additions & 3 deletions examples/Buttons/InlineKeyboardButton/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using namespace tgbotxx;

class InlineButtonsBot : public Bot {
class InlineButtonsBot final : public Bot {
public:
InlineButtonsBot(const std::string &token) : Bot(token) {}

Expand Down Expand Up @@ -67,11 +67,11 @@ int main(int argc, const char *argv[]) {
static std::unique_ptr<InlineButtonsBot> BOT(new InlineButtonsBot(argv[1]));
std::signal(SIGINT, [](int) { // Graceful Bot exit on CTRL+C
if (BOT) {
std::cout << "Stopping Bot. Please wait...\n";
std::cout << "Stopping Bot. Please wait..." << std::endl;
BOT->stop();
}
std::exit(EXIT_SUCCESS);
});
BOT->start();
std::cout << "Bot Stopped." << std::endl;
return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion examples/Buttons/ReplyKeyboardMarkup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(tgbotxx
GIT_REPOSITORY "https://github.com/baderouaich/tgbotxx"
GIT_TAG "v1.1.9.2"
GIT_TAG "v1.2.9.2"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
Expand Down
6 changes: 3 additions & 3 deletions examples/Buttons/ReplyKeyboardMarkup/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using namespace tgbotxx;

class KeyboardButtonsBot : public Bot {
class KeyboardButtonsBot final : public Bot {
public:
KeyboardButtonsBot(const std::string &token) : Bot(token) {}

Expand Down Expand Up @@ -67,11 +67,11 @@ int main(int argc, const char *argv[]) {
static std::unique_ptr<KeyboardButtonsBot> BOT(new KeyboardButtonsBot(argv[1]));
std::signal(SIGINT, [](int) { // Graceful Bot exit on CTRL+C
if (BOT) {
std::cout << "Stopping Bot. Please wait...\n";
std::cout << "Stopping Bot. Please wait..." << std::endl;
BOT->stop();
}
std::exit(EXIT_SUCCESS);
});
BOT->start();
std::cout << "Bot Stopped." << std::endl;
return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion examples/EarthquakeBot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(tgbotxx
GIT_REPOSITORY "https://github.com/baderouaich/tgbotxx"
GIT_TAG "v1.1.9.2"
GIT_TAG "v1.2.9.2"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
Expand Down
10 changes: 4 additions & 6 deletions examples/EarthquakeBot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <set>
using namespace tgbotxx;

class EarthQuakeBot : public Bot {
class EarthQuakeBot final : public Bot {
public:
EarthQuakeBot(const std::string &token) : Bot(token) {}

Expand Down Expand Up @@ -140,23 +140,21 @@ class EarthQuakeBot : public Bot {
};


static std::unique_ptr<EarthQuakeBot> BOT;

int main(int argc, const char *argv[]) {
if (argc < 2) {
std::cerr << "Usage:\nearthquake_bot \"BOT_TOKEN\"\n";
return EXIT_FAILURE;
}

static std::unique_ptr<EarthQuakeBot> BOT = std::make_unique<EarthQuakeBot>(argv[1]);
std::signal(SIGINT, [](int) { // Graceful Bot exit on CTRL+C
if(BOT) {
std::cout << "Stopping Bot. Please wait...\n";
std::cout << "Stopping Bot. Please wait..." << std::endl;
BOT->stop();
}
std::exit(EXIT_SUCCESS);
});

BOT = std::make_unique<EarthQuakeBot>(argv[1]);
BOT->start();
std::cout << "Bot Stopped." << std::endl;
return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion examples/EchoBot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(tgbotxx
GIT_REPOSITORY "https://github.com/baderouaich/tgbotxx"
GIT_TAG "v1.1.9.2"
GIT_TAG "v1.2.9.2"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
Expand Down
6 changes: 3 additions & 3 deletions examples/EchoBot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <csignal>
using namespace tgbotxx;

class EchoBot : public Bot {
class EchoBot final : public Bot {
public:
EchoBot(const std::string& token) : Bot(token) { }

Expand Down Expand Up @@ -70,11 +70,11 @@ int main(int argc, const char *argv[]) {
static std::unique_ptr<EchoBot> BOT(new EchoBot(argv[1]));
std::signal(SIGINT, [](int) { // Graceful Bot exit on CTRL+C
if(BOT) {
std::cout << "Stopping Bot. Please wait...\n";
std::cout << "Stopping Bot. Please wait..." << std::endl;
BOT->stop();
}
std::exit(EXIT_SUCCESS);
});
BOT->start();
std::cout << "Bot Stopped." << std::endl;
return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion examples/ErrorHandling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using namespace tgbotxx;
using namespace std::chrono_literals;

class MyBot : public Bot {
class MyBot final : public Bot {
public:
void onLongPollError(const std::string& errorMessage, ErrorCode errorCode) override {
// Handle long polling error
Expand Down
2 changes: 1 addition & 1 deletion examples/PaidSubscriptionBot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(tgbotxx
GIT_REPOSITORY "https://github.com/baderouaich/tgbotxx"
GIT_TAG "v1.1.9.2"
GIT_TAG "v1.2.9.2"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
Expand Down
3 changes: 2 additions & 1 deletion examples/PaidSubscriptionBot/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ int main(int argc, const char *argv[]) {
{
std::signal(sig, [](int s) {
if(BOT) {
std::cout << "Stopping Bot. Please wait..." << std::endl;
BOT->stop();
}
std::exit(s == SIGINT ? EXIT_SUCCESS : EXIT_FAILURE);
});
}

// Start the bot
BOT->start();
std::cout << "Bot Stopped." << std::endl;
return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion examples/PingBot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(tgbotxx
GIT_REPOSITORY "https://github.com/baderouaich/tgbotxx"
GIT_TAG "v1.1.9.2"
GIT_TAG "v1.2.9.2"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
Expand Down
6 changes: 3 additions & 3 deletions examples/PingBot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <csignal>
using namespace tgbotxx;

class PingBot : public Bot {
class PingBot final : public Bot {
public:
PingBot(const std::string &token) : Bot(token) {}

Expand Down Expand Up @@ -46,11 +46,11 @@ int main(int argc, const char *argv[]) {
static std::unique_ptr<PingBot> BOT(new PingBot(argv[1]));
std::signal(SIGINT, [](int) { // Graceful Bot exit on CTRL+C
if(BOT) {
std::cout << "Stopping Bot. Please wait...\n";
std::cout << "Stopping Bot. Please wait..." << std::endl;
BOT->stop();
}
std::exit(EXIT_SUCCESS);
});
BOT->start();
std::cout << "Bot Stopped." << std::endl;
return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion examples/QrCodeBot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(tgbotxx
GIT_REPOSITORY "https://github.com/baderouaich/tgbotxx"
GIT_TAG "v1.1.9.2"
GIT_TAG "v1.2.9.2"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
Expand Down
8 changes: 4 additions & 4 deletions examples/QrCodeBot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace tgbotxx;
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image_write.h>

class QrCodeBot : public Bot {
class QrCodeBot final : public Bot {
public:
QrCodeBot(const std::string& token) : Bot(token) {}

Expand Down Expand Up @@ -135,15 +135,15 @@ int main(int argc, const char *argv[]) {
std::cerr << "Usage:\nqrcode_bot \"BOT_TOKEN\"\n";
return EXIT_FAILURE;
}
static std::unique_ptr<QrCodeBot> BOT;
static std::unique_ptr<QrCodeBot> BOT = std::make_unique<QrCodeBot>(argv[1]);
std::signal(SIGINT, [](int) { // Graceful Bot exit on CTRL+C
if (BOT) {
std::cout << "Stopping Bot. Please wait..." << std::endl;
BOT->stop();
}
std::exit(EXIT_SUCCESS);
});

BOT = std::make_unique<QrCodeBot>(argv[1]);
BOT->start();
std::cout << "Bot Stopped." << std::endl;
return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion examples/ThreadPoolBot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(tgbotxx
GIT_REPOSITORY "https://github.com/baderouaich/tgbotxx"
GIT_TAG "v1.1.9.2"
GIT_TAG "v1.2.9.2"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
Expand Down
10 changes: 6 additions & 4 deletions examples/ThreadPoolBot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using namespace tgbotxx;
using namespace std::chrono_literals;

class ThreadPoolBot : public Bot {
class ThreadPoolBot final : public Bot {
public:
ThreadPoolBot(const std::string &token) : Bot(token) {}
explicit ThreadPoolBot(const std::string &token) : Bot(token) {}

private:
cpr::ThreadPool threadPool;
Expand All @@ -30,9 +30,10 @@ class ThreadPoolBot : public Bot {
}

void onStop() override {
std::cout << "Bot Stopped\n";
std::cout << "Stopping thread pool...\n";
// Stop the thread pool
threadPool.Stop();
std::cout << "Thread pool stopped.\n";
}


Expand Down Expand Up @@ -78,12 +79,13 @@ int main(int argc, const char *argv[]) {
// Graceful Bot exit CTRL+C
std::signal(SIGINT, [](int s) {
if (BOT) {
std::cout << "Stopping Bot. Please wait..." << std::endl;
BOT->stop();
}
std::exit(EXIT_SUCCESS);
});

// Start the bot
BOT->start();
std::cout << "Bot Stopped." << std::endl;
return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion examples/UrlShortenerBot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(tgbotxx
GIT_REPOSITORY "https://github.com/baderouaich/tgbotxx"
GIT_TAG "v1.1.9.2"
GIT_TAG "v1.2.9.2"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
Expand Down
4 changes: 2 additions & 2 deletions examples/UrlShortenerBot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <tgbotxx/tgbotxx.hpp>
using namespace tgbotxx;

class UrlShortenerBot : public Bot {
class UrlShortenerBot final : public Bot {
public:
UrlShortenerBot(const std::string& token) : Bot(token) {}

Expand Down Expand Up @@ -56,8 +56,8 @@ int main(int argc, const char *argv[]) {
std::cout << "Stopping Bot. Please wait...\n";
BOT->stop();
}
std::exit(EXIT_SUCCESS);
});
BOT->start();
std::cout << "Bot Stopped." << std::endl;
return EXIT_SUCCESS;
}
Loading
Loading