/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/ck-dialogflow-webhook@0.1.0/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var express=require("express");
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function __awaiter(e,t,n,r){return new(n||(n=Promise))((function(o,a){function s(e){try{i(r.next(e))}catch(e){a(e)}}function u(e){try{i(r.throw(e))}catch(e){a(e)}}function i(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}i((r=r.apply(e,t||[])).next())}))}function __generator(e,t){var n,r,o,a,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}var chatRequset=function(e,t){return __awaiter(void 0,void 0,void 0,(function(){var n,r,o,a;return __generator(this,(function(s){switch(s.label){case 0:return n=t.text,r=t.languageCode,o=t.sessionPath,a={session:o,queryInput:{text:{text:n,languageCode:r}}},[4,e.detectIntent(a)];case 1:return[2,s.sent()]}}))}))},chatEvent=function(e,t){return __awaiter(void 0,void 0,void 0,(function(){var n,r,o,a;return __generator(this,(function(s){switch(s.label){case 0:return n=t.eventName,r=t.sessionPath,o=t.languageCode,a={session:r,queryInput:{event:{name:n,languageCode:o}}},[4,e.detectIntent(a)];case 1:return[2,s.sent()]}}))}))},dialogflow=require("dialogflow"),Router=express.Router,ckDialogflowWebhook=function(e){var t=new dialogflow.v2.SessionsClient({keyFilename:e}),n=Router();return n.post("/ckWebhook/dialogFLow/chatInit",(function(e,n){var r=e.body.data,o=r.sessionId,a=r.projectId;try{var s={sessionPath:t.sessionPath(a,o)};n.json({result:s})}catch(e){console.log(e)}})),n.post("/ckWebhook/dialogFLow/chatRequest",(function(e,n){return __awaiter(void 0,void 0,void 0,(function(){var r,o,a;return __generator(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),r=e.body.data,[4,chatRequset(t,r)];case 1:return o=s.sent(),n.json({result:o}),[3,3];case 2:return a=s.sent(),console.log(a),[3,3];case 3:return[2]}}))}))})),n.post("/ckWebhook/dialogFLow/chatEvent",(function(e,n){return __awaiter(void 0,void 0,void 0,(function(){var r,o,a;return __generator(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),r=e.body.data,[4,chatEvent(t,r)];case 1:return o=s.sent(),n.json({result:o}),[3,3];case 2:return a=s.sent(),console.log(a),[3,3];case 3:return[2]}}))}))})),n};exports.default=ckDialogflowWebhook;
//# sourceMappingURL=/sm/c761027b3bac83cf5f752c08ce1751771e088dba8d4494fcbb02bf148365e0b0.map