Use this template to kick-start your command set development.
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
- Fork a copy of this repo into your account.
- Clone the repo locally as
currency
or rename it tocurrency
after cloning. - Open
commands.yaml
and edit it to reflectcurrency
command-set containingconverter
command. - Your
commands.yaml
might look like this:
commands:
currency:
description: Convert currency from one to other
- Now we want to add 2 mandatory params to our command which is
from
andto
, ourcommands.yaml
is going to look like this:
commands:
currency:
description: Convert currency from one to other
parameters:
- name: from
- name: to
- Next, we need to rename files. So under packages directory, rename
hello
tocurrency
- Under
currency
directory, renamehello.js
toconverter.js
- 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 theconverter
code 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
};
- You can then install your command-set by running the following command
/nc csm_install github:user/currency
- You can run the converter command with
/nc converter
- You can make changes on the online editor with
/nc command_code converter
- Make sure you commit any changes to your github command-set. The changes can updated with
/nc csm_update currency
- 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