Skip to content

Commit

Permalink
fix: webhook await timeout (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
d0ctr authored Feb 20, 2024
2 parents f6ce5cd + 100d084 commit 2eb25e3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bilderberg_butler",
"version": "2.85.0",
"version": "2.85.1",
"description": "Discord bot for bilderberg club",
"main": "index.js",
"scripts": {
Expand Down
16 changes: 9 additions & 7 deletions telegram/telegram-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class TelegramInteraction {
const title = (
typeof content == 'string'
? content
: content.find((node) => node.tag == 'p' || typeof node === 'string')?.children[0] || 'GPT Answer'
: content.find((node) => node.tag == 'p' || typeof node === 'string')?.children[0] || 'Bilderberg Butler'
).split(' ').slice(0, 5).join(' ').slice(0, 256);

try {
Expand All @@ -362,17 +362,16 @@ class TelegramInteraction {
/**
* High level function for replying to Telegram-specific commands
* Returns undefined or promise for reply request
* @returns {undefined | Promise}
*/
async reply() {
reply() {
if (typeof TelegramHandlers[this.command_name]?.handler !== 'function') {
this.logger.warn(`Received nonsense, how did it get here???`);
return;
}

this.logger.info(`Received command: ${this.command_name}`);

return TelegramHandlers[this.command_name].handler(this.context, this).then(([err, response, callback, overrides]) => {
TelegramHandlers[this.command_name].handler(this.context, this).then(([err, response, callback, overrides]) => {
if (!callback) callback = () => {};
if (err) {
return this._reply(err, overrides).catch((err) => {
Expand All @@ -391,9 +390,11 @@ class TelegramInteraction {
}).then(callback);
}
else if (response instanceof String || typeof response === 'string') {
return this._reply(response, overrides).catch((err) => {
return this._reply(response, overrides).catch(err => {
if (!err?.description?.includes('message is too long')) throw err;
return this._replyWithArticle(response);
}).catch(err => {
this.logger.error(`Error while replying with response text to [${this.command_name}]`);
this.logger.debug(`Error caused by text: ${JSON.stringify(response)}`);
this._reply(`Что-то случилось:\n<code>${err}</code>`).catch((err) => this.logger.error(`Safe reply failed`, { error: err.stack || err }));
}).then(callback);
}
Expand All @@ -404,7 +405,7 @@ class TelegramInteraction {
})
}
else if (response instanceof Object) {
return this._replyWithMedia(response, overrides).catch((err) => {
return this._replyWithMedia(response, overrides).catch(err => {
this.logger.error(`Error while replying with media to [${this.command_name}]`);
this._reply(`Что-то случилось:\n<code>${err}</code>`).catch((err) => this.logger.error(`Safe reply failed`, { error: err.stack || err }));
}).then(callback);
Expand Down Expand Up @@ -857,6 +858,7 @@ class TelegramClient {

this.client = new Bot(process.env.TELEGRAM_TOKEN, {
client: {
canUseWebhookReply: (method) => method === 'sendChatAction',
buildUrl: (root, token, method) => `${root}/bot${token}${process.env?.ENV === 'dev' ? '/test' : ''}/${method}`
}
});
Expand Down

0 comments on commit 2eb25e3

Please sign in to comment.