Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.69 KB

File metadata and controls

56 lines (42 loc) · 1.69 KB

How to add your Hear.

Create under src/hears a js file. You can use src/hears/test.js as example.

Your module MUST export 2 properties and 1 function.
It MAY also export the following properties:
  • init: (optional) This function will be called with controlle (botkit bot controller for donramos) and db (jfs module storage object). This function is called before registering the hear, so you may you use to interact with the controller and the data storage to retrieve data needed for your hear callback.
  • usage: Explains how to use your hear.
  • whatItDoes: Explains what your hear does.
Example
let config = require('../config');

module.exports = {
    init: init,
    msg: '(test)*'+'(.*)',
    env: config.HEAR_ENVS.MENTION_AND_DIRECT,
    usage: '@donramos quien va a [tu accion]',
    whatItDoes: 'Elige un presente en RG aleatoriamiente para hacer lo que indiques',
    responseCallback: responseCallback
};

let enteradoCount = 0;
let usersInRG = [];

function init(controller, db) {
    db.get('usersInRG')
        .then(function(users){
            usersInRG = users;
        });
}

function responseCallback(bot, message) {
    if (enteradoCount > 2) {
        bot.reply(message, "Hay, creo que le habla a Ud.!");
        enteradoCount = 0;
    } else {
        bot.reply(message, "Enterado!");
        enteradoCount++;
    }
}