File tree 1 file changed +14
-5
lines changed
1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -24,11 +24,20 @@ class TelegramService {
24
24
return bot . sendMessage ( chatId , 'Messages has been cleared' ) ;
25
25
}
26
26
const timer = new Date ( ) . getTime ( ) ;
27
- // Trả lời tin nhắn dựa trên các tin nhắn cũ
28
- const responseMsg = await ChatGPTService . generateCompletion ( chatMsg , user ) ;
29
- const timeDiff = new Date ( ) . getTime ( ) - timer ;
30
- console . log ( 'Taken ' + timeDiff + 'ms to respond (about ' + ~ ~ ( timeDiff / 100 ) / 10 + 's)' ) ;
31
- return await bot . sendMessage ( chatId , responseMsg ) ;
27
+ try {
28
+ // Trả lời tin nhắn dựa trên các tin nhắn cũ
29
+ const responseMsg = await ChatGPTService . generateCompletion ( chatMsg , user ) ;
30
+ const timeDiff = new Date ( ) . getTime ( ) - timer ;
31
+ console . log ( 'Taken ' + timeDiff + 'ms to respond (about ' + ~ ~ ( timeDiff / 100 ) / 10 + 's)' ) ;
32
+ return await bot . sendMessage ( chatId , responseMsg ) ;
33
+ } catch ( e ) {
34
+ if ( e && e . response && e . response . data ) {
35
+ await bot . sendMessage ( chatId , e . response . data ?. error ?. message || "Failed status from OpenAI Platform" ) ;
36
+ console . log ( e . response . data ?. error ) ;
37
+ } else {
38
+ await bot . sendMessage ( chatId , "Unexpected error, please check server log for more details." ) ;
39
+ }
40
+ }
32
41
}
33
42
}
34
43
You can’t perform that action at this time.
0 commit comments