11import { Bot , webhookCallback } from 'grammy' ;
22import type { Context } from 'grammy' ;
3- import { Catch } from '../decorators/Catch' ;
43import Config from '../config' ;
54import { GenerateCommand } from './handlers/GenerateCommands' ;
65import { GeneralCommands } from './commands/genearl/GeneralCommands' ;
@@ -15,7 +14,7 @@ export class CopBot {
1514 private static instance : CopBot ;
1615 private _bot : Bot < Context > ;
1716 private constructor ( ) {
18- this . _bot = new Bot < Context > ( Config . token , { client : { timeoutSeconds : 20 } } ) ;
17+ this . _bot = new Bot < Context > ( Config . token , { client : { timeoutSeconds : 10 } } ) ;
1918 }
2019 // Public method to get the singleton instance of CopBot
2120 public static getInstance ( ) : CopBot {
@@ -53,7 +52,12 @@ export class CopBot {
5352 const app = express ( ) ;
5453 app . use ( express . json ( ) ) ;
5554
56- app . post ( webhookPath , webhookCallback ( this . _bot , 'express' ) ) ;
55+ app . post ( webhookPath , ( req , res ) => {
56+ webhookCallback ( this . _bot , 'express' ) ( req , res ) . catch ( ( err ) => {
57+ logger . error ( 'Webhook processing error:' , err ) ;
58+ res . sendStatus ( 500 ) ;
59+ } ) ;
60+ } ) ;
5761
5862 const port = process . env . PORT || 3000 ;
5963 app . listen ( port , async ( ) => {
@@ -102,6 +106,7 @@ export class CopBot {
102106 const name = user . username ? `@${ user . username } ` : user . first_name ;
103107 const responseMessage = `Dear ${ name } , ask your question correctly.\nIf you want to know how to do this, read the article below:\ndontasktoask.ir` ;
104108 await reply . textReply ( responseMessage ) ;
109+ return ;
105110 }
106111 const command = messageText ?. split ( ' ' ) [ 0 ] ?. replace ( '/' , '' ) ;
107112 if ( command && ctx . message ?. entities ?. [ 0 ] . type === 'bot_command' ) {
0 commit comments