Skip to content

fix: use handleMessage instead of sendMessage for elizaOS unified API#41

Open
standujar wants to merge 2 commits into1.xfrom
fix/unified-api-handlemessage
Open

fix: use handleMessage instead of sendMessage for elizaOS unified API#41
standujar wants to merge 2 commits into1.xfrom
fix/unified-api-handlemessage

Conversation

@standujar
Copy link
Contributor

@standujar standujar commented Jan 7, 2026

Greptile Overview

Greptile Summary

This PR updates the Discord plugin to use the new handleMessage method instead of the deprecated sendMessage method in the elizaOS unified messaging API. The changes are clean and complete:

  • Updated the UnifiedMessagingAPI interface definition to use handleMessage
  • Updated the runtime check function hasUnifiedMessagingAPI to detect the new method
  • Updated the actual API call in messages.ts to invoke handleMessage
  • Updated documentation comments to reflect the new method name

The PR also includes formatting changes (single to double quotes) that appear to be from an auto-formatter. All changes are backward compatible since they only affect the new unified API path, with fallbacks to messageService and event-based handling still intact.

Confidence Score: 5/5

  • This PR is safe to merge with no risk - it's a straightforward method rename that aligns with the updated elizaOS API
  • The changes are minimal, focused, and complete. All three required updates (interface definition, runtime check, and API call) are present and correct. The PR maintains backward compatibility through existing fallback mechanisms for older core versions. No logic changes were introduced, only a method name update.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/messages.ts 5/5 Updated unified API call from sendMessage to handleMessage at line 455, aligning with the new interface definition
src/utils.ts 5/5 Updated UnifiedMessagingAPI interface and hasUnifiedMessagingAPI function to use handleMessage instead of deprecated sendMessage, includes formatting changes (quote style)

Sequence Diagram

sequenceDiagram
    participant Discord as Discord Message
    participant MM as MessageManager
    participant Utils as getUnifiedMessagingAPI()
    participant Runtime as IAgentRuntime
    participant UnifiedAPI as elizaOS.handleMessage
    participant MsgService as messageService.handleMessage
    participant Callback as HandlerCallback
    
    Discord->>MM: handleMessage(message)
    MM->>MM: processMessage()
    MM->>MM: buildMemoryFromMessage()
    MM->>Utils: getUnifiedMessagingAPI(runtime)
    Utils->>Runtime: Check elizaOS.handleMessage exists
    
    alt Unified API Available (NEW)
        Runtime-->>Utils: elizaOS.handleMessage found
        Utils-->>MM: Return UnifiedMessagingAPI
        MM->>UnifiedAPI: handleMessage(agentId, message, {onResponse: callback})
        UnifiedAPI->>Callback: Execute callback with content
        Callback->>Discord: Send response to channel
    else MessageService Available
        Runtime-->>Utils: messageService found
        Utils-->>MM: Return null, check messageService
        MM->>MsgService: handleMessage(runtime, message, callback)
        MsgService->>Callback: Execute callback with content
        Callback->>Discord: Send response to channel
    else Legacy Event-based
        Runtime-->>Utils: Neither available
        Utils-->>MM: Return null
        MM->>Runtime: emitEvent(MESSAGE_RECEIVED)
        Runtime->>Callback: Execute callback with content
        Callback->>Discord: Send response to channel
    end
Loading

Summary by CodeRabbit

  • Refactor
    • Refined the unified messaging interface to a new public API surface, improving consistency of message handling.
  • Chores
    • Bumped package version to 1.3.7.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2026

Walkthrough

Renamed the unified messaging API method from sendMessage to handleMessage and updated its usages. Also bumped the package version from 1.3.6 to 1.3.7. Method signature and call-site arguments remain unchanged; only the method name and version field were modified.

Changes

Cohort / File(s) Summary
Unified Messaging API Rename
src/utils.ts, src/messages.ts
Replaced sendMessage with handleMessage in the UnifiedMessagingAPI declaration and updated call site in message handler. Runtime access checks and docs updated to elizaOS.handleMessage. Signature/arguments unchanged.
Version Bump
package.json
Incremented package version from 1.3.6 to 1.3.7.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through lines to change a name,
From sendMessage to handleMessage—still the same.
Two files nudged, a version skip,
A tiny hop, a cheerful quip. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically describes the main change: replacing sendMessage with handleMessage in the elizaOS unified API across the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/unified-api-handlemessage

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 8c36bd8 and 1652073.

