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
impl FakeChannel
Sourcepub fn new(id: &str, caps: ChannelCaps) -> Self
pub fn new(id: &str, caps: ChannelCaps) -> Self
A channel id (fake:test) with caps.
Like a platform without buttons: prompts are okbot_core::ChannelError::Unsupported.
Sourcepub fn opening_direct_chats(self) -> Self
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.
Sourcepub async fn inject(&self, event: InboundEvent)
pub async fn inject(&self, event: InboundEvent)
Waits until the runtime started this channel, then delivers event.
Sourcepub fn sent_texts(&self) -> Vec<String>
pub fn sent_texts(&self) -> Vec<String>
Texts sent so far, oldest first.
Sourcepub fn sent(&self) -> Vec<(ReplyTarget, String)>
pub fn sent(&self) -> Vec<(ReplyTarget, String)>
Messages sent so far with their targets.
Sourcepub fn prompt_updates(&self) -> Vec<(String, String, bool)>
pub fn prompt_updates(&self) -> Vec<(String, String, bool)>
Prompt updates so far: (message id, text, buttons kept).
Sourcepub async fn answer(&self, answer: PromptAnswer)
pub async fn answer(&self, answer: PromptAnswer)
Delivers an answer to a prompt, as a click would.
Sourcepub fn typing_count(&self) -> usize
pub fn typing_count(&self) -> usize
Typing indicators shown so far.
Trait Implementations§
Source§impl Channel for FakeChannel
impl Channel for FakeChannel
Source§fn caps(&self) -> &ChannelCaps
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,
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,
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,
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,
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,
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,
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,
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,
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,
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.Auto Trait Implementations§
impl !Freeze for FakeChannel
impl RefUnwindSafe for FakeChannel
impl Send for FakeChannel
impl Sync for FakeChannel
impl Unpin for FakeChannel
impl UnsafeUnpin for FakeChannel
impl UnwindSafe for FakeChannel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more