diff options
author | Nuno Esculcas <Nuno.Esculcas@ctw.bmwgroup.com> | 2020-11-08 12:01:39 +0000 |
---|---|---|
committer | Nuno Esculcas <Nuno.Esculcas@ctw.bmwgroup.com> | 2020-11-08 12:01:39 +0000 |
commit | 0bf49aa347de2512370c96aef7b5477423f14318 (patch) | |
tree | e2111fe529bf0d2fa13ad5fbfc29bb67c50f1cf4 /src | |
parent | 9fe48a3628b58dc259c36a106630d8134d029da5 (diff) |
Add support to configure the API bot server url
Now creating the bot class it is possible to override the API bot
server url that defaults to: 'https://api.telegram.org'
This enables you to connect your bot to the local API bot server.
Diffstat (limited to 'src')
-rw-r--r-- | src/Api.cpp | 10 | ||||
-rw-r--r-- | src/Bot.cpp | 4 |
2 files changed, 8 insertions, 6 deletions
diff --git a/src/Api.cpp b/src/Api.cpp index 0a08353..9acf1bb 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -15,8 +15,8 @@ using namespace boost::property_tree; namespace TgBot { -Api::Api(string token, const HttpClient& httpClient) - : _token(std::move(token)), _httpClient(httpClient), _tgTypeParser() { +Api::Api(string token, const HttpClient& httpClient, const std::string& url) + : _token(std::move(token)), _httpClient(httpClient), _tgTypeParser(), _url(url) { } User::Ptr Api::getMe() const { @@ -1172,7 +1172,8 @@ std::vector<BotCommand::Ptr> Api::getMyCommands() const } ptree Api::sendRequest(const string& method, const vector<HttpReqArg>& args) const { - string url = "https://api.telegram.org/bot"; + string url(_url); + url += "/bot"; url += _token; url += "/"; url += method; @@ -1195,7 +1196,8 @@ ptree Api::sendRequest(const string& method, const vector<HttpReqArg>& args) con } string Api::downloadFile(const string& filePath, const std::vector<HttpReqArg>& args) const { - string url = "https://api.telegram.org/file/bot"; + string url(_url); + url += "/file/bot"; url += _token; url += "/"; url += filePath; diff --git a/src/Bot.cpp b/src/Bot.cpp index 11bea2c..080b9a2 100644 --- a/src/Bot.cpp +++ b/src/Bot.cpp @@ -8,9 +8,9 @@ namespace TgBot { -Bot::Bot(std::string token, const HttpClient& httpClient) +Bot::Bot(std::string token, const HttpClient& httpClient, const std::string& url) : _token(std::move(token)) - , _api(_token, httpClient) + , _api(_token, httpClient, url) , _eventBroadcaster(std::make_unique<EventBroadcaster>()) , _eventHandler(getEvents()) { } |