Coder Social home page Coder Social logo

commander-template's Introduction

Nimbella Commander Template

Use this template to kick-start your command set development.

Creating Currency Command-set using the template

Let's assume you want to create a currency command-set with 1 command, converter which converts one currency to another. We can do this by following the following steps

  1. Fork a copy of this repo into your account.
  2. Clone the repo locally as currency or rename it to currency after cloning.
  3. Open commands.yaml and edit it to reflect currency command-set containing converter command.
  4. Your commands.yaml might look like this:
commands:
  currency:
    description: Convert currency from one to other
  1. Now we want to add 2 mandatory params to our command which is from and to, our commands.yaml is going to look like this:
commands:
  currency:
    description: Convert currency from one to other
    parameters:
      - name: from
      - name: to
  1. Next, we need to rename files. So under packages directory, rename hello to currency
  2. Under currency directory, rename hello.js to converter.js
  3. Edit converter.js to add the currency convertor logic. Once this is done, save the file and commit all the contents and push the changes to your repo. This is what the convertercode might look like:
async function install(pkgs) {
  pkgs = pkgs.join(' ');
  return new Promise((resolve, reject) => {
    const { exec } = require('child_process');
    exec(`npm install ${pkgs}`, (err, stdout, stderr) => {
      if (err) reject(err);
      else resolve();
    });
  });
}

async function _command(params, commandText, secrets = {}) {
  const {
    from,
    to
  } = params;

  let packages = [ 'exchange-rates-api' ];
  await install(packages);

  const { convert } = require('exchange-rates-api');
  let amount = await convert(1, from, to);

  return {
    response_type: 'in_channel', // or `ephemeral` for private response
    text: '1 ' + from + ' is equal to ' + amount + ' ' + to
  };
  1. You can then install your command-set by running the following command /nc csm_install github:user/currency

Running & Debugging your command-set

  1. You can run the converter command with /nc converter
  2. You can make changes on the online editor with /nc command_code converter
  3. Make sure you commit any changes to your github command-set. The changes can updated with /nc csm_update currency
  4. Any logs you add within the command can be seen by running /nc activation_log after running your command. This might help in fixing bugs

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.