all files / botmaster-fulfill-actions/ pause.js

100% Statements 10/10
100% Branches 2/2
100% Functions 0/0
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31                                    18× 18× 18× 18× 18×        
/**
 *  Break text up with a separate messages pausing before each one
 *  ```xml
 *  <pause wait=2000 />
 *  ```
 *  evaluated in series
 *  after evaluating all text / xml before removed
 *  controller sends text before and then waits before allowing rest of text/xml to be evaluated
 *  @param wait {String} how long to wait in ms between each defaults to 1000
 *  @module pause
 */
 
const R = require('ramda');
 
const DEFAULT_WAIT = 1000;
 
const spec = {
    series: true,
    evaluate: 'step',
    replace: 'before',
    controller: (params, cb) => {
        const newMessage = R.clone(params.update);
        newMessage.message.text = params.before;
        params.bot.sendMessage(newMessage);
        const wait = R.isNil(params.attributes.wait) ? DEFAULT_WAIT : Number(params.attributes.wait);
        setTimeout(() => cb(null, ''), wait);
    }
};
 
module.exports = spec;