0.0.6 • Published 8 years ago

generator-slack-bot v0.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

About Slack bot Yeoman Generator

Full Yeoman Generator to create Slack Bot with travis, coveralls and test.

Installation

First, install Yeoman and generator-slack-bot using npm (we assume you have pre-installed node.js).

npm install -g yo
npm install -g generator-slack-bot

Then generate your new Bot:

yo slack-bot

Which will generate the following project structure, if for example your bot name is Mazinga:

├── travis.yml
├── gitignore
├── jscsrc
├── LICENSE
├── README.md
├── app.json
├── package.json
├── Gruntfile.js
├── configBot.json
├── grunt/coveralls.js
├── grunt/jscs.js
├── grunt/jshint.js
├── grunt/mocha_istanbul.js
├── grunt/mochaTest.js
├── src/slackMessageAnalyzer.js
├── src/main.js
├── src/botMazinga.js
├── test/botMazinga.spec.js
└── test/mockoBjects/channel.js

And run npm install for you to fetch all dependencies.

Getting Started with the bot

In order to make the bot works you need a TOKEN_SLACK. Your Slack bot integration token is obtainable at https://my.slack.com/services/new/bot. After you have obtained your TOKEN_SLACK copy it in the configBot.json

Main chunk of codes to understand in the generated bot

  1. slackMessageAnalyzer.js

    In this class you are going to find all the utility in order to analyzer the slack message

ClassMethodParametersDescription
slackMessageAnalyzer.jscreateSlackMessageLink(titleLink, link)@param {Boolean} @param {String} titleLink text to show instead of the pure URL @param {String} link to redirectCreate a slack link format message
slackMessageAnalyzer.jscreateSlackMessageLink(titleLink, link)@param {String} textMessage message to analyze @param {String} textToSearch text to search in the messageCreate a slack link format message isTextContainedInMessage
  1. yourBotName.js

    In this class there are the listeners for the messages

ClassMethodParametersDescription
yourBotName.js_listenerMessage(condition, callback)@param {Boolean} condition to meet to call the callback @param {Function} callback to call if the condition is satisfiedCall a callback in the case a message from slack meets the condition

Code Example

This pice of code below will activate a listner on the hello message and will answer in the general chat wit a mssage 'Hello Answer'

   _listenerHelloMessage() {
    this._listenerMessage(this.isHelloMessage, (function(message) {
      var message = 'Hello answer';
      var fallBack = 'Hello answer';
      var color = 'warning';
      var title = 'Hello Answer ' + slackMessageAnalyzer.createSlackMessageLink('made by slack bot generator','https://github.com/eromano/generator-slack-bot');

      this.postSlackMessage(message, fallBack, color, null, title, '', 'general');
    }).bind(this));
  }
  
  isHelloMessage(textMessage) {
    return slackMessageAnalyzer.isTextContainedInMessage(textMessage, 'hello');
  }

History

For detailed changelog, see Releases.

Contributors

ContributorGitHub profileTwitter profile
Eugenio Romano (contributor)Eugenio Romano@RomanoEugenio

All contributors contributors.

License

MIT