├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ └── npm-publish.yml ├── .gitignore ├── .prettierrc ├── LICENSE ├── dist ├── index.d.ts ├── index.es.d.ts ├── index.es.js ├── index.es.js.map ├── index.js └── index.js.map ├── jest.config.js ├── package-lock.json ├── package.json ├── readme.md ├── rollup.config.js ├── src ├── @types │ ├── common.d.ts │ └── queries.d.ts ├── index.ts └── queries │ ├── chatEvent.ts │ └── chatRequset.ts └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # Matches multiple files with brace expansion notation 12 | # Set default charset 13 | [*.{js,py, ts, tsx, jsx}] 14 | charset = utf-8 15 | indent_style = space 16 | indent_size = 2 17 | 18 | # 4 space indentation 19 | [*.py] 20 | indent_style = space 21 | indent_size = 4 22 | 23 | # Tab indentation (no size specified) 24 | [Makefile] 25 | indent_style = tab 26 | 27 | # Indentation override for all JS under lib directory 28 | [lib/**.js] 29 | indent_style = space 30 | indent_size = 2 31 | 32 | # Matches the exact files either package.json or .travis.yml 33 | [{package.json,.travis.yml}] 34 | indent_style = space 35 | indent_size = 2 36 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | "eslint:recommended", 4 | "plugin:react/recommended", 5 | "plugin:@typescript-eslint/recommended", 6 | "prettier/@typescript-eslint", 7 | "plugin:prettier/recommended" 8 | ], 9 | plugins: ["react", "@typescript-eslint", "prettier"], 10 | env: { 11 | browser: true, 12 | jest: true, 13 | es6: true, 14 | node: true 15 | }, 16 | rules: { 17 | "prettier/prettier": [ 18 | "error", 19 | { trailingComma: "es5", semi: false, singleQuote: true, printWidth: 120 } 20 | ], 21 | "@typescript-eslint/explicit-function-return-type": "off" 22 | }, 23 | settings: { 24 | react: { 25 | pragma: "React", 26 | version: "detect" 27 | } 28 | }, 29 | parser: "@typescript-eslint/parser", 30 | parserOptions: { 31 | ecmaFeatures: { 32 | jsx: false 33 | } 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages 3 | 4 | name: Node.js Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: actions/setup-node@v1 16 | with: 17 | node-version: 12 18 | - run: npm ci 19 | - run: npm test 20 | 21 | publish-npm: 22 | needs: build 23 | runs-on: ubuntu-latest 24 | steps: 25 | - uses: actions/checkout@v2 26 | - uses: actions/setup-node@v1 27 | with: 28 | node-version: 12 29 | registry-url: https://registry.npmjs.org/ 30 | - run: npm ci 31 | - run: npm publish 32 | env: 33 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /node_modules 3 | 4 | /storybook-static 5 | 6 | .env -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "semi": false, 4 | "singleQuote": true, 5 | "printWidth": 120 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright (c) 2020, Virtual Assistant, LLC 190 | All rights reserved. 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /dist/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare const ckDialogflowWebhook: (keyFilename: string) => import("express-serve-static-core").Router; 3 | export { ckDialogflowWebhook as default }; 4 | -------------------------------------------------------------------------------- /dist/index.es.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare const ckDialogflowWebhook: (keyFilename: string) => import("express-serve-static-core").Router; 3 | export { ckDialogflowWebhook as default }; 4 | -------------------------------------------------------------------------------- /dist/index.es.js: -------------------------------------------------------------------------------- 1 | import { Router as Router$1 } from 'express'; 2 | 3 | /*! ***************************************************************************** 4 | Copyright (c) Microsoft Corporation. 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 14 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | PERFORMANCE OF THIS SOFTWARE. 16 | ***************************************************************************** */ 17 | 18 | function __awaiter(thisArg, _arguments, P, generator) { 19 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 20 | return new (P || (P = Promise))(function (resolve, reject) { 21 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 22 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 23 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 24 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 25 | }); 26 | } 27 | 28 | function __generator(thisArg, body) { 29 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 30 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 31 | function verb(n) { return function (v) { return step([n, v]); }; } 32 | function step(op) { 33 | if (f) throw new TypeError("Generator is already executing."); 34 | while (_) try { 35 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 36 | if (y = 0, t) op = [op[0] & 2, t.value]; 37 | switch (op[0]) { 38 | case 0: case 1: t = op; break; 39 | case 4: _.label++; return { value: op[1], done: false }; 40 | case 5: _.label++; y = op[1]; op = [0]; continue; 41 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 42 | default: 43 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 44 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 45 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 46 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 47 | if (t[2]) _.ops.pop(); 48 | _.trys.pop(); continue; 49 | } 50 | op = body.call(thisArg, _); 51 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 52 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 53 | } 54 | } 55 | 56 | var chatRequset = function (sessionClient, data) { return __awaiter(void 0, void 0, void 0, function () { 57 | var text, languageCode, sessionPath, request, responses; 58 | return __generator(this, function (_a) { 59 | switch (_a.label) { 60 | case 0: 61 | text = data.text, languageCode = data.languageCode, sessionPath = data.sessionPath; 62 | request = { 63 | session: sessionPath, 64 | queryInput: { 65 | text: { 66 | text: text, 67 | languageCode: languageCode, 68 | }, 69 | }, 70 | }; 71 | return [4 /*yield*/, sessionClient.detectIntent(request)]; 72 | case 1: 73 | responses = _a.sent(); 74 | return [2 /*return*/, responses]; 75 | } 76 | }); 77 | }); }; 78 | 79 | var chatEvent = function (sessionClient, data) { return __awaiter(void 0, void 0, void 0, function () { 80 | var eventName, sessionPath, languageCode, request, responses; 81 | return __generator(this, function (_a) { 82 | switch (_a.label) { 83 | case 0: 84 | eventName = data.eventName, sessionPath = data.sessionPath, languageCode = data.languageCode; 85 | request = { 86 | session: sessionPath, 87 | queryInput: { 88 | event: { 89 | name: eventName, 90 | languageCode: languageCode, 91 | }, 92 | }, 93 | }; 94 | return [4 /*yield*/, sessionClient.detectIntent(request)]; 95 | case 1: 96 | responses = _a.sent(); 97 | return [2 /*return*/, responses]; 98 | } 99 | }); 100 | }); }; 101 | 102 | var dialogflow = require('dialogflow'); 103 | var Router = Router$1; 104 | var ckDialogflowWebhook = function (keyFilename) { 105 | var sessionClient = new dialogflow.v2.SessionsClient({ keyFilename: keyFilename }); 106 | var router = Router(); 107 | router.post('/ckWebhook/dialogFLow/chatInit', function (req, res) { 108 | var _a = req.body.data, sessionId = _a.sessionId, projectId = _a.projectId; 109 | try { 110 | var sessionPath = sessionClient.sessionPath(projectId, sessionId); 111 | var result = { 112 | sessionPath: sessionPath, 113 | }; 114 | res.json({ result: result }); 115 | } 116 | catch (err) { 117 | console.log(err); 118 | } 119 | }); 120 | router.post('/ckWebhook/dialogFLow/chatRequest', function (req, res) { return __awaiter(void 0, void 0, void 0, function () { 121 | var data, result, err_1; 122 | return __generator(this, function (_a) { 123 | switch (_a.label) { 124 | case 0: 125 | _a.trys.push([0, 2, , 3]); 126 | data = req.body.data; 127 | return [4 /*yield*/, chatRequset(sessionClient, data)]; 128 | case 1: 129 | result = _a.sent(); 130 | res.json({ result: result }); 131 | return [3 /*break*/, 3]; 132 | case 2: 133 | err_1 = _a.sent(); 134 | console.log(err_1); 135 | return [3 /*break*/, 3]; 136 | case 3: return [2 /*return*/]; 137 | } 138 | }); 139 | }); }); 140 | router.post('/ckWebhook/dialogFLow/chatEvent', function (req, res) { return __awaiter(void 0, void 0, void 0, function () { 141 | var data, result, err_2; 142 | return __generator(this, function (_a) { 143 | switch (_a.label) { 144 | case 0: 145 | _a.trys.push([0, 2, , 3]); 146 | data = req.body.data; 147 | return [4 /*yield*/, chatEvent(sessionClient, data)]; 148 | case 1: 149 | result = _a.sent(); 150 | res.json({ result: result }); 151 | return [3 /*break*/, 3]; 152 | case 2: 153 | err_2 = _a.sent(); 154 | console.log(err_2); 155 | return [3 /*break*/, 3]; 156 | case 3: return [2 /*return*/]; 157 | } 158 | }); 159 | }); }); 160 | return router; 161 | }; 162 | 163 | export default ckDialogflowWebhook; 164 | //# sourceMappingURL=index.es.js.map 165 | -------------------------------------------------------------------------------- /dist/index.es.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.es.js","sources":["../node_modules/tslib/tslib.es6.js","../src/queries/chatRequset.ts","../src/queries/chatEvent.ts","../src/index.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __createBinding(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n};\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, privateMap) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to get private field on non-instance\");\r\n }\r\n return privateMap.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, privateMap, value) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to set private field on non-instance\");\r\n }\r\n privateMap.set(receiver, value);\r\n return value;\r\n}\r\n","import { ChatRequestData } from '../@types/queries'\n\nexport const chatRequset = async (sessionClient: any, data: ChatRequestData) => {\n const { text, languageCode, sessionPath } = data\n const request = {\n session: sessionPath,\n queryInput: {\n text: {\n text,\n languageCode,\n },\n },\n }\n const responses = await sessionClient.detectIntent(request)\n return responses\n}\n","import { ChatEventData } from '../@types/queries'\n\nexport const chatEvent = async (sessionClient: any, data: ChatEventData) => {\n const { eventName, sessionPath, languageCode } = data\n const request = {\n session: sessionPath,\n queryInput: {\n event: {\n name: eventName,\n languageCode,\n },\n },\n }\n const responses = await sessionClient.detectIntent(request)\n return responses\n}\n","import * as express from 'express'\nconst dialogflow = require('dialogflow')\nimport { chatRequset } from './queries/chatRequset'\nimport { chatEvent } from './queries/chatEvent'\nconst { Router } = express\nconst ckDialogflowWebhook = (keyFilename: string) => {\n const sessionClient = new dialogflow.v2.SessionsClient({ keyFilename })\n const router = Router()\n router.post('/ckWebhook/dialogFLow/chatInit', (req, res) => {\n const { sessionId, projectId } = req.body.data\n try {\n const sessionPath = sessionClient.sessionPath(projectId, sessionId)\n\n const result = {\n sessionPath,\n }\n res.json({ result })\n } catch (err) {\n console.log(err)\n }\n })\n router.post('/ckWebhook/dialogFLow/chatRequest', async (req, res) => {\n try {\n const { data } = req.body\n const result = await chatRequset(sessionClient, data)\n res.json({ result })\n } catch(err){\n console.log(err)\n }\n })\n router.post('/ckWebhook/dialogFLow/chatEvent', async (req, res) => {\n try{\n const { data } = req.body\n const result = await chatEvent(sessionClient, data)\n res.json({ result })\n } catch(err){\n console.log(err)\n }\n })\n return router\n}\nexport default ckDialogflowWebhook\n"],"names":["express.Router"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;A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CAAC,KAAG,CAAC,CAAA;;;;;SAEnB,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf;;;;"} -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | var express = require('express'); 6 | 7 | /*! ***************************************************************************** 8 | Copyright (c) Microsoft Corporation. 9 | 10 | Permission to use, copy, modify, and/or distribute this software for any 11 | purpose with or without fee is hereby granted. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 14 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 15 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 16 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 17 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 18 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 19 | PERFORMANCE OF THIS SOFTWARE. 20 | ***************************************************************************** */ 21 | 22 | function __awaiter(thisArg, _arguments, P, generator) { 23 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 24 | return new (P || (P = Promise))(function (resolve, reject) { 25 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 26 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 27 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 28 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 29 | }); 30 | } 31 | 32 | function __generator(thisArg, body) { 33 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 34 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 35 | function verb(n) { return function (v) { return step([n, v]); }; } 36 | function step(op) { 37 | if (f) throw new TypeError("Generator is already executing."); 38 | while (_) try { 39 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 40 | if (y = 0, t) op = [op[0] & 2, t.value]; 41 | switch (op[0]) { 42 | case 0: case 1: t = op; break; 43 | case 4: _.label++; return { value: op[1], done: false }; 44 | case 5: _.label++; y = op[1]; op = [0]; continue; 45 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 46 | default: 47 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 48 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 49 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 50 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 51 | if (t[2]) _.ops.pop(); 52 | _.trys.pop(); continue; 53 | } 54 | op = body.call(thisArg, _); 55 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 56 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 57 | } 58 | } 59 | 60 | var chatRequset = function (sessionClient, data) { return __awaiter(void 0, void 0, void 0, function () { 61 | var text, languageCode, sessionPath, request, responses; 62 | return __generator(this, function (_a) { 63 | switch (_a.label) { 64 | case 0: 65 | text = data.text, languageCode = data.languageCode, sessionPath = data.sessionPath; 66 | request = { 67 | session: sessionPath, 68 | queryInput: { 69 | text: { 70 | text: text, 71 | languageCode: languageCode, 72 | }, 73 | }, 74 | }; 75 | return [4 /*yield*/, sessionClient.detectIntent(request)]; 76 | case 1: 77 | responses = _a.sent(); 78 | return [2 /*return*/, responses]; 79 | } 80 | }); 81 | }); }; 82 | 83 | var chatEvent = function (sessionClient, data) { return __awaiter(void 0, void 0, void 0, function () { 84 | var eventName, sessionPath, languageCode, request, responses; 85 | return __generator(this, function (_a) { 86 | switch (_a.label) { 87 | case 0: 88 | eventName = data.eventName, sessionPath = data.sessionPath, languageCode = data.languageCode; 89 | request = { 90 | session: sessionPath, 91 | queryInput: { 92 | event: { 93 | name: eventName, 94 | languageCode: languageCode, 95 | }, 96 | }, 97 | }; 98 | return [4 /*yield*/, sessionClient.detectIntent(request)]; 99 | case 1: 100 | responses = _a.sent(); 101 | return [2 /*return*/, responses]; 102 | } 103 | }); 104 | }); }; 105 | 106 | var dialogflow = require('dialogflow'); 107 | var Router = express.Router; 108 | var ckDialogflowWebhook = function (keyFilename) { 109 | var sessionClient = new dialogflow.v2.SessionsClient({ keyFilename: keyFilename }); 110 | var router = Router(); 111 | router.post('/ckWebhook/dialogFLow/chatInit', function (req, res) { 112 | var _a = req.body.data, sessionId = _a.sessionId, projectId = _a.projectId; 113 | try { 114 | var sessionPath = sessionClient.sessionPath(projectId, sessionId); 115 | var result = { 116 | sessionPath: sessionPath, 117 | }; 118 | res.json({ result: result }); 119 | } 120 | catch (err) { 121 | console.log(err); 122 | } 123 | }); 124 | router.post('/ckWebhook/dialogFLow/chatRequest', function (req, res) { return __awaiter(void 0, void 0, void 0, function () { 125 | var data, result, err_1; 126 | return __generator(this, function (_a) { 127 | switch (_a.label) { 128 | case 0: 129 | _a.trys.push([0, 2, , 3]); 130 | data = req.body.data; 131 | return [4 /*yield*/, chatRequset(sessionClient, data)]; 132 | case 1: 133 | result = _a.sent(); 134 | res.json({ result: result }); 135 | return [3 /*break*/, 3]; 136 | case 2: 137 | err_1 = _a.sent(); 138 | console.log(err_1); 139 | return [3 /*break*/, 3]; 140 | case 3: return [2 /*return*/]; 141 | } 142 | }); 143 | }); }); 144 | router.post('/ckWebhook/dialogFLow/chatEvent', function (req, res) { return __awaiter(void 0, void 0, void 0, function () { 145 | var data, result, err_2; 146 | return __generator(this, function (_a) { 147 | switch (_a.label) { 148 | case 0: 149 | _a.trys.push([0, 2, , 3]); 150 | data = req.body.data; 151 | return [4 /*yield*/, chatEvent(sessionClient, data)]; 152 | case 1: 153 | result = _a.sent(); 154 | res.json({ result: result }); 155 | return [3 /*break*/, 3]; 156 | case 2: 157 | err_2 = _a.sent(); 158 | console.log(err_2); 159 | return [3 /*break*/, 3]; 160 | case 3: return [2 /*return*/]; 161 | } 162 | }); 163 | }); }); 164 | return router; 165 | }; 166 | 167 | exports.default = ckDialogflowWebhook; 168 | //# sourceMappingURL=index.js.map 169 | -------------------------------------------------------------------------------- /dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sources":["../node_modules/tslib/tslib.es6.js","../src/queries/chatRequset.ts","../src/queries/chatEvent.ts","../src/index.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __createBinding(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n};\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, privateMap) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to get private field on non-instance\");\r\n }\r\n return privateMap.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, privateMap, value) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to set private field on non-instance\");\r\n }\r\n privateMap.set(receiver, value);\r\n return value;\r\n}\r\n","import { ChatRequestData } from '../@types/queries'\n\nexport const chatRequset = async (sessionClient: any, data: ChatRequestData) => {\n const { text, languageCode, sessionPath } = data\n const request = {\n session: sessionPath,\n queryInput: {\n text: {\n text,\n languageCode,\n },\n },\n }\n const responses = await sessionClient.detectIntent(request)\n return responses\n}\n","import { ChatEventData } from '../@types/queries'\n\nexport const chatEvent = async (sessionClient: any, data: ChatEventData) => {\n const { eventName, sessionPath, languageCode } = data\n const request = {\n session: sessionPath,\n queryInput: {\n event: {\n name: eventName,\n languageCode,\n },\n },\n }\n const responses = await sessionClient.detectIntent(request)\n return responses\n}\n","import * as express from 'express'\nconst dialogflow = require('dialogflow')\nimport { chatRequset } from './queries/chatRequset'\nimport { chatEvent } from './queries/chatEvent'\nconst { Router } = express\nconst ckDialogflowWebhook = (keyFilename: string) => {\n const sessionClient = new dialogflow.v2.SessionsClient({ keyFilename })\n const router = Router()\n router.post('/ckWebhook/dialogFLow/chatInit', (req, res) => {\n const { sessionId, projectId } = req.body.data\n try {\n const sessionPath = sessionClient.sessionPath(projectId, sessionId)\n\n const result = {\n sessionPath,\n }\n res.json({ result })\n } catch (err) {\n console.log(err)\n }\n })\n router.post('/ckWebhook/dialogFLow/chatRequest', async (req, res) => {\n try {\n const { data } = req.body\n const result = await chatRequset(sessionClient, data)\n res.json({ result })\n } catch(err){\n console.log(err)\n }\n })\n router.post('/ckWebhook/dialogFLow/chatEvent', async (req, res) => {\n try{\n const { data } = req.body\n const result = await chatEvent(sessionClient, data)\n res.json({ result })\n } catch(err){\n console.log(err)\n }\n })\n return router\n}\nexport default ckDialogflowWebhook\n"],"names":["express.Router"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAqDA;AACO,SAAS,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE;AAC7D,IAAI,SAAS,KAAK,CAAC,KAAK,EAAE,EAAE,OAAO,KAAK,YAAY,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,UAAU,OAAO,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;AAChH,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,EAAE,UAAU,OAAO,EAAE,MAAM,EAAE;AAC/D,QAAQ,SAAS,SAAS,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;AACnG,QAAQ,SAAS,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;AACtG,QAAQ,SAAS,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,EAAE;AACtH,QAAQ,IAAI,CAAC,CAAC,SAAS,GAA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;oBACV,qBAAM,SAAS,CAAC,aAAa,EAAE,IAAI,CAAC,EAAA;;oBAA7C,MAAM,GAAG,SAAoC;oBACnD,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,QAAA,EAAE,CAAC,CAAA;;;;oBAElB,OAAO,CAAC,GAAG,CAAC,KAAG,CAAC,CAAA;;;;;SAEnB,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf;;;;"} -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | roots: ['/src'], 3 | transform: { 4 | '^.+\\.ts?$': 'ts-jest', 5 | }, 6 | testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.ts?$', 7 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], 8 | } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ck-dialogflow-webhook", 3 | "version": "0.1.0", 4 | "description": "SOVA dialog webhook", 5 | "homepage": "https://sova.ai", 6 | "authors": [ 7 | { 8 | "name": "sova.ai", 9 | "gitHub": "https://github.com/sovaai" 10 | } 11 | ], 12 | "files": [ 13 | "dist" 14 | ], 15 | "main": "dist/index.js", 16 | "module": "dist/index.es.js", 17 | "engines": { 18 | "node": ">=10", 19 | "npm": ">=5" 20 | }, 21 | "scripts": { 22 | "start": "rollup -c -w", 23 | "build": "rollup -c", 24 | "commit-all": "git add . && git-cz", 25 | "changelog": "./node_modules/.bin/conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md" 26 | }, 27 | "keywords": [ 28 | "SOVA", 29 | "chat-kit-module" 30 | ], 31 | "license": "Apache-2.0", 32 | "peerDependencies": { 33 | "express": "^4.17.1" 34 | }, 35 | "devDependencies": { 36 | "@rollup/plugin-commonjs": "^11.0.2", 37 | "@rollup/plugin-json": "^4.1.0", 38 | "@rollup/plugin-node-resolve": "^7.1.3", 39 | "@rollup/plugin-replace": "^2.3.3", 40 | "@types/dialogflow": "^4.0.4", 41 | "@types/express": "^4.17.7", 42 | "@types/node": "^13.13.15", 43 | "@typescript-eslint/eslint-plugin": "^2.24.0", 44 | "@typescript-eslint/parser": "^2.24.0", 45 | "@wessberg/rollup-plugin-ts": "^1.2.23", 46 | "commitizen": "^4.0.3", 47 | "conventional-changelog-cli": "^2.0.31", 48 | "cz-conventional-changelog": "^3.1.0", 49 | "dialogflow": "^1.2.0", 50 | "eslint": "^6.8.0", 51 | "eslint-config-prettier": "^6.10.1", 52 | "eslint-config-react": "^1.1.7", 53 | "eslint-plugin-prettier": "^3.1.2", 54 | "jest": "^25.1.0", 55 | "prettier": "^1.19.1", 56 | "rollup": "^2.1.0", 57 | "rollup-plugin-peer-deps-external": "^2.2.2", 58 | "ts-jest": "^25.2.1", 59 | "ts-loader": "^6.2.2", 60 | "typescript": "^3.8.3" 61 | }, 62 | "repository": { 63 | "type": "git", 64 | "url": "git@github.com:sovaai/chatKit-dialogflow-webhook.git" 65 | }, 66 | "config": { 67 | "commitizen": { 68 | "path": "./node_modules/cz-conventional-changelog" 69 | } 70 | }, 71 | "dependencies": {} 72 | } 73 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | **Dialogflow webhook** –  mechanism for alerting you to system events through callbacks. 2 | You can use this webhook with [CK Dialogflow module](https://github.com/sovaai/chatKit-dialogflow-module 'read about this module'). 3 | 4 | # :space_invader: Install 5 | 6 | For install library you need enter next comand: 7 | 8 | ```javascript 9 | npm i ck-dialogflow-webhook 10 | ``` 11 | 12 | # Usage 13 | 14 | ```javascript 15 | import * as express from 'express' 16 | 17 | import ckDialogflowWebhook from 'ck-webhook-dialogflow' 18 | const configPath = 19 | const dialogflow = ckDialogflowWebhook(configPath) 20 | 21 | const app = express() 22 | 23 | app.use(dialogflow) 24 | ``` 25 | 26 | You need to set up authentication. The client application that uses the API must be authenticated and granted access to the requested resources. You need create a service account and download the private key file (token). Instruction about this you can reed [here](https://cloud.google.com/dialogflow/es/docs/quick/setup?authuser=1) (title "Set up authentication") 27 | 28 | ## Routes 29 | 30 | ### /ckWebhook/dialogFLow/chatInit 31 | 32 | ```javascript 33 | router.post('/ckWebhook/dialogFLow/chatInit', (req, res) => { 34 | const { sessionId, projectId } = req.body.data 35 | try { 36 | const sessionPath = sessionClient.sessionPath(projectId, sessionId) 37 | 38 | const result = { 39 | sessionPath, 40 | } 41 | res.json({ result }) 42 | } catch (err) { 43 | console.log(err) 44 | } 45 | }) 46 | ``` 47 | 48 | ### /ckWebhook/dialogFLow/chatRequest 49 | 50 | ```javascript 51 | router.post('/ckWebhook/dialogFLow/chatRequest', async (req, res) => { 52 | try { 53 | const { data } = req.body 54 | const result = await chatRequset(sessionClient, data) 55 | res.json({ result }) 56 | } catch (err) { 57 | console.log(err) 58 | } 59 | }) 60 | ``` 61 | 62 | ### /ckWebhook/dialogFLow/chatEvent 63 | 64 | ```javascript 65 | router.post('/ckWebhook/dialogFLow/chatEvent', async (req, res) => { 66 | try { 67 | const { data } = req.body 68 | const result = await chatEvent(sessionClient, data) 69 | res.json({ result }) 70 | } catch (err) { 71 | console.log(err) 72 | } 73 | }) 74 | ``` 75 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import typescript from '@wessberg/rollup-plugin-ts' 2 | import commonjs from '@rollup/plugin-commonjs' 3 | import peerDepsExternal from 'rollup-plugin-peer-deps-external' 4 | import resolve from '@rollup/plugin-node-resolve' 5 | import json from '@rollup/plugin-json' 6 | import pkg from './package.json' 7 | 8 | export default { 9 | input: 'src/index.ts', 10 | output: [ 11 | { 12 | file: pkg.main, 13 | format: 'cjs', 14 | exports: 'named', 15 | sourcemap: true, 16 | }, 17 | { 18 | file: pkg.module, 19 | format: 'es', 20 | exports: 'named', 21 | sourcemap: true, 22 | }, 23 | ], 24 | plugins: [ 25 | commonjs(), 26 | json(), 27 | peerDepsExternal(), 28 | resolve(), 29 | typescript(), 30 | ], 31 | } 32 | -------------------------------------------------------------------------------- /src/@types/common.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'dialogflow' 2 | -------------------------------------------------------------------------------- /src/@types/queries.d.ts: -------------------------------------------------------------------------------- 1 | export interface ChatRequestData { 2 | sessionPath: string 3 | text: string 4 | languageCode: string 5 | } 6 | export interface ChatEventData { 7 | sessionPath: string 8 | eventName: string 9 | languageCode: string 10 | } -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import * as express from 'express' 2 | const dialogflow = require('dialogflow') 3 | import { chatRequset } from './queries/chatRequset' 4 | import { chatEvent } from './queries/chatEvent' 5 | const { Router } = express 6 | const ckDialogflowWebhook = (keyFilename: string) => { 7 | const sessionClient = new dialogflow.v2.SessionsClient({ keyFilename }) 8 | const router = Router() 9 | router.post('/ckWebhook/dialogFLow/chatInit', (req, res) => { 10 | const { sessionId, projectId } = req.body.data 11 | try { 12 | const sessionPath = sessionClient.sessionPath(projectId, sessionId) 13 | 14 | const result = { 15 | sessionPath, 16 | } 17 | res.json({ result }) 18 | } catch (err) { 19 | console.log(err) 20 | } 21 | }) 22 | router.post('/ckWebhook/dialogFLow/chatRequest', async (req, res) => { 23 | try { 24 | const { data } = req.body 25 | const result = await chatRequset(sessionClient, data) 26 | res.json({ result }) 27 | } catch(err){ 28 | console.log(err) 29 | } 30 | }) 31 | router.post('/ckWebhook/dialogFLow/chatEvent', async (req, res) => { 32 | try{ 33 | const { data } = req.body 34 | const result = await chatEvent(sessionClient, data) 35 | res.json({ result }) 36 | } catch(err){ 37 | console.log(err) 38 | } 39 | }) 40 | return router 41 | } 42 | export default ckDialogflowWebhook 43 | -------------------------------------------------------------------------------- /src/queries/chatEvent.ts: -------------------------------------------------------------------------------- 1 | import { ChatEventData } from '../@types/queries' 2 | 3 | export const chatEvent = async (sessionClient: any, data: ChatEventData) => { 4 | const { eventName, sessionPath, languageCode } = data 5 | const request = { 6 | session: sessionPath, 7 | queryInput: { 8 | event: { 9 | name: eventName, 10 | languageCode, 11 | }, 12 | }, 13 | } 14 | const responses = await sessionClient.detectIntent(request) 15 | return responses 16 | } 17 | -------------------------------------------------------------------------------- /src/queries/chatRequset.ts: -------------------------------------------------------------------------------- 1 | import { ChatRequestData } from '../@types/queries' 2 | 3 | export const chatRequset = async (sessionClient: any, data: ChatRequestData) => { 4 | const { text, languageCode, sessionPath } = data 5 | const request = { 6 | session: sessionPath, 7 | queryInput: { 8 | text: { 9 | text, 10 | languageCode, 11 | }, 12 | }, 13 | } 14 | const responses = await sessionClient.detectIntent(request) 15 | return responses 16 | } 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": false, 6 | "skipLibCheck": true, 7 | "esModuleInterop": true, 8 | "allowSyntheticDefaultImports": true, 9 | "strict": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "noEmit": true, 16 | "jsx": "react", 17 | /* "composite": true, */ 18 | "declaration": true 19 | }, 20 | "plugins": [{ "name": "typescript-tslint-plugin" }], 21 | "exclude": ["node_modules"] 22 | } 23 | --------------------------------------------------------------------------------