[][src]Crate vk_bot

Crate for creating chat bots for VK (VKontakte) communities.

note: this crate requires nightly Rust because of Rocket.

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.

Examples

Examples are available in the examples folder:

Basic example

The following example is taken from examples/basic.rs. It is not tested as a doc test because Bot::start never returns.

This example is not tested
use regex::Regex;
use vk_bot::{Bot, Core, Event, Handler};

fn main() {
    // A simple closure for convenience...
    let simple_handler = |message| {
        // ...that returns a handler!
        Handler::new(move |ctx| {
            // Set the message...
            ctx.response().set_message(message);

            // ...and send it, printing the error if not successful.
            eprintln!("{:?}", ctx.send());
        })
    };

    let core = Core::new()
        // Set prefix for commands (defined via `cmd`):
        .cmd_prefix("/")
        // Command that will be used if message contains `/say_hi` (without quotes) in the beginning:
        .cmd("say_hi", simple_handler("Hi!"))
        // Will be used if message contains `nice` in it:
        .regex(Regex::new("nice").unwrap(), simple_handler("Thanks!"))
        // Will be used if the bot doesn't know how to respond:
        .on(
            Event::NoMatch,
            simple_handler("I don't understand this message..."),
        );

    Bot::new(
        "your vk token",                   // VK token
        "f123456",                         // Confirmation token (from Callback API settings)
        1,                                 // Group ID
        Some("very_secure_phrase".into()), // 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 Bot struct and server setup.

context

The Context struct.

core

The Core struct, supported Events, and handler / tester types.

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.