pub struct ChatBot { /* private fields */ }Expand description
Implementations§
Source§impl ChatBot
impl ChatBot
Sourcepub fn new(config: ChatBotConfig) -> Self
pub fn new(config: ChatBotConfig) -> Self
Create a new ChatBot with the given configuration.
Sourcepub fn add_adapter(&mut self, adapter: impl ChatAdapter + 'static)
pub fn add_adapter(&mut self, adapter: impl ChatAdapter + 'static)
Add a chat platform adapter.
Sourcepub fn on_mention<F, Fut>(&mut self, handler: F)where
F: Fn(ThreadHandle, IncomingMessage) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
pub fn on_mention<F, Fut>(&mut self, handler: F)where
F: Fn(ThreadHandle, IncomingMessage) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
Register a handler invoked when the bot is mentioned.
Sourcepub fn on_message<F, Fut>(&mut self, pattern: Option<String>, handler: F)where
F: Fn(ThreadHandle, IncomingMessage) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
pub fn on_message<F, Fut>(&mut self, pattern: Option<String>, handler: F)where
F: Fn(ThreadHandle, IncomingMessage) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
Register a handler for incoming messages.
If pattern is Some, only messages whose text contains the
substring will trigger the handler.
Sourcepub fn on_subscribed_message<F, Fut>(&mut self, handler: F)where
F: Fn(ThreadHandle, IncomingMessage) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
pub fn on_subscribed_message<F, Fut>(&mut self, handler: F)where
F: Fn(ThreadHandle, IncomingMessage) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
Register a handler for messages in threads the bot has subscribed to.
Sourcepub fn on_action<F, Fut>(&mut self, action_ids: Option<Vec<String>>, handler: F)where
F: Fn(ActionEvent, ThreadHandle) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
pub fn on_action<F, Fut>(&mut self, action_ids: Option<Vec<String>>, handler: F)where
F: Fn(ActionEvent, ThreadHandle) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
Register a handler for interactive action events.
If action_ids is Some, only actions whose action_id is in the
list will trigger the handler.
Sourcepub fn on_reaction<F, Fut>(
&mut self,
emojis: Option<Vec<EmojiValue>>,
handler: F,
)
pub fn on_reaction<F, Fut>( &mut self, emojis: Option<Vec<EmojiValue>>, handler: F, )
Register a handler for reaction events.
If emojis is Some, only reactions matching one of the listed
emoji values will trigger the handler.
Sourcepub fn on_slash_command<F, Fut>(
&mut self,
commands: Option<Vec<String>>,
handler: F,
)
pub fn on_slash_command<F, Fut>( &mut self, commands: Option<Vec<String>>, handler: F, )
Register a handler for slash-command events.
If commands is Some, only commands whose name matches one of the
listed strings will trigger the handler.
Sourcepub fn on_modal_submit<F, Fut>(
&mut self,
callback_ids: Option<Vec<String>>,
handler: F,
)
pub fn on_modal_submit<F, Fut>( &mut self, callback_ids: Option<Vec<String>>, handler: F, )
Register a handler for modal-submit events.
If callback_ids is Some, only submissions whose callback_id
matches one of the listed strings will trigger the handler.
Sourcepub fn on_modal_close<F, Fut>(&mut self, handler: F)
pub fn on_modal_close<F, Fut>(&mut self, handler: F)
Register a handler for modal-close (dismiss) events.
Sourcepub async fn run(&mut self) -> Result<(), ChatError>
pub async fn run(&mut self) -> Result<(), ChatError>
Start the event dispatch loop.
This method takes ownership of the stored adapters via &mut self,
polls each adapter’s recv_event in a
round-robin fashion using futures_util::stream::select_all, and
dispatches every incoming ChatEvent to the registered handlers.
The loop terminates when all adapters return None (i.e. their
event sources are exhausted).
§Errors
Returns Err(ChatError::Closed) if no adapters have been registered.