2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-09-05 08:45:44 +00:00

Webhook health check endpoint

This commit is contained in:
Anton Mironov
2017-01-29 21:59:40 +03:00
parent 24a3f6dade
commit 3263c6c253
5 changed files with 51 additions and 15 deletions

View File

@@ -30,6 +30,17 @@ exports = module.exports = {
* @return {Promise}
*/
isPollingMockServer,
/**
* Send a message to the webhook at the specified port and path.
* @param {Number} port
* @param {String} path
* @param {Object} [options]
* @param {String} [options.method=POST] Method to use
* @param {Object} [options.message] Message to send. Default to a generic text message
* @param {Boolean} [options.https=false] Use https
* @return {Promise}
*/
sendWebHookRequest,
/**
* Send a message to the webhook at the specified port.
* @param {Number} port
@@ -134,11 +145,11 @@ function hasOpenWebHook(port, reverse) {
}
function sendWebHookMessage(port, token, options = {}) {
function sendWebHookRequest(port, path, options = {}) {
assert.ok(port);
assert.ok(token);
assert.ok(path);
const protocol = options.https ? 'https' : 'http';
const url = `${protocol}://127.0.0.1:${port}/bot${token}`;
const url = `${protocol}://127.0.0.1:${port}${path}`;
return request({
url,
method: options.method || 'POST',
@@ -146,11 +157,19 @@ function sendWebHookMessage(port, token, options = {}) {
update_id: 1,
message: options.message || { text: 'test' }
},
json: true,
json: options.json || true,
});
}
function sendWebHookMessage(port, token, options = {}) {
assert.ok(port);
assert.ok(token);
const path = `/bot${token}`;
return sendWebHookRequest(port, path, options);
}
function handleRatelimit(bot, methodName, suite) {
const backupMethodName = `__${methodName}`;
if (!bot[backupMethodName]) bot[backupMethodName] = bot[methodName];