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,gBAAiB,CACb,KAAM,EACN,OAAQ,mBAIpB,EAAQ,GAAG,YAAa,IAMpB,GAJA,EAAO,YAAY,SAAS,IACxB,EAAS,EAAS,EAAU,EAAI,IAGhC,UAAU,EAAS,QAAS,CAC5B,IAAI,EAAS,EAAS,OAAO,OAEzB,UAAU,IACN,EAAO,gBAAgB,IACvB,EAAO,gBAAgB,GAAQ,SAAS,IACpC,EAAS,EAAS,EAAU,EAAI,GAIhD,KAGJ,EAAQ,GAAG,SAAU,IACjB,QAAQ,MAAM,EAAM,IAGxB,EAAQ,KACZ,CAEJ,CAAE,MAAO,GACL,QAAQ,MAAM,EAClB,CACJ,EAEO,CACX,CApHA,OAAO,QAAU,SAAU,GACvB,OAAO,sBAAsB,EACjC","file":"/npm/@abbott-platform/api-ai-botkit@1.6.0/api-ai-botkit.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@abbott-platform/api-ai-botkit@1.6.0/api-ai-botkit.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * Copyright 2017 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n'use strict';\nconst apiai = require('apiai');\n\nconst uuidV4 = require('uuid/v4');\nconst Entities = require('html-entities').XmlEntities;\nconst decoder = new Entities();\n\nmodule.exports = function (apiaiToken) {\n    return createApiAiProcessing(apiaiToken);\n};\n\nfunction isDefined(obj) {\n    if (typeof obj == 'undefined') {\n        return false;\n    }\n\n    if (!obj) {\n        return false;\n    }\n\n    return obj != null;\n}\n\nfunction createApiAiProcessing(token) {\n    let worker = {};\n\n    worker.apiaiService = apiai(token);\n    worker.sessionIds = {};\n\n    worker.actionCallbacks = {};\n    worker.allCallback = [];\n\n    worker.action = function (action, callback) {\n        if (worker.actionCallbacks[action]) {\n            worker.actionCallbacks[action].push(callback);\n        } else {\n            worker.actionCallbacks[action] = [callback];\n        }\n\n        return worker;\n    };\n\n    worker.all = function (callback) {\n        worker.allCallback.push(callback);\n        return worker;\n    };\n\n\n    worker.process = function (message, bot) {\n        try {\n\n            if (isDefined(message.text)) {\n                let userId = message.user;\n\n                let requestText = decoder.decode(message.text);\n                requestText = requestText.replace(\"’\", \"'\");\n\n                if (isDefined(bot.identity) && isDefined(bot.identity.id)) {\n                    // it seems it is Slack\n\n                    if (message.user == bot.identity.id) {\n                        // message from bot can be skipped\n                        return;\n                    }\n\n                    if (message.text.indexOf(\"<@U\") == 0 && message.text.indexOf(bot.identity.id) == -1) {\n                        // skip other users direct mentions\n                        return;\n                    }\n\n                    let botId = '<@' + bot.identity.id + '>';\n                    if (requestText.indexOf(botId) > -1) {\n                        requestText = requestText.replace(botId, '');\n                    }\n\n                    userId = message.channel;\n                }\n\n                if (!(userId in worker.sessionIds)) {\n                    worker.sessionIds[userId] = uuidV4();\n                }\n\n                let request = worker.apiaiService.textRequest(requestText,\n                    {\n                        sessionId: worker.sessionIds[userId],\n                        originalRequest: {\n                            data: message,\n                            source: \"api-ai-botkit\"\n                        }\n                    });\n\n                request.on('response', (response) => {\n\n                    worker.allCallback.forEach((callback) => {\n                        callback(message, response, bot);\n                    });\n\n                    if (isDefined(response.result)) {\n                        let action = response.result.action;\n\n                        if (isDefined(action)) {\n                            if (worker.actionCallbacks[action]) {\n                                worker.actionCallbacks[action].forEach((callback) => {\n                                    callback(message, response, bot);\n                                });\n                            }\n                        }\n                    }\n                });\n\n                request.on('error', (error) => {\n                    console.error(error);\n                });\n\n                request.end();\n            }\n\n        } catch (err) {\n            console.error(err);\n        }\n    };\n\n    return worker;\n}"]}