commodore 0.2.1

Slack Command API handler library
Documentation

commodore

Build Status Coverage Status Software License crates.io

call rank and take command of slack with rust at your helm

Commodore allows you to easily extend your Slack experience with Rust via Slack's Command API.

rust docs

Find them here

Install

Note this crate relies on hyper for handling http. You will want to include the following in your Cargo.toml file.

[dependencies]
commodore = "0.2"
hyper = "0.9"

usage

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

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