Overview
TheChatPlatform trait defines the interface for all chat platform adapters in Magpie. Every messaging platform integration (Discord, Teams, Slack, etc.) implements this trait to provide a consistent API for fetching conversation history, sending messages, and managing threads.
Trait Definition
Methods
Platform identifier (e.g., “discord”, “teams”, “slack”).Returns a static string identifying the chat platform. Used for logging and debugging.
Fetch conversation history from a channel/thread, formatted as text.Parameters:
channel_id- Platform-specific channel or thread identifier
Ok(String)- Formatted conversation history as textErr(_)- If fetching history fails
task in run_pipeline(). Dumping the last N channel messages often adds noise rather than useful context.Send a message to a channel/thread.Parameters:
channel_id- Platform-specific channel or thread identifiertext- Message content to send
Ok(())- Message sent successfullyErr(_)- If sending fails
Close or archive a thread after the final response has been sent.Parameters:
channel_id- Platform-specific channel or thread identifier
Ok(())- Thread closed successfully (or no-op)Err(_)- If closing fails
Ok(()). Platforms that support thread archiving (e.g., Discord) override this.Example Implementation
Here’s a complete implementation for Discord using the Serenity library:Usage in Pipeline
TheChatPlatform trait is used throughout the pipeline to send status updates:
Design Notes
- All trait methods use
async_traitsince chat platform APIs are typically async - The trait requires
Send + Syncbounds for use across async task boundaries - Channel IDs are platform-specific strings (numeric IDs for Discord, complex identifiers for Teams)
- Error handling uses
anyhow::Resultfor flexibility - The default
close_threadimplementation makes thread archiving optional