Skip to content

Commit e4c3aef

Browse files
committed
feat(bot): Updated webhook creation and error handling in CopBot
1 parent a5c4663 commit e4c3aef

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/bot/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,22 @@ export class CopBot {
3131
const web_hook = Config.web_hook;
3232
const isProduction = Config.environment === 'production';
3333
if (isProduction) {
34-
const server = http.createServer(webhookCallback(this._bot, 'http'));
34+
const server = http.createServer(webhookCallback(this._bot, 'http', { timeoutMilliseconds: 30000 }));
3535
server.listen(port, '0.0.0.0', () => {
3636
console.log(`Bot started on port ${port}`);
3737
});
3838
try {
3939
await this._bot.api.setWebhook(`${web_hook}`);
4040
console.log(`Webhook set successfully to: ${web_hook}`);
41-
} catch (error) {
42-
console.error('Error setting webhook:', error);
43-
process.exit(1);
41+
const webhookStatus = await this._bot.api.getWebhookInfo();
42+
if (webhookStatus.url) {
43+
console.log(`Webhook is already set to: ${webhookStatus.url}`);
44+
} else {
45+
console.log('No webhook set.');
46+
}
47+
} catch (error:any) {
48+
console.error('Error setting webhook:', error.message || error.stack);
49+
process.exit(1); // Exit if critical error
4450
}
4551
} else {
4652
try {

0 commit comments

Comments
 (0)