# commodore
[](https://travis-ci.org/softprops/commodore) [](https://coveralls.io/github/softprops/commodore?branch=master) [](LICENSE) [](https://crates.io/crates/commodore)
> call rank and take command of slack with rust at your helm
Commodore allows you to easily extend your [Slack](https://slack.com/) experience with [Rust](https://www.rust-lang.org/) via Slack's [Command API](https://api.slack.com/slash-commands).
[Documentation](https://softprops.github.io/commodore)
## Install
> Note: this crate relies on hyper for handling http. You will want to include the following in your `Cargo.toml` file.
```toml
[dependencies]
commodore = "0.3"
hyper = "0.10"
```
## usage
```rust
extern crate commodore;
extern crate hyper;
use commodore::{Captures, Command, Mux, Responder, Response};
use hyper::Server;
use std::thread;
use std::time::Duration;
pub fn main() {
let mut mux = Mux::new();
mux.command("/commodore", "secrettoken", |c: &Command,
_: &Option<Captures>,
responder: Box<Responder>|
-> Option<Response> {
println!("handler recv cmd {:#?}", c);
thread::spawn(move || {
// simulate doing something important
thread::sleep(Duration::from_secs(3));
responder.respond(Response::ephemeral("some time later"));
});
Some(Response::ephemeral("got it"))
});
let svc = Server::http("0.0.0.0:4567")
.unwrap()
.handle(mux)
.unwrap();
println!("listening on {}", svc.socket);
}
```
## responding
commodore supports a typed representation of slacks response structure. To
make creating instances of these convenient, builder instances are provided
```rust
extern crate commodore;
use commodore::{Attachment, Field, Response};
fn main() {
let response = Response::builder()
.text("hallo")
.in_channel()
.attach(
Attachment::builder()
.text("attached")
.color("red")
.field(
Field {
title: "foo".to_owned(),
value: "value".to_owned(),
short: false
}
)
.build()
).build();
println!("{:#?}", response);
}
```
Doug Tangren (softprops) 2016-2017