@@ -15,39 +15,6 @@ export class TelegramClient {
15
15
this . bot = new Telegraf ( botToken ) ;
16
16
this . messageManager = new MessageManager ( this . bot , this . runtime ) ;
17
17
18
- elizaLogger . log ( "Setting up message handler..." ) ;
19
- this . bot . on ( "message" , async ( ctx ) => {
20
- try {
21
- elizaLogger . log ( "📥 Received message:" , ctx . message ) ;
22
- await this . messageManager . handleMessage ( ctx ) ;
23
- } catch ( error ) {
24
- elizaLogger . error ( "❌ Error handling message:" , error ) ;
25
- await ctx . reply (
26
- "An error occurred while processing your message."
27
- ) ;
28
- }
29
- } ) ;
30
-
31
- // Handle specific message types for better logging
32
- this . bot . on ( "photo" , ( ctx ) => {
33
- elizaLogger . log (
34
- "📸 Received photo message with caption:" ,
35
- ctx . message . caption
36
- ) ;
37
- } ) ;
38
-
39
- this . bot . on ( "document" , ( ctx ) => {
40
- elizaLogger . log (
41
- "📎 Received document message:" ,
42
- ctx . message . document . file_name
43
- ) ;
44
- } ) ;
45
-
46
- this . bot . catch ( ( err , ctx ) => {
47
- elizaLogger . error ( `❌ Telegram Error for ${ ctx . updateType } :` , err ) ;
48
- ctx . reply ( "An unexpected error occurred. Please try again later." ) ;
49
- } ) ;
50
-
51
18
elizaLogger . log ( "✅ TelegramClient constructor completed" ) ;
52
19
}
53
20
@@ -60,7 +27,51 @@ export class TelegramClient {
60
27
elizaLogger . log (
61
28
"✨ Telegram bot successfully launched and is running!"
62
29
) ;
63
- elizaLogger . log ( `Bot username: @${ this . bot . botInfo ?. username } ` ) ;
30
+
31
+ await this . bot . telegram . getMe ( ) . then ( ( botInfo ) => {
32
+ this . bot . botInfo = botInfo ;
33
+ } ) ;
34
+
35
+ console . log ( `Bot username: @${ this . bot . botInfo ?. username } ` ) ;
36
+
37
+ this . messageManager . bot = this . bot ;
38
+
39
+ // Include if you want to view message maanger bot info
40
+ // console.log(`Message Manager bot info: @${this.messageManager.bot}`);
41
+
42
+ elizaLogger . log ( "Setting up message handler..." ) ;
43
+
44
+ this . bot . on ( "message" , async ( ctx ) => {
45
+ try {
46
+ console . log ( "📥 Received message:" , ctx . message ) ;
47
+ await this . messageManager . handleMessage ( ctx ) ;
48
+ } catch ( error ) {
49
+ elizaLogger . error ( "❌ Error handling message:" , error ) ;
50
+ await ctx . reply (
51
+ "An error occurred while processing your message."
52
+ ) ;
53
+ }
54
+ } ) ;
55
+
56
+ // Handle specific message types for better logging
57
+ this . bot . on ( "photo" , ( ctx ) => {
58
+ elizaLogger . log (
59
+ "📸 Received photo message with caption:" ,
60
+ ctx . message . caption
61
+ ) ;
62
+ } ) ;
63
+
64
+ this . bot . on ( "document" , ( ctx ) => {
65
+ elizaLogger . log (
66
+ "📎 Received document message:" ,
67
+ ctx . message . document . file_name
68
+ ) ;
69
+ } ) ;
70
+
71
+ this . bot . catch ( ( err , ctx ) => {
72
+ elizaLogger . error ( `❌ Telegram Error for ${ ctx . updateType } :` , err ) ;
73
+ ctx . reply ( "An unexpected error occurred. Please try again later." ) ;
74
+ } ) ;
64
75
65
76
// Graceful shutdown handlers
66
77
const shutdownHandler = async ( signal : string ) => {
@@ -93,4 +104,4 @@ export class TelegramClient {
93
104
await this . bot . stop ( ) ;
94
105
elizaLogger . log ( "Telegram bot stopped" ) ;
95
106
}
96
- }
107
+ }
0 commit comments