Skip to main content

ChatAdapter

Trait ChatAdapter 

Source
pub trait ChatAdapter: Send + Sync {
Show 15 methods // Required methods fn name(&self) -> &str; fn post_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, thread_id: &'life1 str, message: &'life2 AdapterPostableMessage, ) -> Pin<Box<dyn Future<Output = Result<SentMessage, ChatError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn edit_message<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, thread_id: &'life1 str, message_id: &'life2 str, message: &'life3 AdapterPostableMessage, ) -> Pin<Box<dyn Future<Output = Result<SentMessage, ChatError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn delete_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, thread_id: &'life1 str, message_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), ChatError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn render_card(&self, card: &CardElement) -> String; fn render_message(&self, message: &AdapterPostableMessage) -> String; fn recv_event<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Option<ChatEvent>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided methods fn stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, thread_id: &'life1 str, text_stream: TextStream, options: &'life2 StreamOptions, ) -> Pin<Box<dyn Future<Output = Result<SentMessage, ChatError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn add_reaction<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _thread_id: &'life1 str, _message_id: &'life2 str, _emoji: &'life3 EmojiValue, ) -> Pin<Box<dyn Future<Output = Result<(), ChatError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn remove_reaction<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _thread_id: &'life1 str, _message_id: &'life2 str, _emoji: &'life3 EmojiValue, ) -> Pin<Box<dyn Future<Output = Result<(), ChatError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn open_dm<'life0, 'life1, 'async_trait>( &'life0 self, _user_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String, ChatError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn post_ephemeral<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _thread_id: &'life1 str, _user_id: &'life2 str, _message: &'life3 AdapterPostableMessage, ) -> Pin<Box<dyn Future<Output = Result<EphemeralMessage, ChatError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn open_modal<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _trigger_id: &'life1 str, _modal: &'life2 ModalElement, _context_id: Option<&'life3 str>, ) -> Pin<Box<dyn Future<Output = Result<String, ChatError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn start_typing<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _thread_id: &'life1 str, _status: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<(), ChatError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn upload_file<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _thread_id: &'life1 str, _file: &'life2 FileUpload, ) -> Pin<Box<dyn Future<Output = Result<SentMessage, ChatError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... }
}
Expand description

Extension point for chat platforms (Slack, Discord, CLI, etc.).

Each platform provides a concrete implementation. Required methods must be implemented; optional methods have sensible defaults that return ChatError::NotSupported.

§Object safety

The trait is object-safe and can be used as Box<dyn ChatAdapter>. Note that recv_event takes &mut self, so a shared reference (&dyn ChatAdapter) is insufficient for receiving events.

Required Methods§

Source

fn name(&self) -> &str

Short, unique name of this adapter (e.g. "slack", "discord").

Source

fn post_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, thread_id: &'life1 str, message: &'life2 AdapterPostableMessage, ) -> Pin<Box<dyn Future<Output = Result<SentMessage, ChatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Post a new message to the given thread.

Source

fn edit_message<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, thread_id: &'life1 str, message_id: &'life2 str, message: &'life3 AdapterPostableMessage, ) -> Pin<Box<dyn Future<Output = Result<SentMessage, ChatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Edit an existing message in the given thread.

Source

fn delete_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, thread_id: &'life1 str, message_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), ChatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Delete a message from the given thread.

Source

fn render_card(&self, card: &CardElement) -> String

Render a CardElement into the adapter’s native format string.

Source

fn render_message(&self, message: &AdapterPostableMessage) -> String

Render an AdapterPostableMessage into a plain-text or markup representation suitable for the adapter.

Source

fn recv_event<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Option<ChatEvent>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Wait for the next inbound ChatEvent.

Returns None when the event source is exhausted.

Provided Methods§

Source

fn stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, thread_id: &'life1 str, text_stream: TextStream, options: &'life2 StreamOptions, ) -> Pin<Box<dyn Future<Output = Result<SentMessage, ChatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Stream text progressively to a thread.

The default implementation uses fallback_stream which posts a placeholder and then repeatedly edits it as chunks arrive from the stream.

Source

fn add_reaction<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _thread_id: &'life1 str, _message_id: &'life2 str, _emoji: &'life3 EmojiValue, ) -> Pin<Box<dyn Future<Output = Result<(), ChatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Add a reaction emoji to a message.

Source

fn remove_reaction<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _thread_id: &'life1 str, _message_id: &'life2 str, _emoji: &'life3 EmojiValue, ) -> Pin<Box<dyn Future<Output = Result<(), ChatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Remove a reaction emoji from a message.

Source

fn open_dm<'life0, 'life1, 'async_trait>( &'life0 self, _user_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String, ChatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Open (or return an existing) direct-message channel with a user.

Returns the thread/channel ID of the DM.

Source

fn post_ephemeral<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _thread_id: &'life1 str, _user_id: &'life2 str, _message: &'life3 AdapterPostableMessage, ) -> Pin<Box<dyn Future<Output = Result<EphemeralMessage, ChatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Post a message visible only to the specified user.

Source

fn open_modal<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _trigger_id: &'life1 str, _modal: &'life2 ModalElement, _context_id: Option<&'life3 str>, ) -> Pin<Box<dyn Future<Output = Result<String, ChatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Open a modal dialog tied to the given trigger interaction.

Source

fn start_typing<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _thread_id: &'life1 str, _status: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<(), ChatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Show a typing / status indicator in the given thread.

Source

fn upload_file<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _thread_id: &'life1 str, _file: &'life2 FileUpload, ) -> Pin<Box<dyn Future<Output = Result<SentMessage, ChatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Upload a file to the given thread.

Implementors§