Skip to main content

Channel

Trait Channel 

Source
pub trait Channel: Send + Sync {
    // Required methods
    fn id(&self) -> &ChannelId;
    fn caps(&self) -> &ChannelCaps;
    fn run<'life0, 'async_trait>(
        &'life0 self,
        sink: Arc<dyn InboundSink>,
        shutdown: CancellationToken,
    ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn send<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        to: &'life1 ReplyTarget,
        message: &'life2 RenderedMessage,
    ) -> Pin<Box<dyn Future<Output = Result<SentRef, ChannelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn edit<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _sent: &'life1 SentRef,
        _message: &'life2 RenderedMessage,
    ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn typing<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _to: &'life1 ReplyTarget,
    ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn prompt<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _to: &'life1 ReplyTarget,
        _prompt: &'life2 Prompt,
    ) -> Pin<Box<dyn Future<Output = Result<SentRef, ChannelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn close_prompt<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _sent: &'life1 SentRef,
        _message: &'life2 RenderedMessage,
        _keep_buttons: bool,
    ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn open_direct<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _user: &'life1 UserId,
    ) -> Pin<Box<dyn Future<Output = Result<ConversationKey, ChannelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn set_commands<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _commands: &'life1 [CommandInfo],
    ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn webhook(&self) -> Option<Arc<dyn WebhookHandler>> { ... }
}
Expand description

A chat platform adapter (design §3.2).

A channel receives events (through Channel::run or a WebhookHandler) and sends replies. It knows nothing about agents or knowledge.

Required Methods§

Source

fn id(&self) -> &ChannelId

The configured instance, for example zalo:shop.

Source

fn caps(&self) -> &ChannelCaps

What the platform supports.

Source

fn run<'life0, 'async_trait>( &'life0 self, sink: Arc<dyn InboundSink>, shutdown: CancellationToken, ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Receives events until shutdown is cancelled, delivering them to sink.

Polling and socket platforms loop here and reconnect on their own. Webhook platforms may only do start-up work (such as registering the webhook) and then wait for shutdown. Returning an error stops this channel only.

Source

fn send<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, to: &'life1 ReplyTarget, message: &'life2 RenderedMessage, ) -> Pin<Box<dyn Future<Output = Result<SentRef, ChannelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Sends one message.

Provided Methods§

Source

fn edit<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _sent: &'life1 SentRef, _message: &'life2 RenderedMessage, ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Replaces the text of a sent message. Only called when ChannelCaps::edit is true.

Source

fn typing<'life0, 'life1, 'async_trait>( &'life0 self, _to: &'life1 ReplyTarget, ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Shows a typing indicator once. The runtime repeats it while an agent works.

Source

fn prompt<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _to: &'life1 ReplyTarget, _prompt: &'life2 Prompt, ) -> Pin<Box<dyn Future<Output = Result<SentRef, ChannelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Shows a prompt (a message with buttons) in a conversation. Answers come back through InboundSink::answer. Platforms without buttons return ChannelError::Unsupported.

Source

fn close_prompt<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _sent: &'life1 SentRef, _message: &'life2 RenderedMessage, _keep_buttons: bool, ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Replaces a prompt’s text and removes its buttons (answered, cancelled or expired). With keep_buttons, only the text changes and the prompt can be answered again.

Source

fn open_direct<'life0, 'life1, 'async_trait>( &'life0 self, _user: &'life1 UserId, ) -> Pin<Box<dyn Future<Output = Result<ConversationKey, ChannelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The direct chat with user, opened if needed, for messages the bot starts (notifications) to someone who has not written to it yet. Platforms whose bots cannot start a direct chat, or need an extra permission for it, return ChannelError::Unsupported; the runtime then only uses direct chats it has already seen.

Source

fn set_commands<'life0, 'life1, 'async_trait>( &'life0 self, _commands: &'life1 [CommandInfo], ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Lists the bot’s commands in the platform’s command menu. Called once, before Channel::run, and only when the bot has commands of its own. Commands always arrive as text messages starting with /name: platforms whose menu sends something else (Discord’s slash commands) turn it into such a message. Platforms without a menu ignore this.

Source

fn webhook(&self) -> Option<Arc<dyn WebhookHandler>>

The webhook endpoint, for platforms that push events over HTTP.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§