Skip to content

Commit 5a136d7

Browse files
authored
Merge pull request #22 from elizaos-plugins/feat/use-elizaos-handlemessage
refactor: implement unified messaging API with elizaOS support
2 parents 25075dd + b46a3ef commit 5a136d7

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/messageManager.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,15 +682,22 @@ export class MessageManager {
682682
}
683683
};
684684

685-
// Call the message handler directly instead of emitting events
686-
// This provides a clearer, more traceable flow for message processing
687-
if (!this.runtime.messageService) {
685+
// Use elizaOS.handleMessage if available (unified messaging API with streaming support)
686+
// Falls back to direct messageService call for backward compatibility
687+
if (this.runtime.hasElizaOS()) {
688+
await this.runtime.elizaOS.handleMessage(this.runtime.agentId, memory, {
689+
onResponse: async (content) => {
690+
await callback(content);
691+
},
692+
});
693+
} else if (this.runtime.messageService) {
694+
await this.runtime.messageService.handleMessage(this.runtime, memory, callback);
695+
} else {
688696
logger.error({ src: 'plugin:telegram', agentId: this.runtime.agentId }, 'Message service is not available');
689697
throw new Error(
690698
'Message service is not initialized. Ensure the message service is properly configured.'
691699
);
692700
}
693-
await this.runtime.messageService.handleMessage(this.runtime, memory, callback);
694701
} catch (error) {
695702
logger.error({ src: 'plugin:telegram', agentId: this.runtime.agentId, chatId: ctx.chat?.id, messageId: ctx.message?.message_id, from: ctx.from?.username || ctx.from?.id, error: error instanceof Error ? error.message : String(error) }, 'Error handling Telegram message');
696703
throw error;

0 commit comments

Comments
 (0)