mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 13:27:44 +00:00
[telegram] Allow specifying API Base URL
Feature: We can now pass a custom API Base URL to be used during making HTTP requests. This is useful in proxying requests, or running tests. In particular, this library is (almost) ready to be used with PWRTelegram API (http://pwrtelegram.xyz/).
This commit is contained in:
parent
8edd5f4c6d
commit
6b4ff126f4
@ -137,6 +137,7 @@ Emits `message` when a message arrives.
|
||||
| [options.webHook.autoOpen] | <code>Boolean</code> | <code>true</code> | Open webHook immediately |
|
||||
| [options.onlyFirstMatch] | <code>Boolean</code> | <code>false</code> | Set to true to stop after first match. Otherwise, all regexps are executed |
|
||||
| [options.request] | <code>Object</code> | | Options which will be added for all requests to telegram api. See https://github.com/request/request#requestoptions-callback for more information. |
|
||||
| [options.baseApiUrl] | <code>String</code> | <code>https://api.telegram.org</code> | API Base URl; useful for proxying and testing |
|
||||
|
||||
<a name="TelegramBot+initPolling"></a>
|
||||
|
||||
|
@ -51,12 +51,14 @@ class TelegramBot extends EventEmitter {
|
||||
* @param {Boolean} [options.webHook.autoOpen=true] Open webHook immediately
|
||||
* @param {Boolean} [options.onlyFirstMatch=false] Set to true to stop after first match. Otherwise, all regexps are executed
|
||||
* @param {Object} [options.request] Options which will be added for all requests to telegram api. See https://github.com/request/request#requestoptions-callback for more information.
|
||||
* @param {String} [options.baseApiUrl=https://api.telegram.org] API Base URl; useful for proxying and testing
|
||||
* @see https://core.telegram.org/bots/api
|
||||
*/
|
||||
constructor(token, options = {}) {
|
||||
super();
|
||||
this.token = token;
|
||||
this.options = options;
|
||||
this.options.baseApiUrl = options.baseApiUrl || 'https://api.telegram.org';
|
||||
this._textRegexpCallbacks = [];
|
||||
this._onReplyToMessages = [];
|
||||
|
||||
@ -169,11 +171,7 @@ class TelegramBot extends EventEmitter {
|
||||
* @see https://core.telegram.org/bots/api#making-requests
|
||||
*/
|
||||
_buildURL(_path) {
|
||||
return URL.format({
|
||||
protocol: 'https',
|
||||
host: 'api.telegram.org',
|
||||
pathname: `/bot${this.token}/${_path}`
|
||||
});
|
||||
return `${this.options.baseApiUrl}/bot${this.token}/${_path}`;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -830,11 +828,7 @@ class TelegramBot extends EventEmitter {
|
||||
*/
|
||||
getFileLink(fileId) {
|
||||
return this.getFile(fileId)
|
||||
.then(resp => URL.format({
|
||||
protocol: 'https',
|
||||
host: 'api.telegram.org',
|
||||
pathname: `/file/bot${this.token}/${resp.file_path}`
|
||||
}));
|
||||
.then(resp => `${this.options.baseApiUrl}/file/bot${this.token}/${resp.file_path}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user