Giter Site home page Giter Site logo

commodore's Introduction

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.

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

commodore's People

Contributors

softprops avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

commodore's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.