tgbotxx 1.1.6.9
Telegram Bot C++ Library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PaidSubscriptionBot.hpp
Go to the documentation of this file.
1#pragma once
2#include <tgbotxx/tgbotxx.hpp>
3
5 using UserId = decltype(tgbotxx::User::id);
6 using ChatId = decltype(tgbotxx::Chat::id);
7
8public:
9 PaidSubscriptionBot(const std::string &token, const std::string& paymentProviderToken);
10
11private:
12 void onStart() override;
13 void onCommand(const tgbotxx::Ptr<tgbotxx::Message> &message) override;
14 void onAnyMessage(const tgbotxx::Ptr<tgbotxx::Message> &message) override;
15 void onStop() override;
17 void onPreCheckoutQuery(const tgbotxx::Ptr<tgbotxx::PreCheckoutQuery> &preCheckoutQuery) override;
18 void onLongPollError(const std::string& errorMessage, tgbotxx::ErrorCode errorCode) override;
19private:
20 bool isUserAlreadySubscribed(UserId id);
21 void subscribeNewUser(ChatId chatId, tgbotxx::Ptr<tgbotxx::User> newUser);
22 void onSuccessfulPayment(const tgbotxx::Ptr<tgbotxx::SuccessfulPayment>& successfulPayment);
23 void saveSubscribedUsersIds();
24 void loadSubscribedUsersIds();
25
26private:
27 std::string m_paymentProviderToken; // tip: better get from ENV on production
28 std::vector<UserId> m_subscribers; // tip: better use a realtime database to store subscribers info
29};
PaidSubscriptionBot(const std::string &token, const std::string &paymentProviderToken)
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
ErrorCode
https://core.telegram.org/api/errors
Definition Exception.hpp:8
std::int64_t id
Unique identifier for this chat.
Definition Chat.hpp:22
std::int64_t id
Unique identifier for this user or bot. This number may have more than 32 significant bits and some p...
Definition User.hpp:17