GithubHelp home page GithubHelp logo

brh55 / generator-spark-bot Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 69 KB

:zap: Yeoman generator that scaffold out a Cisco spark bot with usability and simplicity in mind

License: MIT License

JavaScript 100.00%
cisco cisco-spark yeoman flint scaffold nodejs spark

generator-spark-bot's Introduction

generator-spark-bot Travis XO code style

generator-spark-bot is a yeoman generator that scaffolds out a node Cisco Spark bot following an event-driven fashion, and is extremely easy to get started with.

trigger context => callback()

Designed with simplicity and usability in mind:

  • Fast to get started, just drop a .js file within /commands and your bot will register a listener on start
  • Easier unit testing with access to commands' private methods
  • Includes Flint for a more robust framework

Usage

Ensure yeoman is is installed:

npm install -g yo or yarn global add yo

After yeoman is installed:

$ mkdir project-name
$ cd project-name
$ yo spark-bot

App Structure

.
├── commands                  # Event handlers are within the commands
│   └── example.js            # An example command for reference
├── app.js                    # Bot entry point
├── config.js                 # Configurations
├── test.js                   # AVA Test
├── readme.md
├── license
└── package.json

Commands

Commands will instruct the bot on when and how to respond to particular contextual triggers.

To add a command, simply add a .js file within the commands directory. When the bot is initializing, commands will automatically register with Flint at runtime.

These command must implement an interface that contains a trigger property and a callback method. Refer to example.js within the commands directory.

trigger | <RegEx>, <string>

The contextual trigger that will cause the bot to execute the callback upon matches.

callback | <function>

The function to be executed (event handler).

Command Sub-generator

yo spark-bot:command

For convenience, the :command sub-generator will generate a new command within the /commands directory.

Scripts

  • npm run test - Run linter and unit test
  • npm start - Start the bot
  • npm run debug - Activate debugging to log

Unit Testing

Unit testing is straightforward, simple, and already configured with the AVA test runner. Commands are accessible through the fileName as a property of the commands object. Thus, any command callbacks can be tested as such: commands.fileName.callback.

In addition, the rewire module is pre-configured to test private methods and is easily accessible without the need of exporting any private methods. This is done with the __get__() method. IE: commands.example.__get__('buildExampleMessage').

Tech Dependencies

Test Runner

  • AVA - 🚀 Futuristic JavaScript test runner

Linter

  • XO - JavaScript happiness style linter

Framework

  • Express - Fast, unopinionated, minimalist web framework for node.
  • Flint - Cisco Spark Bot SDK for Node JS

License

MIT © Brandon Him

generator-spark-bot's People

Contributors

brh55 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

yeoman-projects

generator-spark-bot's Issues

add command sub generator

Looking to add an command sub generator:

  • Allow users to run yo spark-bot:command --props
  • Scaffold out a new command in current directory following command interface

Botkit Support

Looking to add a level of Botkit support to this generator, open to anyone to tackle.

Testing

Need to fully test out everything, still in the works and haven't had time to validate everything just quite yet.

Checklist:
✅ Scaffold and run
=> Example should show up

❔ Add a new command with regex
=> Command should run

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.