📒 Files selected for processing (1)
  • package.json
✅ Files skipped from review due to trivial changes (1)
  • package.json

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @src/utils.ts:
- Around line 49-54: The current hasUnifiedMessagingAPI runtime check looks for
runtime.elizaOS.handleMessage, which is a non-standard pattern for @elizaos/core
v1.7.0; change the detection to prefer the standard messageService API by
checking for runtime.messageService && typeof
runtime.messageService.handleMessage === "function" (and optionally keep a
secondary check for runtime.elizaOS && typeof runtime.elizaOS.handleMessage ===
"function" for legacy compatibility), updating the hasUnifiedMessagingAPI
function accordingly and ensuring code paths that rely on unified messaging (see
messages.ts fallback referencing messageService.handleMessage) will use the
messageService detection first.
🧹 Nitpick comments (1)
src/utils.ts (1)

25-31: Interface and runtime check are consistent with the API rename.

The UnifiedMessagingAPI interface correctly exposes handleMessage with the expected signature, and the hasUnifiedMessagingAPI function at lines 49-54 properly checks for elizaOS.handleMessage. The changes are internally consistent.

Consider strengthening the types in a follow-up: message: any and onResponse?: any lose type safety. Using the actual Memory and HandlerCallback types from @elizaos/core would improve maintainability.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 7a4dfe2 and 8c36bd8.

📒 Files selected for processing (2)
  • src/messages.ts
  • src/utils.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/utils.ts (1)
src/types.ts (2)
  • DiscordActionRow (535-538)
  • DiscordComponentOptions (520-533)
🔇 Additional comments (2)
src/messages.ts (2)

447-477: API method rename applied correctly with consistent fallback chain.

The call to unifiedAPI.handleMessage at line 455 correctly uses the renamed method with the same argument structure. The fallback logic to messageService.handleMessage (line 464) and event-based handling (lines 471-476) remains intact, ensuring backward compatibility with older core versions.


455-457: No action required. Verification confirms no stale sendMessage references remain in the codebase that could cause runtime errors. The refactoring from sendMessage to handleMessage is complete and safe.

