Crate matrix_bot_api[−][src]
matrix_bot_api
Easy to use API for implementing your own Matrix-Bot (see matrix.org)
Basic setup:
There are two parts: A MessageHandler and the MatrixBot. The MessageHandler defines what happens on received messages The MatrixBot consumes your MessageHandler and deals with all the matrix-protocol-stuff, calling your MessageHandler for each new text-message.
You can write your own MessageHandler by implementing the MessageHandler
-trait,
or use one provided by this crate (currently only StatelessHandler
).
Example
extern crate matrix_bot_api; use matrix_bot_api::{MatrixBot, MessageType}; use matrix_bot_api::handlers::StatelessHandler; fn main() { let mut handler = StatelessHandler::new(); handler.register_handle("shutdown", |bot: &MatrixBot, _room: &str, _cmd: &str| { bot.shutdown(); }); handler.register_handle("echo", |bot: &MatrixBot, room: &str, cmd: &str| { bot.send_message(&format!("Echo: {}", cmd), room, MessageType::TextMessage); }); let mut bot = MatrixBot::new(handler); bot.run(&user, &password, &homeserver_url); }
Have a look in the examples/ directory for detailed examples.
Modules
handlers |
Structs
MatrixBot |
Enums
MessageType |
How messages from the bot should be formated. This is up to the client, but usually RoomNotice's have a different color than TextMessage's. |