Skip to content

Commit 093613e

Browse files
authored
Merge pull request #24 from elizaos-plugins/fix/typescript-errors-1.6.4
fix: resolve TypeScript errors for @elizaos/core 1.7.x compatibility
2 parents 5a136d7 + 5a0aaa9 commit 093613e

4 files changed

Lines changed: 49 additions & 41 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elizaos/plugin-telegram",
3-
"version": "1.6.3",
3+
"version": "1.6.4",
44
"type": "module",
55
"main": "dist/index.js",
66
"module": "dist/index.js",
@@ -18,7 +18,7 @@
1818
"dist"
1919
],
2020
"dependencies": {
21-
"@elizaos/core": "^1.6.2",
21+
"@elizaos/core": "^1.7.2",
2222
"@telegraf/types": "7.1.0",
2323
"@types/node": "^24.0.10",
2424
"strip-literal": "^3.0.0",
@@ -27,7 +27,7 @@
2727
"typescript": "^5.8.3"
2828
},
2929
"devDependencies": {
30-
"@elizaos/config": "^1.6.4",
30+
"@elizaos/config": "^1.7.2",
3131
"@eslint/js": "^9.17.0",
3232
"@typescript-eslint/eslint-plugin": "^8.22.0",
3333
"@typescript-eslint/parser": "^8.22.0",

src/messageManager.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { Markup } from 'telegraf';
1818
import {
1919
type TelegramContent,
2020
TelegramEventTypes,
21-
type TelegramMessageSentPayload,
2221
type TelegramReactionReceivedPayload,
2322
} from './types';
2423
import { convertToTelegramButtons, convertMarkdownToTelegram, cleanText } from './utils';
@@ -593,7 +592,6 @@ export class MessageManager {
593592
name: ctx.from.first_name,
594593
source: 'telegram',
595594
channelId: telegramRoomid,
596-
serverId: undefined,
597595
type: channelType,
598596
worldId: createUniqueUuid(this.runtime, roomId) as UUID,
599597
worldName: telegramRoomid,
@@ -859,20 +857,25 @@ export class MessageManager {
859857
}
860858

861859
// Emit both generic and platform-specific message sent events
862-
this.runtime.emitEvent(EventType.MESSAGE_SENT, {
863-
runtime: this.runtime,
864-
message: {
865-
content: content,
866-
},
867-
roomId,
868-
source: 'telegram',
869-
});
860+
if (memories.length > 0) {
861+
this.runtime.emitEvent(EventType.MESSAGE_SENT, {
862+
runtime: this.runtime,
863+
message: memories[0],
864+
source: 'telegram',
865+
});
866+
}
870867

871868
// Also emit platform-specific event
872-
this.runtime.emitEvent(TelegramEventTypes.MESSAGE_SENT, {
873-
originalMessages: sentMessages,
874-
chatId,
875-
} as TelegramMessageSentPayload);
869+
this.runtime.emitEvent(
870+
TelegramEventTypes.MESSAGE_SENT as string,
871+
{
872+
runtime: this.runtime,
873+
source: 'telegram',
874+
originalMessages: sentMessages,
875+
chatId,
876+
message: memories[0],
877+
} as any
878+
);
876879

877880
return sentMessages;
878881
} catch (error) {

src/service.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,14 @@ export class TelegramService extends Service {
159159
*/
160160
private async initializeBot(): Promise<void> {
161161
this.bot?.start((ctx) => {
162-
this.runtime.emitEvent([TelegramEventTypes.SLASH_START], {
163-
// we don't need this
164-
ctx,
165-
});
162+
this.runtime.emitEvent(
163+
TelegramEventTypes.SLASH_START as string,
164+
{
165+
ctx,
166+
runtime: this.runtime,
167+
source: 'telegram',
168+
} as any
169+
);
166170
});
167171
this.bot?.launch({
168172
dropPendingUpdates: true,
@@ -386,7 +390,6 @@ export class TelegramService extends Service {
386390
name: ctx.from.first_name || ctx.from.username || 'Unknown User',
387391
source: 'telegram',
388392
channelId: chatId,
389-
serverId: chatId,
390393
type: ChannelType.GROUP,
391394
worldId: worldId,
392395
});
@@ -426,24 +429,30 @@ export class TelegramService extends Service {
426429
entityId,
427430
roomId: roomId,
428431
userName: newMember.username,
429-
userId: telegramId,
432+
userId: telegramId as UUID,
430433
name: newMember.first_name || newMember.username || 'Unknown User',
431434
source: 'telegram',
432435
channelId: chatId,
433-
serverId: chatId,
434436
type: ChannelType.GROUP,
435437
worldId: worldId,
436438
});
437439

438440
this.syncedEntityIds.add(entityId);
439441

440-
this.runtime.emitEvent([TelegramEventTypes.ENTITY_JOINED], {
441-
runtime: this.runtime,
442-
entityId,
443-
worldId,
444-
newMember,
445-
ctx,
446-
});
442+
this.runtime.emitEvent(
443+
TelegramEventTypes.ENTITY_JOINED as string,
444+
{
445+
runtime: this.runtime,
446+
entityId,
447+
worldId,
448+
source: 'telegram',
449+
telegramUser: {
450+
id: newMember.id,
451+
username: newMember.username,
452+
first_name: newMember.first_name,
453+
},
454+
} as any
455+
);
447456
}
448457
}
449458

@@ -576,7 +585,7 @@ export class TelegramService extends Service {
576585
id: worldId,
577586
name: chatTitle,
578587
agentId: this.runtime.agentId,
579-
serverId: chatId,
588+
serverId: chatId as UUID,
580589
metadata: {
581590
source: 'telegram',
582591
...(ownerId && { ownership: { ownerId } }),
@@ -600,7 +609,7 @@ export class TelegramService extends Service {
600609
source: 'telegram',
601610
type: channelType,
602611
channelId: chatId,
603-
serverId: chatId,
612+
serverId: chatId as UUID,
604613
worldId,
605614
};
606615

@@ -636,7 +645,6 @@ export class TelegramService extends Service {
636645
entities,
637646
generalRoom.id!,
638647
generalRoom.channelId!,
639-
generalRoom.serverId!,
640648
generalRoom.type,
641649
worldId
642650
);
@@ -673,7 +681,6 @@ export class TelegramService extends Service {
673681
* @param {Entity[]} entities - The entities to process
674682
* @param {UUID} roomId - The ID of the room to connect entities to
675683
* @param {string} channelId - The channel ID
676-
* @param {string} serverId - The server ID
677684
* @param {ChannelType} roomType - The type of the room
678685
* @param {UUID} worldId - The ID of the world
679686
* @returns {Promise<void>}
@@ -683,7 +690,6 @@ export class TelegramService extends Service {
683690
entities: Entity[],
684691
roomId: UUID,
685692
channelId: string,
686-
serverId: string,
687693
roomType: ChannelType,
688694
worldId: UUID
689695
): Promise<void> {
@@ -713,7 +719,6 @@ export class TelegramService extends Service {
713719
userId: telegramMetadata?.id as UUID,
714720
source: 'telegram',
715721
channelId: channelId,
716-
serverId: serverId,
717722
type: roomType,
718723
worldId: worldId,
719724
});
@@ -904,7 +909,7 @@ export class TelegramService extends Service {
904909
source: 'telegram',
905910
type: ChannelType.GROUP,
906911
channelId: `${chatId}-${threadId}`,
907-
serverId: chatId,
912+
serverId: chatId as UUID,
908913
worldId,
909914
metadata: {
910915
threadId: threadId,

src/tests.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ export class TelegramTestSuite implements TestSuite {
7373
* @throws {Error} If TELEGRAM_TEST_CHAT_ID is not set in the runtime settings or environment variables.
7474
* @returns {string} The validated chat ID.
7575
*/
76-
validateChatId(runtime: IAgentRuntime) {
76+
validateChatId(runtime: IAgentRuntime): string | number {
7777
const testChatId =
7878
runtime.getSetting('TELEGRAM_TEST_CHAT_ID') || process.env.TELEGRAM_TEST_CHAT_ID;
79-
if (!testChatId) {
79+
if (!testChatId || typeof testChatId === 'boolean') {
8080
throw new Error(
8181
'TELEGRAM_TEST_CHAT_ID is not set. Please provide a valid chat ID in the environment variables.'
8282
);
@@ -200,7 +200,7 @@ export class TelegramTestSuite implements TestSuite {
200200
if (!this.messageManager) throw new Error('MessageManager not initialized.');
201201

202202
const chatId = this.validateChatId(runtime);
203-
const fileId = await this.getFileId(chatId, TEST_IMAGE_URL);
203+
const fileId = await this.getFileId(String(chatId), TEST_IMAGE_URL);
204204

205205
const mockMessage = {
206206
message_id: 12345,

0 commit comments

Comments
 (0)