[−][src]Crate vk_bot
Crate for creating chat bots for VK (VKontakte) communities.
You can see Core
documentation for information on how to
define bot behavior. In particular, make sure to take a look
at Core::on
first.
Example
The following example is from
examples/basic.rs
.
It is not tested here as Bot::start
never returns.
ⓘThis example is not tested
use vk_bot::{ keyboard::{Button, Color, Keyboard}, Bot, Core, Event, Handler, Tester, }; fn main() { // A simple closure for convenience... let simple_handler = |message| { // ...that returns a handler! Handler::new(move |ctx| { ctx.response().set_message(message); eprintln!("{:#?}", ctx.send()); }) }; // Create a keyboard. let kbd = Keyboard::new( vec![vec![ Button::new("A", Color::Primary, None), Button::new("B", Color::Default, Some(r#"{"a": "b"}"#.into())), ]], false, ); let core = Core::new() .cmd_prefix("/") .cmd( "keyboard", Handler::new(move |ctx| { ctx.response().set_message("Here you go:"); ctx.response().set_keyboard(kbd.clone()); eprintln!("{:#?}", ctx.send()); }), ) .regex("nice", simple_handler("Thanks!")) .on(Event::NoMatch, simple_handler("I don't understand...")) .payload(r#"{"a":"b"}"#, simple_handler("You pressed button B!")) // accept all remaining payloads! .dyn_payload(Tester::new(|_| true), simple_handler("Received a payload!")); Bot::new( "your vk token", // VK token "f123456", // Confirmation token (from Callback API settings) 1, // Group ID "very_secure_phrase", // Secret (from Callback API settings) 12345, // Port core, ) .start(); }
Re-exports
pub use crate::bot::Bot; |
pub use crate::context::Context; |
pub use crate::core::Core; |
pub use crate::core::Event; |
pub use crate::core::Handler; |
pub use crate::core::Tester; |
Modules
bot | The |
context | The |
core | The |
keyboard | Keyboards. |
request | Structs for storing request information. |
response | Structs for storing response information. |
Macros
rocket_uri_macro_get | Rocket code generated wrapping URI macro. |
rocket_uri_macro_post | Rocket code generated wrapping URI macro. |