Giter Site home page Giter Site logo

slack-stuart's Introduction

#Stuart

Stuart is an extensible Slack Bot. Ready to take on any task that you've programmed. He's intended to be run as a separate Node service. Once configured within your Slack instance, he will listen to your wishes and do the best he can to service you.

With Stuart, you can create customized commands that you can from inside of Slack. For instance, ask for a local lunch spot:

/stuart food sushi

So you're hungry, @greg?

How about, Osaka House today? It has a Yelp rating of 2.5 / 5

http://www.yelp.com/biz/osaka-house-madison

505 State St

Stuart will also run automated tasks that happen in the background. For example, Stuart can let your team know what the weather forecast is every morning.

Today in Madison : Partly Cloudy, Current temp : 72 (41 / 72)

He also comes with an SMS interface which allows you to inject content into Slack with his persona. Your own little puppet with your team.

##Getting Started

  1. Configure your Slack Integrations
    1. Create a new slash command
    • Name the command /stuart
    • Set the URL to be http://yourhostname/slack
    • Method should be POST
    • Label should be Stuart or whatever you name it in your config file
    1. Create an Inbound Webhook
    • From the "Setup Instructions",
      • Copy the "Unique Webhook URL" from Slack into your config.js file
      • Copy the token from Slack into your config.js file
    • From the "Integration Settings"
      • Set the default channel you'd like (don't worry, Stuart can still post to any channel)
      • Set the bot name (Stuart)
      • Set the default bot avatar (also set in config.js)
  2. Update config.js in your server project
    1. host : should match the hostname where you've deployed Stuart
    2. slack_host : should match the Slack settings for your webhook
    3. slack_token : should match the Slack settings for your webhook

##Let it rip!

npm install
node slack-stuart.js

In your browser, visit:

http://localhost:8087

##Plugins Stuart is a pretty dumb by himself. But his future is bright. And it's in your hands. Plugin definitions are found in plugins/plugins.json.

By default, plugins that require configuration have their activation flag set to false. To enable them, update the "fixme" blocks and flip the activate property to true.

###Plugin Creation Plugins come in one of two forms - slash command instructions and Cron tasks.

####Slash Command - /stuart Integrate new commands directly into the /stuart slash command.

For example, this would call Stuart's random plugin from inside of Slack

/stuart random

To create a new slash instruction, you need to write two methods - run() and help() - and define the plugin details in the plugins.json spec. For example, the random command has the following configuration:

JSON spec :

  "random" : {
    "active" : true,
      "name"   : "Random number generator",
      "hook"   : "./plugins/slash/random",
      "author" : "greg",
      "config" : {}
  }
  • active is used enable/disable the plugin during server startup
  • name is used when users ask Stuart for help (/stuart help).
  • hook is the file which contains the plugin implementation.
  • author should match the Slack username so Stuart can notify the plugin author in the event the plugin is broken.
  • config is an object contains configuration parameters unique to the plugin integration. Check out some of the other plugins in package.json to see some configuration examples.

The code implemented in the "hook" file (in this case, ./plugins/slash/random) :

module.exports.run = function(request, stuart, plugin) {
    var num = Math.round(Math.random() * 100);
    stuart.slack_post(num.toString(), '#'+request.channel_name, request.user_name);
};

module.exports.help = function(request, stuart) {
 stuart.slack_post("Randomly picks a number between 0 and 100. Usage : '/stuart random'", '@'+request.user_name, request.user_name);
};

####Cron Tasks Automated activities that run on a fixed schedule. There is no interface from within Slack to drive this activity. All of it is driven externally and the results are pushed into Slack via the Incoming Webhook.

To create a Cron task, you need to write one method - register() - and define the cron details in the plugins.json spec. For example, the inspire task has the following configuration:

JSON spec :

"inspire" : {
    "active" : true,
  "name" : "Inspiring messages",
  "hook" : "./plugins/cron/inspire",
  "author" : "greg",
  "config" : {}
}

The code implemented in the "hook" file (in this case, ./plugins/cron/inspire) :

var cronJob = require('cron').CronJob;
var Stuart = require('../stuart');

// in this example, positive_quote() is another internal function not shown here
var cronTask = function() {
    Stuart.slack_post("_"+positive_quote()+"_", '#general');
};

module.exports.register = function() {
    // 8:00am every Monday.
    new cronJob('43 7 * * 1', cronTask, null, true, "America/Chicago");
};

###Tips for Testing An easy way to test your integrations is to simply fire up a new instance of Slack. It's free and you can setup the slash command in inbound webook integrations just like you would with your production Slack instance.

If you're running on a localhost during test, you can use a tool like ngrok to tunnel requests with a public hostname.

slack-stuart's People

Contributors

gtracy avatar mabermoske avatar

Watchers

 avatar

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.