text: !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@aws-amplify/core"),require("aws-sdk/clients/lexruntime")):"function"==typeof define&&define.amd?define("aws_amplify_interactions",["@aws-amplify/core","aws-sdk/clients/lexruntime"],e):"object"==typeof exports?exports.aws_amplify_interactions=e(require("@aws-amplify/core"),require("aws-sdk/clients/lexruntime")):t.aws_amplify_interactions=e(t["@aws-amplify/core"],t["aws-sdk/clients/lexruntime"])}(this,(function(t,e){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(e,n){e.exports=t},function(t,n){t.exports=e},function(t,e,n){"use strict";n.r(e),n.d(e,"AWSLexProvider",(function(){return g})),n.d(e,"InteractionsClass",(function(){return v}));var o,r=n(0),i=n.n(r),s=function(){return(s=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)},a=new r.ConsoleLogger("AbstractInteractionsProvider"),u=function(){function t(t){void 0===t&&(t={}),this._config=t}return t.prototype.configure=function(t){return void 0===t&&(t={}),this._config=s(s({},this._config),t),a.debug("configure "+this.getProviderName(),this._config),this.options},t.prototype.getCategory=function(){return"Interactions"},Object.defineProperty(t.prototype,"options",{get:function(){return s({},this._config)},enumerable:!0,configurable:!0}),t}(),l=n(1),c=(o=function(t,e){return(o=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])})(t,e)},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),f=function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((o=o.apply(t,e||[])).next())}))},p=function(t,e){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,o=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},d=new r.ConsoleLogger("AWSLexProvider"),g=function(t){function e(e){void 0===e&&(e={});var n=t.call(this,e)||this;return n.aws_lex=new l({region:n._config.region}),n._botsCompleteCallback={},n}return c(e,t),e.prototype.getProviderName=function(){return"AWSLexProvider"},e.prototype.responseCallback=function(t,e,n,o,r){var i=this;t?o(t):(d.debug("postContent state",e.dialogState),"ReadyForFulfillment"!==e.dialogState&&"Fulfilled"!==e.dialogState||("function"==typeof this._botsCompleteCallback[r]&&setTimeout((function(){return i._botsCompleteCallback[r](null,{slots:e.slots})}),0),this._config&&"function"==typeof this._config[r].onComplete&&setTimeout((function(){return i._config[r].onComplete(null,{slots:e.slots})}),0)),n(e),"Failed"===e.dialogState&&("function"==typeof this._botsCompleteCallback[r]&&setTimeout((function(){return i._botsCompleteCallback[r]("Bot conversation failed")}),0),this._config&&"function"==typeof this._config[r].onComplete&&setTimeout((function(){return i._config[r].onComplete("Bot conversation failed")}),0)))},e.prototype.sendMessage=function(t,e){var n=this;return new Promise((function(o,i){return f(n,void 0,void 0,(function(){var n,s,a=this;return p(this,(function(u){switch(u.label){case 0:return this._config[t]?[4,r.Credentials.get()]:[2,i("Bot "+t+" does not exist")];case 1:return(n=u.sent())?(r.AWS.config.update({credentials:n}),this.aws_lex=new l({region:this._config[t].region,credentials:n}),"string"==typeof e?(s={botAlias:this._config[t].alias,botName:t,inputText:e,userId:n.identityId},d.debug("postText to lex",e),this.aws_lex.postText(s,(function(e,n){a.responseCallback(e,n,o,i,t)}))):(s="voice"===e.options.messageType?{botAlias:this._config[t].alias,botName:t,contentType:"audio/x-l16; sample-rate=16000",inputStream:e.content,userId:n.identityId,accept:"audio/mpeg"}:{botAlias:this._config[t].alias,botName:t,contentType:"text/plain; charset=utf-8",inputStream:e.content,userId:n.identityId,accept:"audio/mpeg"},d.debug("postContent to lex",e),this.aws_lex.postContent(s,(function(e,n){a.responseCallback(e,n,o,i,t)}))),[2]):[2,i("No credentials")]}}))}))}))},e.prototype.onComplete=function(t,e){if(!this._config[t])throw new ErrorEvent("Bot "+t+" does not exist");this._botsCompleteCallback[t]=e},e}(u),b=function(){return(b=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)},h=function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((o=o.apply(t,e||[])).next())}))},y=function(t,e){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,o=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},_=new r.ConsoleLogger("Interactions"),v=function(){function t(t){this._options=t,_.debug("Interactions Options",this._options),this._pluggables={}}return t.prototype.getModuleName=function(){return"Interactions"},t.prototype.configure=function(t){var e=this,n=t?t.Interactions||t:{};_.debug("configure Interactions",{opt:n}),this._options=b(b({bots:{}},n),n.Interactions);var o=this._options.aws_bots_config,r=this._options.bots;return!Object.keys(r).length&&o&&Array.isArray(o)&&o.forEach((function(t){e._options.bots[t.name]=t})),!this._pluggables.AWSLexProvider&&r&&Object.keys(r).map((function(t){return r[t]})).find((function(t){return!t.providerName||"AWSLexProvider"===t.providerName}))&&(this._pluggables.AWSLexProvider=new g),Object.keys(this._pluggables).map((function(t){e._pluggables[t].configure(e._options.bots)})),this._options},t.prototype.addPluggable=function(t){if(t&&"Interactions"===t.getCategory()){if(this._pluggables[t.getProviderName()])throw new Error("Bot "+t.getProviderName()+" already plugged");return t.configure(this._options.bots),void(this._pluggables[t.getProviderName()]=t)}},t.prototype.send=function(t,e){return h(this,void 0,void 0,(function(){var n;return y(this,(function(o){switch(o.label){case 0:if(!this._options.bots||!this._options.bots[t])throw new Error("Bot "+t+" does not exist");if(n=this._options.bots[t].providerName||"AWSLexProvider",!this._pluggables[n])throw new Error("Bot "+n+" does not have valid pluggin did you try addPluggable first?");return[4,this._pluggables[n].sendMessage(t,e)];case 1:return[2,o.sent()]}}))}))},t.prototype.onComplete=function(t,e){if(!this._options.bots||!this._options.bots[t])throw new Error("Bot "+t+" does not exist");var n=this._options.bots[t].providerName||"AWSLexProvider";if(!this._pluggables[n])throw new Error("Bot "+n+" does not have valid pluggin did you try addPluggable first?");this._pluggables[n].onComplete(t,e)},t}(),m=new r.ConsoleLogger("Interactions"),w=null;w||(m.debug("Create Interactions Instance"),w=new v(null));var x=w;i.a.register(x);e.default=x}])}));
  //# sourceMappingURL=aws-amplify-interactions.min.js.map