Skip to content

Latest commit

 

History

History
359 lines (230 loc) · 6.71 KB

File metadata and controls

359 lines (230 loc) · 6.71 KB

Coding Cougs


Hackathon!

“A hackathon, a hacker neologism, is an event when programmers meet to do collaborative computer programming.” -Wikipedia

Note: Hackathon definition


alt text


What is Slack?

Slack is a team communication tool, that makes collaboration and messaging easy.

  • Channels
  • Direct Messages
  • Share files
  • Search
  • Integration

Slackbots: Why

  • A cool project to learn something new!
  • Very helpful for those that use Slack as their primary form of communication

alt text


Slackbots: What

Slackbots are useful bots that can be programmed to fufill a multitude of functions

  • Be the HR representative and answer common questions
  • Personal secretary for reminders, deadlines, and possibly
  • Respond to custom messages
  • Link users to integrated applications

Node JS & JavaScript

  • Node.js - "Node.js is an open-source, cross-platform JavaScript run-time environment for executing JavaScript code server-side."-Wikipedia
  • JavaScript - "JavaScript (JS) is a lightweight interpreted or Just In Time-compiled programming language with first-class functions."

First-Class Function


Install Node.js and NPM

Open the terminal

  • To install node
brew install node
  • To see if Node is installed
node -v
  • To see if NPM is installed
npm -v

Note: How to install Node and NPM


Install Node.js and NPM alt.

Go to the link provided


Create a node project

  • Create a package.json file
npm init
  • Create a new file called index.js
touch index.js
  • Add print statement to your index.js file
console.log('Hello World');
  • Run your application!
node index.js

Note: Create a hello world node project


Install a package

  • Install dependencies in the node module
npm install express
  • Print Hello World in your browser
var express = require('express')
var app = express()
 
app.get('/', function (req, res) {
  res.send('Hello World')
})
 
app.listen(3000)

Note: Create a hello world node project that runs on a server


Test your application

  • Run your application!
node index.js
  • In your browser go to

http://localhost:3000

Note: Test Application


Slack API

  • Provides Node-Style Callbacks
    • RTM and Web API
  • Powerful Low Level API
    • Allows you the creator to use parts of the API surface that you want to use without the entire payload.
    • Methods match Slack's API documentation
  • Install
npm install slack

Note: This Slack API is a thin wrapper


Slack API setup

  • Probably defined at the beginning of the file
var slack = require('slack');
var   bot = slack.rtm.client();

Note: Obtains a username our of a user id


Reaction Bot


// start listening to the slack team associated to the token 
bot.listen({token:token})

// on RTM message event
bot.message(function(msg){ 

    var      name = 'thumbsup';  // Select Emoji
    var   channel = msg.channel; // Grab the channel the message was received from
    var timestamp = msg.ts       // Grab the timestamp of the message
    var    params = {token, name, channel, timestamp} // create a parameter object

    slack.reactions.add(params, (err, data) => {       // Use Slack Web API Node Style

        if(err){
            console.log("Error: ",err); // Will Print Error
        } else {
            console.log("Success: Added Reaction"); // Will Print Success
        }

     });
});

Note: Obtains a username our of a user id ** Change the font size on this slide...


Slack API Documentation

Note: Haiden ~~~ Resources and Documentation


node-slack-upload

  • Uploading can be tricky, node-slack-upload makes it easy!
  • Provides support for multipart and content variables
  • Install
npm install node-slack-upload

Note: Haiden


node-slack-upload Setup

  • Probably defined at the beginning of the file
var Slack_Upload = require('node-slack-upload');
var           fs = require('fs');
var    _upLoader = new Slack_Upload(token);

Note: Haiden


Upload Bot

_upLoader.uploadFile({
       file: fs.createReadStream('file_path'), // open a File
       channels: message.channel               // the channel id you with to upload too
       }, function(err, data) {                // callback
             if (err) {
                    console.error(err);        // error happened
              }
            else {
                    console.log('Successfully uploaded files'); // success 
              }
    });

Note: Haiden


slack-node-upload Documentation

Note: Haiden ~~~ Resources and Documentation


Botkit

  • Botkit is a simple library to build bots for slack.
  • Very simple to use.
  • Botkit is node based and it allows to utilize any node package to get any functionality.
  • Botkit allows you to hear, reply, and have multi-message conversations.

Botkit Documentation


Heroku


Still Feeling Lost?


Text Editors


Coding Cougs on GitHub


Coding Cougs on Slack


Questions?

Thank you.

Note: speaker notes FTW!