/commander-template

GitHub Template to kick-start your Nimbella command set development.

Primary LanguageJavaScript

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