diff --git a/lib/core.js b/lib/core.js index d8212e9..94f3027 100644 --- a/lib/core.js +++ b/lib/core.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.YveBot=e()}(this,function(){"use strict";var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};function e(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=r.maxQueuedPromises?o(new Error("Queue limit reached")):(r.queue.push({promiseGenerator:n,resolve:t,reject:o,notify:i||e}),r._dequeue())})},n.prototype.getPendingLength=function(){return this.pendingPromises},n.prototype.getQueueLength=function(){return this.queue.length},n.prototype._dequeue=function(){var e=this;if(this.pendingPromises>=this.maxPendingPromises)return!1;var n,r=this.queue.shift();if(!r)return this.options.onEmpty&&this.options.onEmpty(),!1;try{this.pendingPromises++,(n=r.promiseGenerator(),n&&"function"==typeof n.then?n:new t(function(t){t(n)})).then(function(t){e.pendingPromises--,r.resolve(t),e._dequeue()},function(t){e.pendingPromises--,r.reject(t),e._dequeue()},function(t){r.notify(t)})}catch(t){e.pendingPromises--,r.reject(t),e._dequeue()}return!0},n},t.exports?t.exports=n():e.Queue=n()}(s={exports:{}},s.exports),s.exports),c=function(){function t(t){this._moduleName=t}return t.prototype.define=function(t,e,n){var r=this,o=!(n&&n.override);if("string"!=typeof t)Object.keys(t).forEach(function(n){r.define(n,t[n],e)});else if(o&&t in this){var i=typeof this;console.warn("You can't redefine \""+t+'" in '+i+". Force it using { override: true } in options argument.")}else this.set(t,e);return this},t.prototype.defineExtension=function(){for(var t=this,e=[],n=0;n-1},nt.prototype.set=function(t,e){var n=this.__data__,r=tt(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this};var rt=V(v,"Map");function ot(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function it(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e-1}function It(t,e,n){for(var r=-1,o=null==t?0:t.length;++r=Ft){var c=e?null:kt(t);if(c)return At(c);u=!1,o=St,a=new Ot}else a=e?[]:s;t:for(;++r=0},Gt={includes:function(t,e){return t instanceof RegExp?Gt.regex(t,e):!!Wt(t)&&e.toLowerCase().indexOf(String(t).toLowerCase())>=0},equals:function(t,e){return!!Wt(t)&&e.toLowerCase()===String(t).toLowerCase()},regex:function(t,e){return t.test(e)},function:function(t,e){return t(e)}},Ut=function(t){function n(){var e=t.call(this,"listeners")||this;return e.define(Gt),e}return e(n,t),n}(c),Vt=function(){try{var t=V(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();var Yt=Object.prototype.hasOwnProperty;function Zt(t,e,n){var r=t[e];Yt.call(t,e)&&X(r,n)&&(void 0!==n||e in t)||function(t,e,n){"__proto__"==e&&Vt?Vt(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}(t,e,n)}var Dt=9007199254740991,Ht=/^(?:0|[1-9]\d*)$/;function Jt(t,e){var n=typeof t;return!!(e=null==e?Dt:e)&&("number"==n||"symbol"!=n&&Ht.test(t))&&t>-1&&t%1==0&&to?0:o+e),(n=n>o?o:n)<0&&(n+=o),o=e>n?0:n-e>>>0,e>>>=0;for(var i=Array(o);++r=0})}(String(t),r)),[2,Ct(n.map(function(t){var n=Mt(e.options,t);if(n)return void 0===n.value?n.label:n.value}).filter(function(t){return void 0!==t}))]})})},validators:[{function:function(t,e){var n=Lt(t),r=e.options.map(function(t){return String(t.value||t.label)});return n.every(function(t){return r.some(function(e){return qt(t,e)})})},warning:"Unknown options"}]}},re=function(t){function o(){var e=t.call(this,"types")||this,n={};for(var r in ne)ne.hasOwnProperty(r)&&(n[r]=zt(ne[r]));return e.define(n),e}return e(o,t),o.prototype.extend=function(t,e,o,i){var u=this[e],s=u.executors,a=r(u,["executors"]),c=zt(o),f=c.executors,l=r(c,["executors"]);return this.define(t,n({executors:s.concat(f)},a,l),i)},o.prototype.set=function(t,e){this[t]=zt(e)},o}(c),oe=function(t){return/^\d+$/.test(t)},ie=function(t){return oe(t)?Number(t):t.length},ue={required:{validate:function(t,e){return Boolean((e||"").trim())===t},warning:"This is required"},email:{validate:function(t,e){return/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(e)===t},warning:"Invalid email format"},regex:{validate:function(t,e){return new RegExp(t).test(e)},warning:"Invalid answer format"},minWords:{validate:function(t,e){return e.split(" ").length>=t},warning:function(t){return"This answer must have at least "+t+" words"}},maxWords:{validate:function(t,e){return e.split(" ").length<=t},warning:function(t){return"This answer must have a maximum "+t+" words"}},min:{validate:function(t,e){return ie(e)>=t},warning:function(t){return"This answer length must be min "+t}},max:{validate:function(t,e){return ie(e)<=t},warning:function(t){return"This answer length must be max "+t}},lenght:{validate:function(t,e){return ie(e)===t},warning:function(t){return"It must have lenght "+t}},string:{validate:function(t,e){return Boolean(!oe(e)&&"string"==typeof e)===t},warning:"It must be a string"},number:{validate:function(t,e){return oe(e)===t},warning:"It must be a number"},function:{validate:function(t,e,n,r){return t(e,n,r)},warning:"Error on execute a validator function"}},se=function(t){function n(){var e=t.call(this,"validators")||this;return e.define(ue),e}return e(n,t),n}(c),ae=function(){function t(t,e){this.sessionId="session",this.options=n({},{enableWaitForSleep:!0,timePerChar:40},e),this.rules=function(t){var e=[];return t.forEach(function(t){if("string"!=typeof t&&"rules"in t&&"flow"in t){var r=t;e=e.concat(r.rules.map(function(e){return n({},Tt(e),{flow:t.flow})}))}else e.push(Tt(t))}),e}(t),this.handlers={},this.store=new ee(this),this.controller=new Qt(this),this.queue=new a(1),this.options.context&&this.store.set("context",this.options.context),this.on("error",function(t){throw t})}return Object.defineProperty(t.prototype,"context",{get:function(){return this.store.get("context")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"types",{get:function(){return t.types},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"actions",{get:function(){return t.actions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"listeners",{get:function(){return t.listeners},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"validators",{get:function(){return t.validators},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exceptions",{get:function(){return t.exceptions},enumerable:!0,configurable:!0}),t.prototype.on=function(t,e){return!(["error"].indexOf(t)>=0)&&t in this.handlers?this.handlers[t].push(e):this.handlers[t]=[e],this},t.prototype.listen=function(t){var e=this;return this.on("listen",function(r,o){t.every(function(t){var i=function(t){var e=t.passive;return n({},t,{passive:e||!1})}(t),u=!i.passive&&["Passive","PassiveLoop"].indexOf(o.type)<0,s=!o.passive;if(!i.next||u||s)return!0;var a=Object.keys(i).filter(function(t){return"next"!==t&&t in e.listeners})[0];if(a&&e.listeners[a](i[a],r))return e.store.set("waitingForAnswer",!1),e.controller.jumpByName(i.next),!1;return!0})}),this},t.prototype.start=function(){if(this.dispatch("start"),!this.store.get("waitingForAnswer")){var t=this.store.get("currentIdx")||0;this.controller.run(t)}return this},t.prototype.end=function(){return this.dispatch("end",this.store.output()),this},t.prototype.talk=function(t,e){var r=n({},this.options.rule,e||{});return this.controller.sendMessage(t,r),this},t.prototype.hear=function(t){var e=this;return this.controller.receiveMessage(t).then(function(){return e.dispatch("reply",t)}),this},t.prototype.dispatch=function(t){for(var e=this,n=[],r=1;r0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=r.maxQueuedPromises?o(new Error("Queue limit reached")):(r.queue.push({promiseGenerator:n,resolve:t,reject:o,notify:i||e}),r._dequeue())})},n.prototype.getPendingLength=function(){return this.pendingPromises},n.prototype.getQueueLength=function(){return this.queue.length},n.prototype._dequeue=function(){var e=this;if(this.pendingPromises>=this.maxPendingPromises)return!1;var n,r=this.queue.shift();if(!r)return this.options.onEmpty&&this.options.onEmpty(),!1;try{this.pendingPromises++,(n=r.promiseGenerator(),n&&"function"==typeof n.then?n:new t(function(t){t(n)})).then(function(t){e.pendingPromises--,r.resolve(t),e._dequeue()},function(t){e.pendingPromises--,r.reject(t),e._dequeue()},function(t){r.notify(t)})}catch(t){e.pendingPromises--,r.reject(t),e._dequeue()}return!0},n},t.exports?t.exports=n():e.Queue=n()}(s={exports:{}},s.exports),s.exports),c=function(){function t(t){this._moduleName=t}return t.prototype.define=function(t,e,n){var r=this,o=!(n&&n.override);if("string"!=typeof t)Object.keys(t).forEach(function(n){r.define(n,t[n],e)});else if(o&&t in this){var i=typeof this;console.warn("You can't redefine \""+t+'" in '+i+". Force it using { override: true } in options argument.")}else this.set(t,e);return this},t.prototype.defineExtension=function(){for(var t=this,e=[],n=0;n-1},nt.prototype.set=function(t,e){var n=this.__data__,r=tt(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this};var rt=V(v,"Map");function ot(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function it(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e-1}function It(t,e,n){for(var r=-1,o=null==t?0:t.length;++r=Ft){var c=e?null:kt(t);if(c)return At(c);u=!1,o=St,a=new Ot}else a=e?[]:s;t:for(;++r=0},Gt={includes:function(t,e){return t instanceof RegExp?Gt.regex(t,e):!!Wt(t)&&e.toLowerCase().indexOf(String(t).toLowerCase())>=0},equals:function(t,e){return!!Wt(t)&&e.toLowerCase()===String(t).toLowerCase()},regex:function(t,e){return t.test(e)},function:function(t,e){return t(e)}},Ut=function(t){function n(){var e=t.call(this,"listeners")||this;return e.define(Gt),e}return e(n,t),n}(c),Vt=function(){try{var t=V(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();var Yt=Object.prototype.hasOwnProperty;function Zt(t,e,n){var r=t[e];Yt.call(t,e)&&X(r,n)&&(void 0!==n||e in t)||function(t,e,n){"__proto__"==e&&Vt?Vt(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}(t,e,n)}var Dt=9007199254740991,Ht=/^(?:0|[1-9]\d*)$/;function Jt(t,e){var n=typeof t;return!!(e=null==e?Dt:e)&&("number"==n||"symbol"!=n&&Ht.test(t))&&t>-1&&t%1==0&&to?0:o+e),(n=n>o?o:n)<0&&(n+=o),o=e>n?0:n-e>>>0,e>>>=0;for(var i=Array(o);++r=0})}(String(t),r)),[2,Ct(n.map(function(t){var n=Mt(e.options,t);if(n)return void 0===n.value?n.label:n.value}).filter(function(t){return void 0!==t}))]})})},validators:[{function:function(t,e){var n=Lt(t),r=e.options.map(function(t){return String(t.value||t.label)});return n.every(function(t){return r.some(function(e){return qt(t,e)})})},warning:"Unknown options"}]}},re=function(t){function o(){var e=t.call(this,"types")||this,n={};for(var r in ne)ne.hasOwnProperty(r)&&(n[r]=zt(ne[r]));return e.define(n),e}return e(o,t),o.prototype.extend=function(t,e,o,i){var u=this[e],s=u.executors,a=r(u,["executors"]),c=zt(o),f=c.executors,l=r(c,["executors"]);return this.define(t,n({executors:s.concat(f)},a,l),i)},o.prototype.set=function(t,e){this[t]=zt(e)},o}(c),oe=function(t){return/^\d+$/.test(t)},ie=function(t){return oe(t)?Number(t):t.length},ue={required:{validate:function(t,e){return Boolean((e||"").trim())===t},warning:"This is required"},email:{validate:function(t,e){return/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(e)===t},warning:"Invalid email format"},regex:{validate:function(t,e){return new RegExp(t).test(e)},warning:"Invalid answer format"},minWords:{validate:function(t,e){return e.split(" ").length>=t},warning:function(t){return"This answer must have at least "+t+" words"}},maxWords:{validate:function(t,e){return e.split(" ").length<=t},warning:function(t){return"This answer must have a maximum "+t+" words"}},min:{validate:function(t,e){return ie(e)>=t},warning:function(t){return"This answer length must be min "+t}},max:{validate:function(t,e){return ie(e)<=t},warning:function(t){return"This answer length must be max "+t}},lenght:{validate:function(t,e){return ie(e)===t},warning:function(t){return"It must have lenght "+t}},string:{validate:function(t,e){return Boolean(!oe(e)&&"string"==typeof e)===t},warning:"It must be a string"},number:{validate:function(t,e){return oe(e)===t},warning:"It must be a number"},function:{validate:function(t,e,n,r){return t(e,n,r)},warning:"Error on execute a validator function"}},se=function(t){function n(){var e=t.call(this,"validators")||this;return e.define(ue),e}return e(n,t),n}(c),ae=function(){function t(t,e){this.sessionId="session",this.options=n({},{enableWaitForSleep:!0,timePerChar:40},e),this.rules=function(t){var e=[];return t.forEach(function(t){if("string"!=typeof t&&"rules"in t&&"flow"in t){var r=t;e=e.concat(r.rules.map(function(e){return n({},Tt(e),{flow:t.flow})}))}else e.push(Tt(t))}),e}(t),this.handlers={},this.store=new ee(this),this.controller=new Qt(this),this.queue=new a(1),this.options.context&&this.store.set("context",this.options.context),this.on("error",function(t){throw t})}return Object.defineProperty(t.prototype,"context",{get:function(){return this.store.get("context")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"types",{get:function(){return t.types},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"actions",{get:function(){return t.actions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"listeners",{get:function(){return t.listeners},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"validators",{get:function(){return t.validators},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exceptions",{get:function(){return t.exceptions},enumerable:!0,configurable:!0}),t.prototype.on=function(t,e){return!(["error"].indexOf(t)>=0)&&t in this.handlers?this.handlers[t].push(e):this.handlers[t]=[e],this},t.prototype.listen=function(t){var e=this;return this.on("listen",function(r,o){t.every(function(t){var i=function(t){var e=t.passive;return n({},t,{passive:e||!1})}(t),u=!i.passive&&["Passive","PassiveLoop"].indexOf(o.type)<0,s=!o.passive;if(!i.next||u||s)return!0;var a=Object.keys(i).filter(function(t){return"next"!==t&&t in e.listeners})[0];if(a&&e.listeners[a](i[a],r))return e.store.set("waitingForAnswer",!1),e.controller.jumpByName(i.next),!1;return!0})}),this},t.prototype.start=function(){if(this.dispatch("start"),!this.store.get("waitingForAnswer")){var t=this.store.get("currentIdx")||0;this.controller.run(t)}return this},t.prototype.end=function(){return this.dispatch("end",this.store.output()),this},t.prototype.talk=function(t,e){var r=n({},this.options.rule,e||{});return this.controller.sendMessage(t,r),this},t.prototype.hear=function(t){var e=this;return this.controller.receiveMessage(t).then(function(){return e.dispatch("reply",t)}),this},t.prototype.dispatch=function(t){for(var e=this,n=[],r=1;r0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]=r.maxQueuedPromises?i(new Error("Queue limit reached")):(r.queue.push({promiseGenerator:n,resolve:t,reject:i,notify:o||e}),r._dequeue())})},n.prototype.getPendingLength=function(){return this.pendingPromises},n.prototype.getQueueLength=function(){return this.queue.length},n.prototype._dequeue=function(){var e=this;if(this.pendingPromises>=this.maxPendingPromises)return!1;var n,r=this.queue.shift();if(!r)return this.options.onEmpty&&this.options.onEmpty(),!1;try{this.pendingPromises++,(n=r.promiseGenerator(),n&&"function"==typeof n.then?n:new t(function(t){t(n)})).then(function(t){e.pendingPromises--,r.resolve(t),e._dequeue()},function(t){e.pendingPromises--,r.reject(t),e._dequeue()},function(t){r.notify(t)})}catch(t){e.pendingPromises--,r.reject(t),e._dequeue()}return!0},n},t.exports?t.exports=n():e.Queue=n()}(u={exports:{}},u.exports),u.exports),c=function(){function t(t){this._moduleName=t}return t.prototype.define=function(t,e,n){var r=this,i=!(n&&n.override);if("string"!=typeof t)Object.keys(t).forEach(function(n){r.define(n,t[n],e)});else if(i&&t in this){var o=typeof this;console.warn("You can't redefine \""+t+'" in '+o+". Force it using { override: true } in options argument.")}else this.set(t,e);return this},t.prototype.defineExtension=function(){for(var t=this,e=[],n=0;n-1},nt.prototype.set=function(t,e){var n=this.__data__,r=tt(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this};var rt=W(v,"Map");function it(t,e){var n,r,i=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?i["string"==typeof e?"string":"hash"]:i.map}function ot(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e-1}function It(t,e,n){for(var r=-1,i=null==t?0:t.length;++r=Mt){var c=e?null:At(t);if(c)return Tt(c);s=!1,i=jt,a=new Ot}else a=e?[]:u;t:for(;++r=0},Ht={includes:function(t,e){return t instanceof RegExp?Ht.regex(t,e):!!Dt(t)&&e.toLowerCase().indexOf(String(t).toLowerCase())>=0},equals:function(t,e){return!!Dt(t)&&e.toLowerCase()===String(t).toLowerCase()},regex:function(t,e){return t.test(e)},function:function(t,e){return t(e)}},Qt=function(t){function n(){var e=t.call(this,"listeners")||this;return e.define(Ht),e}return e(n,t),n}(c),Wt=function(){try{var t=W(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();var Gt=Object.prototype.hasOwnProperty;function Vt(t,e,n){var r=t[e];Gt.call(t,e)&&X(r,n)&&(void 0!==n||e in t)||function(t,e,n){"__proto__"==e&&Wt?Wt(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}(t,e,n)}var Yt=9007199254740991,Zt=/^(?:0|[1-9]\d*)$/;function Kt(t,e){var n=typeof t;return!!(e=null==e?Yt:e)&&("number"==n||"symbol"!=n&&Zt.test(t))&&t>-1&&t%1==0&&ti?0:i+e),(n=n>i?i:n)<0&&(n+=i),i=e>n?0:n-e>>>0,e>>>=0;for(var o=Array(i);++r=0})}(String(t),r)),[2,kt(n.map(function(t){var n=Nt(e.options,t);if(n)return void 0===n.value?n.label:n.value}).filter(function(t){return void 0!==t}))]})})},validators:[{function:function(t,e){var n=Ut(t),r=e.options.map(function(t){return String(t.value||t.label)});return n.every(function(t){return r.some(function(e){return Lt(t,e)})})},warning:"Unknown options"}]}},ie=function(t){function i(){var e=t.call(this,"types")||this,n={};for(var r in re)re.hasOwnProperty(r)&&(n[r]=Rt(re[r]));return e.define(n),e}return e(i,t),i.prototype.extend=function(t,e,i,o){var s=this[e],u=s.executors,a=r(s,["executors"]),c=Rt(i),l=c.executors,p=r(c,["executors"]);return this.define(t,n({executors:u.concat(l)},a,p),o)},i.prototype.set=function(t,e){this[t]=Rt(e)},i}(c),oe=function(t){return/^\d+$/.test(t)},se=function(t){return oe(t)?Number(t):t.length},ue={required:{validate:function(t,e){return Boolean((e||"").trim())===t},warning:"This is required"},email:{validate:function(t,e){return/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(e)===t},warning:"Invalid email format"},regex:{validate:function(t,e){return new RegExp(t).test(e)},warning:"Invalid answer format"},minWords:{validate:function(t,e){return e.split(" ").length>=t},warning:function(t){return"This answer must have at least "+t+" words"}},maxWords:{validate:function(t,e){return e.split(" ").length<=t},warning:function(t){return"This answer must have a maximum "+t+" words"}},min:{validate:function(t,e){return se(e)>=t},warning:function(t){return"This answer length must be min "+t}},max:{validate:function(t,e){return se(e)<=t},warning:function(t){return"This answer length must be max "+t}},lenght:{validate:function(t,e){return se(e)===t},warning:function(t){return"It must have lenght "+t}},string:{validate:function(t,e){return Boolean(!oe(e)&&"string"==typeof e)===t},warning:"It must be a string"},number:{validate:function(t,e){return oe(e)===t},warning:"It must be a number"},function:{validate:function(t,e,n,r){return t(e,n,r)},warning:"Error on execute a validator function"}},ae=function(t){function n(){var e=t.call(this,"validators")||this;return e.define(ue),e}return e(n,t),n}(c),ce=function(){function t(t,e){this.sessionId="session",this.options=n({},{enableWaitForSleep:!0,timePerChar:40},e),this.rules=function(t){var e=[];return t.forEach(function(t){if("string"!=typeof t&&"rules"in t&&"flow"in t){var r=t;e=e.concat(r.rules.map(function(e){return n({},Ft(e),{flow:t.flow})}))}else e.push(Ft(t))}),e}(t),this.handlers={},this.store=new ee(this),this.controller=new zt(this),this.queue=new a(1),this.options.context&&this.store.set("context",this.options.context),this.on("error",function(t){throw t})}return Object.defineProperty(t.prototype,"context",{get:function(){return this.store.get("context")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"types",{get:function(){return t.types},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"actions",{get:function(){return t.actions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"listeners",{get:function(){return t.listeners},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"validators",{get:function(){return t.validators},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exceptions",{get:function(){return t.exceptions},enumerable:!0,configurable:!0}),t.prototype.on=function(t,e){return!(["error"].indexOf(t)>=0)&&t in this.handlers?this.handlers[t].push(e):this.handlers[t]=[e],this},t.prototype.listen=function(t){var e=this;return this.on("listen",function(r,i){t.every(function(t){var o=function(t){var e=t.passive;return n({},t,{passive:e||!1})}(t),s=!o.passive&&["Passive","PassiveLoop"].indexOf(i.type)<0,u=!i.passive;if(!o.next||s||u)return!0;var a=Object.keys(o).filter(function(t){return"next"!==t&&t in e.listeners})[0];if(a&&e.listeners[a](o[a],r))return e.store.set("waitingForAnswer",!1),e.controller.jumpByName(o.next),!1;return!0})}),this},t.prototype.start=function(){if(this.dispatch("start"),!this.store.get("waitingForAnswer")){var t=this.store.get("currentIdx")||0;this.controller.run(t)}return this},t.prototype.end=function(){return this.dispatch("end",this.store.output()),this},t.prototype.talk=function(t,e){var r=n({},this.options.rule,e||{});return this.controller.sendMessage(t,r),this},t.prototype.hear=function(t){var e=this;return this.controller.receiveMessage(t).then(function(){return e.dispatch("reply",t)}),this},t.prototype.dispatch=function(t){for(var e=this,n=[],r=1;r0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]=r.maxQueuedPromises?i(new Error("Queue limit reached")):(r.queue.push({promiseGenerator:n,resolve:t,reject:i,notify:o||e}),r._dequeue())})},n.prototype.getPendingLength=function(){return this.pendingPromises},n.prototype.getQueueLength=function(){return this.queue.length},n.prototype._dequeue=function(){var e=this;if(this.pendingPromises>=this.maxPendingPromises)return!1;var n,r=this.queue.shift();if(!r)return this.options.onEmpty&&this.options.onEmpty(),!1;try{this.pendingPromises++,(n=r.promiseGenerator(),n&&"function"==typeof n.then?n:new t(function(t){t(n)})).then(function(t){e.pendingPromises--,r.resolve(t),e._dequeue()},function(t){e.pendingPromises--,r.reject(t),e._dequeue()},function(t){r.notify(t)})}catch(t){e.pendingPromises--,r.reject(t),e._dequeue()}return!0},n},t.exports?t.exports=n():e.Queue=n()}(u={exports:{}},u.exports),u.exports),c=function(){function t(t){this._moduleName=t}return t.prototype.define=function(t,e,n){var r=this,i=!(n&&n.override);if("string"!=typeof t)Object.keys(t).forEach(function(n){r.define(n,t[n],e)});else if(i&&t in this){var o=typeof this;console.warn("You can't redefine \""+t+'" in '+o+". Force it using { override: true } in options argument.")}else this.set(t,e);return this},t.prototype.defineExtension=function(){for(var t=this,e=[],n=0;n-1},nt.prototype.set=function(t,e){var n=this.__data__,r=tt(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this};var rt=W(v,"Map");function it(t,e){var n,r,i=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?i["string"==typeof e?"string":"hash"]:i.map}function ot(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e-1}function It(t,e,n){for(var r=-1,i=null==t?0:t.length;++r=Mt){var c=e?null:At(t);if(c)return Tt(c);s=!1,i=jt,a=new Ot}else a=e?[]:u;t:for(;++r=0},Ht={includes:function(t,e){return t instanceof RegExp?Ht.regex(t,e):!!Dt(t)&&e.toLowerCase().indexOf(String(t).toLowerCase())>=0},equals:function(t,e){return!!Dt(t)&&e.toLowerCase()===String(t).toLowerCase()},regex:function(t,e){return t.test(e)},function:function(t,e){return t(e)}},Qt=function(t){function n(){var e=t.call(this,"listeners")||this;return e.define(Ht),e}return e(n,t),n}(c),Wt=function(){try{var t=W(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();var Gt=Object.prototype.hasOwnProperty;function Vt(t,e,n){var r=t[e];Gt.call(t,e)&&X(r,n)&&(void 0!==n||e in t)||function(t,e,n){"__proto__"==e&&Wt?Wt(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}(t,e,n)}var Yt=9007199254740991,Zt=/^(?:0|[1-9]\d*)$/;function Kt(t,e){var n=typeof t;return!!(e=null==e?Yt:e)&&("number"==n||"symbol"!=n&&Zt.test(t))&&t>-1&&t%1==0&&ti?0:i+e),(n=n>i?i:n)<0&&(n+=i),i=e>n?0:n-e>>>0,e>>>=0;for(var o=Array(i);++r=0})}(String(t),r)),[2,kt(n.map(function(t){var n=Nt(e.options,t);if(n)return void 0===n.value?n.label:n.value}).filter(function(t){return void 0!==t}))]})})},validators:[{function:function(t,e){var n=Ut(t),r=e.options.map(function(t){return String(t.value||t.label)});return n.every(function(t){return r.some(function(e){return Lt(t,e)})})},warning:"Unknown options"}]}},ie=function(t){function i(){var e=t.call(this,"types")||this,n={};for(var r in re)re.hasOwnProperty(r)&&(n[r]=Rt(re[r]));return e.define(n),e}return e(i,t),i.prototype.extend=function(t,e,i,o){var s=this[e],u=s.executors,a=r(s,["executors"]),c=Rt(i),l=c.executors,p=r(c,["executors"]);return this.define(t,n({executors:u.concat(l)},a,p),o)},i.prototype.set=function(t,e){this[t]=Rt(e)},i}(c),oe=function(t){return/^\d+$/.test(t)},se=function(t){return oe(t)?Number(t):t.length},ue={required:{validate:function(t,e){return Boolean((e||"").trim())===t},warning:"This is required"},email:{validate:function(t,e){return/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(e)===t},warning:"Invalid email format"},regex:{validate:function(t,e){return new RegExp(t).test(e)},warning:"Invalid answer format"},minWords:{validate:function(t,e){return e.split(" ").length>=t},warning:function(t){return"This answer must have at least "+t+" words"}},maxWords:{validate:function(t,e){return e.split(" ").length<=t},warning:function(t){return"This answer must have a maximum "+t+" words"}},min:{validate:function(t,e){return se(e)>=t},warning:function(t){return"This answer length must be min "+t}},max:{validate:function(t,e){return se(e)<=t},warning:function(t){return"This answer length must be max "+t}},lenght:{validate:function(t,e){return se(e)===t},warning:function(t){return"It must have lenght "+t}},string:{validate:function(t,e){return Boolean(!oe(e)&&"string"==typeof e)===t},warning:"It must be a string"},number:{validate:function(t,e){return oe(e)===t},warning:"It must be a number"},function:{validate:function(t,e,n,r){return t(e,n,r)},warning:"Error on execute a validator function"}},ae=function(t){function n(){var e=t.call(this,"validators")||this;return e.define(ue),e}return e(n,t),n}(c),ce=function(){function t(t,e){this.sessionId="session",this.options=n({},{enableWaitForSleep:!0,timePerChar:40},e),this.rules=function(t){var e=[];return t.forEach(function(t){if("string"!=typeof t&&"rules"in t&&"flow"in t){var r=t;e=e.concat(r.rules.map(function(e){return n({},Ft(e),{flow:t.flow})}))}else e.push(Ft(t))}),e}(t),this.handlers={},this.store=new ee(this),this.controller=new zt(this),this.queue=new a(1),this.options.context&&this.store.set("context",this.options.context),this.on("error",function(t){throw t})}return Object.defineProperty(t.prototype,"context",{get:function(){return this.store.get("context")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"types",{get:function(){return t.types},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"actions",{get:function(){return t.actions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"listeners",{get:function(){return t.listeners},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"validators",{get:function(){return t.validators},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exceptions",{get:function(){return t.exceptions},enumerable:!0,configurable:!0}),t.prototype.on=function(t,e){return!(["error"].indexOf(t)>=0)&&t in this.handlers?this.handlers[t].push(e):this.handlers[t]=[e],this},t.prototype.listen=function(t){var e=this;return this.on("listen",function(r,i){t.every(function(t){var o=function(t){var e=t.passive;return n({},t,{passive:e||!1})}(t),s=!o.passive&&["Passive","PassiveLoop"].indexOf(i.type)<0,u=!i.passive;if(!o.next||s||u)return!0;var a=Object.keys(o).filter(function(t){return"next"!==t&&t in e.listeners})[0];if(a&&e.listeners[a](o[a],r))return e.store.set("waitingForAnswer",!1),e.controller.jumpByName(o.next),!1;return!0})}),this},t.prototype.start=function(){if(this.dispatch("start"),!this.store.get("waitingForAnswer")){var t=this.store.get("currentIdx")||0;this.controller.run(t)}return this},t.prototype.end=function(){return this.dispatch("end",this.store.output()),this},t.prototype.talk=function(t,e){var r=n({},this.options.rule,e||{});return this.controller.sendMessage(t,r),this},t.prototype.hear=function(t){var e=this;return this.controller.receiveMessage(t).then(function(){return e.dispatch("reply",t)}),this},t.prototype.dispatch=function(t){for(var e=this,n=[],r=1;r