Skip to main content

Channel

Trait Channel 

Source
pub trait Channel: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn start<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Receiver<IncomingMessage>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn send<'life0, 'async_trait>(
        &'life0 self,
        message: OutgoingMessage,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stop<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn send_typing<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _chat_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn send_media<'life0, 'async_trait>(
        &'life0 self,
        media: OutgoingMedia,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn supports_media(&self) -> bool { ... }
    fn edit<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        _chat_id: &'life1 str,
        _message_id: &'life2 str,
        _new_text: &'life3 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn as_draft(&self) -> Option<&dyn DraftChannel> { ... }
}
Expand description

The core Channel trait. Implement for each messaging platform (Telegram, Discord, CLI, WebSocket, etc.)

Required Methods§

Source

fn name(&self) -> &str

Channel name (e.g., “telegram”, “discord”, “cli”)

Source

fn start<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Receiver<IncomingMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start receiving messages. Returns a receiver for incoming messages.

Source

fn send<'life0, 'async_trait>( &'life0 self, message: OutgoingMessage, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a message through this channel. Returns an optional message ID for tracking/editing.

Source

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

Stop the channel gracefully.

Provided Methods§

Source

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

Send a typing indicator (or equivalent) to the user.

Source

fn send_media<'life0, 'async_trait>( &'life0 self, media: OutgoingMedia, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send an attachment.

The default errors rather than silently degrading to a text message with a URL in it: a caller that asked for a picture and got a link back has been lied to. Channels that can carry media override this.

Source

fn supports_media(&self) -> bool

Whether send_media will do anything for this channel. Callers that can fall back to text should check this instead of sending and catching.

Source

fn edit<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _chat_id: &'life1 str, _message_id: &'life2 str, _new_text: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Edit a previously sent message if the channel supports it.

Source

fn as_draft(&self) -> Option<&dyn DraftChannel>

Live draft support, if this channel implements it.

Returning Some is the only way to opt into draft delivery, and DraftChannel has no default methods, so opting in forces a real finalize_draft.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§