Skip to content

Commit

Permalink
Merge pull request #157 from nesc1/customizeServerUrl
Browse files Browse the repository at this point in the history
Add support to configure the API bot server url
  • Loading branch information
reo7sp committed Nov 10, 2020
2 parents bd70cd3 + 0bf49aa commit 9dae1b4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion include/tgbot/Api.h
Expand Up @@ -46,7 +46,7 @@ typedef std::shared_ptr<std::vector<std::string>> StringArrayPtr;
friend class Bot;

public:
Api(std::string token, const HttpClient& httpClient);
Api(std::string token, const HttpClient& httpClient, const std::string& url);

/**
* @brief A simple method for testing your bot's auth token.
Expand Down Expand Up @@ -823,6 +823,7 @@ friend class Bot;
const std::string _token;
const HttpClient& _httpClient;
const TgTypeParser _tgTypeParser;
const std::string _url;
};

}
Expand Down
2 changes: 1 addition & 1 deletion include/tgbot/Bot.h
Expand Up @@ -21,7 +21,7 @@ class HttpClient;
class TGBOT_API Bot {

public:
explicit Bot(std::string token, const HttpClient &httpClient = _getDefaultHttpClient());
explicit Bot(std::string token, const HttpClient &httpClient = _getDefaultHttpClient(), const std::string& url="https://api.telegram.org");

/**
* @return Token for accessing api.
Expand Down
10 changes: 6 additions & 4 deletions src/Api.cpp
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Bot.cpp
Expand Up @@ -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()) {
}
Expand Down

0 comments on commit 9dae1b4

Please sign in to comment.