Skip to main content

FakeChannel

Struct FakeChannel 

Source
pub struct FakeChannel { /* private fields */ }
Expand description

A Channel for tests: events are injected by the test, sent messages are recorded.

Implementations§

Source§

impl FakeChannel

Source

pub fn new(id: &str, caps: ChannelCaps) -> Self

A channel id (fake:test) with caps.

Source

pub fn without_buttons(self) -> Self

Like a platform without buttons: prompts are okbot_core::ChannelError::Unsupported.

Source

pub fn opening_direct_chats(self) -> Self

Lets Channel::open_direct open a direct chat with anyone, as room dm-<user id> (Discord, Telegram); without it the call is unsupported.

Source

pub async fn inject(&self, event: InboundEvent)

Waits until the runtime started this channel, then delivers event.

Source

pub fn sent_texts(&self) -> Vec<String>

Texts sent so far, oldest first.

Source

pub fn sent(&self) -> Vec<(ReplyTarget, String)>

Messages sent so far with their targets.

Source

pub fn edits(&self) -> Vec<(String, String)>

Edits so far: (message id, new text).

Source

pub fn prompts(&self) -> Vec<Prompt>

Prompts shown so far, oldest first.

Source

pub fn prompt_updates(&self) -> Vec<(String, String, bool)>

Prompt updates so far: (message id, text, buttons kept).

Source

pub async fn answer(&self, answer: PromptAnswer)

Delivers an answer to a prompt, as a click would.

Source

pub fn typing_count(&self) -> usize

Typing indicators shown so far.

Trait Implementations§

Source§

impl Channel for FakeChannel

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. Read more
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 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.
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 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 set_commands<'life0, 'life1, 'async_trait>( &'life0 self, _commands: &'life1 [CommandInfo], ) -> Pin<Box<dyn Future<Output = Result<(), ChannelError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: '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.
Source§

impl Debug for FakeChannel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.