Comment on lines 49 to 54
export function hasUnifiedMessagingAPI(runtime: IAgentRuntime): boolean {
const runtimeAny = runtime as any;
return !!(runtimeAny.elizaOS && typeof runtimeAny.elizaOS.sendMessage === 'function');
return !!(
runtimeAny.elizaOS && typeof runtimeAny.elizaOS.handleMessage === "function"
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Find package.json to check the actual version
find . -name "package.json" -type f | head -5 | xargs cat

Repository: elizaos-plugins/plugin-discord

Length of output: 4121


🏁 Script executed:

# Search for references to elizaOS and handleMessage in the codebase
rg "elizaOS|handleMessage" -t ts -t js --max-count 20

Repository: elizaos-plugins/plugin-discord

Length of output: 3321


🏁 Script executed:

# Look for IAgentRuntime definition to understand the interface
rg "interface IAgentRuntime|type IAgentRuntime" -A 10 -t ts -t js

Repository: elizaos-plugins/plugin-discord

Length of output: 12407


🏁 Script executed:

# Search for references to sendMessage to understand the deprecation
rg "sendMessage" -t ts -t js --max-count 15

Repository: elizaos-plugins/plugin-discord

Length of output: 604


🏁 Script executed:

# Search for UnifiedMessagingAPI type definition
rg "UnifiedMessagingAPI|interface.*MessageAPI" -B 3 -A 10 -t ts

Repository: elizaos-plugins/plugin-discord

Length of output: 3623


🏁 Script executed:

# Look at the complete getUnifiedMessagingAPI and hasUnifiedMessagingAPI functions
sed -n '40,80p' src/utils.ts

Repository: elizaos-plugins/plugin-discord

Length of output: 1458


🏁 Script executed:

# Search for any comments or documentation about the elizaOS API
rg "elizaOS|unified.*messaging" -B 2 -A 2 -t ts | head -60

Repository: elizaos-plugins/plugin-discord

Length of output: 2253


🌐 Web query:

elizaOS core 1.7.0 unified messaging handleMessage API

💡 Result:

Summary (elizaOS core — handleMessage / unified messaging, v1.7.x)

  • Where: exported from @elizaos/core (Agent runtime API / Types). [1][2]
  • Main signatures:
    • handleMessage(agentId: UUID | IAgentRuntime, message: Message, options?: HandleMessageOptions): Promise. [1]
    • handleMessages(messages: Array<{ agentId: UUID; message: Message }>): Promise<HandleMessageResult[]> (batch API). [1]
  • Key types (most important fields):
    • HandleMessageOptions: onResponse, onStreamChunk, onError, onComplete, skipEvaluators, skipActions. (callbacks usable for streaming/async processing). [1]
    • HandleMessageResult: { messageId: UUID; userMessage: Memory; processing?: { text: string; actions?: ActionResult[]; evaluations?: unknown[] }; error?: Error }. [1]
  • Behavior:
    • Routes inbound messages through the runtime’s message-processing core (bootstrap plugin) and the unified message bus so the same handler works for WebSocket, Discord/Telegram adapters, HTTP, etc. Output may be streamed via onStreamChunk/onResponse callbacks or returned fully in processing.text. [2][3]
  • Notes:
    • Use handleMessages for parallel/batched deliveries (returns array of HandleMessageResult). [1]
    • Options allow skipping evaluator/action phases if you only want raw response text or lower-latency handling. [1]

Sources

  • Types & API reference (handleMessage, options, result shape). [1]
  • Messaging / runtime and bootstrap (unified message bus, message flow through bootstrap/core). [2][3]

🌐 Web query:

@elizaos/core 1.7.0 release notes handleMessage runtime

💡 Result:

Do you want a brief summary of what's changed in @elizaos/core v1.7.0 (specifically handleMessage/runtime), or the direct release notes / links (GitHub release, changelog, or commit diff)? I can search GitHub, npm, and the docs and return citations.


🌐 Web query:

elizaOS IAgentRuntime elizaOS.handleMessage documentation

💡 Result:

Short answer — documentation and signatures:

  • The elizaOS docs describe IAgentRuntime and the runtime HandleMessage API in the Types Reference. The handleMessage signature is:
    handleMessage(
    agentId: UUID | IAgentRuntime,
    message: Message,
    options?: HandleMessageOptions
    ): Promise
    — with HandleMessageOptions (onResponse, onStreamChunk, onError, onComplete, skipEvaluators, skipActions) and HandleMessageResult (messageId, userMessage, processing, error). [1]

  • For broader context on IAgentRuntime (properties and runtime methods like composeState, processActions, evaluate, register* and model/service management) see the Core / AgentRuntime pages. [2][3]

Sources:

  • Types Reference — HandleMessage, HandleMessageOptions, HandleMessageResult. [1]
  • Core / AgentRuntime overview (IAgentRuntime methods & properties). [2]
  • Plugins / Reference pages for related interfaces and examples. [3]

The check for runtime.elizaOS.handleMessage uses a non-standard API pattern for v1.7.0.

While @elizaos/core 1.7.0 does export a handleMessage API, it is not exposed as runtime.elizaOS.handleMessage. The standard unified messaging pattern in 1.7.0 routes through messageService.handleMessage (as evidenced by the fallback in messages.ts). The defensive check here appears to handle a legacy or optional API pattern that may not exist in the target version. Consider confirming whether the elizaOS wrapper is guaranteed to exist, or rely primarily on the messageService fallback.

🤖 Prompt for AI Agents
In @src/utils.ts around lines 49 - 54, The current hasUnifiedMessagingAPI
runtime check looks for runtime.elizaOS.handleMessage, which is a non-standard
pattern for @elizaos/core v1.7.0; change the detection to prefer the standard
messageService API by checking for runtime.messageService && typeof
runtime.messageService.handleMessage === "function" (and optionally keep a
secondary check for runtime.elizaOS && typeof runtime.elizaOS.handleMessage ===
"function" for legacy compatibility), updating the hasUnifiedMessagingAPI
function accordingly and ensuring code paths that rely on unified messaging (see
messages.ts fallback referencing messageService.handleMessage) will use the
messageService detection first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant