6 releases

Uses old Rust 2015

0.3.0 Apr 26, 2017
0.2.2 Oct 21, 2016
0.1.1 Feb 19, 2016

#37 in #slack

24 downloads per month

MIT license

27KB
669 lines

commodore

Build Status Coverage Status Software License

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.

Documentation

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.3"
hyper = "0.10"

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-2017

Dependencies

~13–24MB
~388K SLoC