Skip to content

Commit 9f9d3af

Browse files
committed
chore: Update dependencies and add error handling for bot timeouts
1 parent bcdd98c commit 9f9d3af

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

package-lock.json

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bot/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export class CopBot {
5252
const app = express();
5353
app.use(express.json());
5454
app.post(webhookPath, async (req, res) => {
55-
res.sendStatus(200);
5655
setImmediate(async () => {
5756
try {
5857
await webhookCallback(this._bot, 'express')(req, res);
@@ -74,7 +73,7 @@ export class CopBot {
7473
try {
7574
if (!webhookInfo.url) {
7675
logger.warn('Webhook is not set. Trying to set the webhook...');
77-
await this._bot.api.setWebhook(webhookURL);
76+
await this._bot.api.setWebhook(webhookURL, { max_connections: 100 });
7877
webhookInfo = await this._bot.api.getWebhookInfo();
7978
logger.info(`Webhook set: ${webhookInfo.url}`);
8079
} else {
@@ -114,7 +113,10 @@ export class CopBot {
114113
new GenerateCommand(this._bot).generate();
115114
this._bot.on('my_chat_member', (ctx) => this.handleJoinNewChat(ctx));
116115
this._bot.on('message', (ctx) => this.handleMessage(ctx));
117-
this._bot.catch((error: BotError<Context>) => {
116+
this._bot.catch(async (error: BotError<Context>) => {
117+
if (error.message.includes('timeout')) {
118+
await error.ctx.reply('The request took too long to process. Please try again later.');
119+
}
118120
logger.error(`Bot error occurred: ${error.error}`);
119121
});
120122
this._bot.use(

0 commit comments

Comments
 (0)