all files / dist/ pause.js

92.86% Statements 13/14
66.67% Branches 4/6
100% Functions 3/3
92.86% Lines 13/14
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                          21×         21× 21× 21×     21× 21× 21×          
'use strict';
 
/**
 *  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
 *  if the bot implements typing a typing status is sent between pauses.
 *  @param wait {String} how long to wait in ms between each defaults to 1000
 *  @module pause
 */
 
var R = require('ramda');
 
var DEFAULT_WAIT = 1000;
var lensImplementsTyping = R.lensPath(['implements', 'typing']);
var lensId = R.lensPath(['sender', 'id']);
 
var spec = {
    series: true,
    evaluate: 'step',
    replace: 'before',
    controller: function controller(_ref, cb) {
        var before = _ref.before,
            bot = _ref.bot,
            attributes = _ref.attributes,
            update = _ref.update;
 
        console.log(before);
        bot.reply(update, before, { __update: update }).then(function () {
            Iif (R.view(lensImplementsTyping, update) && R.view(lensId, bot)) {
                bot.sendIsTypingMessageTo(R.view(lensId, update), { ignoreMiddleware: true });
            }
            var wait = R.isNil(attributes.wait) ? DEFAULT_WAIT : Number(attributes.wait);
            setTimeout(function () {
                return cb(null, '');
            }, wait);
        });
    }
};
 
module.exports = spec;