All files / botbuilder-unit/src/messages SetDialogMessage.js

100% Statements 20/20
100% Branches 4/4
100% Functions 8/8
100% Lines 20/20
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      2x   2x     14x   14x 14x     2x 2x   2x 14x 14x     2x 14x 14x   14x 12x   14x 10x       14x 14x             2x
/* jslint es6 */
'use strict';
 
const DEFAULT_ADDRESS = require('./SessionMessage').DEFAULT_ADDRESS;
 
const BaseScriptStep = require('./BaseScriptStep');
 
function SetDialogMessage(step, config, bot, logReporter, prevStepPromise ) {
  BaseScriptStep.call(this,step,config,bot,logReporter,prevStepPromise);
 
  this.stepFinishedPromise = Promise.all([prevStepPromise] ).then(() => {
    return this.send();
  });
}
SetDialogMessage.prototype = Object.create(BaseScriptStep.prototype);
SetDialogMessage.prototype.constructor = SetDialogMessage;
 
SetDialogMessage.prototype.initSession = function () {
  return new Promise((resolve, reject) => {
    this.bot.loadSession(DEFAULT_ADDRESS,resolve);
  });
}
SetDialogMessage.prototype.send = function () {
  return new Promise((resolve, reject) => {
    this.initSession()
      .then((session) => {
        if ( "undefined" != typeof this.config.dialog ) {
          this.bot.settings.defaultDialogId = this.config.dialog;
        }
        if ( "undefined" != typeof this.config.args ) {
          this.bot.settings.defaultDialogArgs = this.config.args ;
        }
      })
    .then(() => {
      this.logReporter.startupDialog(this.step, this.config.dialog, this.config.args);
      resolve();
    })
    .catch(reject)
  })
 
}
 
module.exports = SetDialogMessage;