├── .editorconfig ├── .env-template ├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ └── npm-publish.yml ├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── dist ├── index.d.ts ├── index.es.d.ts ├── index.es.js ├── index.es.js.map ├── index.js └── index.js.map ├── docs └── apimethods │ ├── chatEvent.md │ ├── chatInit.md │ ├── chatRequest.md │ ├── reset.md │ └── setInfo.md ├── jest.config.js ├── package-lock.json ├── package.json ├── rollup.config.js ├── src ├── @types │ ├── common.d.ts │ ├── dialogflow.d.ts │ ├── module.d.ts │ ├── moduleEvents.d.ts │ └── uiEvents.d.ts ├── events │ ├── defaultUiEvents.ts │ └── moduleEvents.ts ├── index.ts ├── module │ └── dialogflow.ts └── utils │ ├── fetch.ts │ ├── regExp.ts │ └── resultControl.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 | -------------------------------------------------------------------------------- /.env-template: -------------------------------------------------------------------------------- 1 | INF_API_URL= -------------------------------------------------------------------------------- /.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 | .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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **ck-dialogflow** is separate module that connects to the widget. It is used to describe scripts and dialog rules. 2 | 3 | ## Install 4 | For install `ck-dialogflow` enter next command: 5 | ```javascript 6 | npm i ck-dialogflow 7 | ``` 8 | 9 | ## Quick start 10 | For quick start `ck-dialogflow` enter next command: 11 | ``` 12 | import ckModuleInit from 'ck-dialogflow' 13 | const DialogflowModule = ckDialogflowInit(dialogflowConfig) 14 | ``` 15 | 16 | 17 | # Description 18 | ## Dialogflow config 19 | Configuration file includes: 20 | ```javascript 21 | const rasaConfig = { 22 | info: { 23 | projectId: string 24 | sessionId: string 25 | } 26 | api?: { 27 | infApiUrl: string, 28 | }, 29 | events?: { 30 | ready?: string, 31 | }, 32 | moduleEvents?: ModuleEvents 33 | uiEvents?: UiEventsList 34 | } 35 | moduleEvents?: { 36 | chatInit: (module: DialogflowModule, data: ChatInitData) => void 37 | chatRequest: (module: DialogflowModule, data: ChatRequestData) => void 38 | chatEvent: (module: DialogflowModule, data: ChatEventData) => void 39 | setInfo: (module: DialogflowModule, data: SetInfoData) => void 40 | reset: (module: DialogflowModule, data: ResetData) => void 41 | }, 42 | uiEvents?: { 43 | sendMessage: (data: SendMessageData) => void 44 | uiManagment: (uiManagmentEvent: uiManagmentEvents, data: UIManagmentData) => void 45 | notifications: (notificationsEvent: NotificationsEvents, data: NotificationsData) => void 46 | modules: (modulesEvent: ModulesEvents, data: ModulesData) => void 47 | } 48 | } 49 | ``` 50 | 51 | ## API methods 52 | `ck-dialogflow` has next API methods: 53 | 54 | | API method | | 55 | |-----------------------------------------------------------------------------------------------------------------------------------------|----------------------------------| 56 | | [chatInit](https://github.com/sovaai/chatKit-dialogflow-module/blob/master/docs/apimethods/chatInit.md "Read about this method") | Dialog Initialization | 57 | | [chatRequest](https://github.com/sovaai/chatKit-dialogflow-module/blob/master/docs/apimethods/chatRequest.md "Read about this method") | Sending user messages | 58 | | [chatEvent](https://github.com/sovaai/chatKit-dialogflow-module/blob/master/docs/apimethods/chatEvent.md "Read about this method") | Chat events | 59 | | [setInfo](https://github.com/sovaai/chatKit-dialogflow-module/blob/master/docs/apimethods/setInfo.md "Read about this method") | Settings information | 60 | | [reset](https://github.com/sovaai/chatKit-dialogflow-module/blob/master/docs/apimethods/reset.md "Read about this method") | Reset dialogue | 61 | 62 | 63 | ## Dialogflow.ModuleDispatcher 64 | `moduleDispatcher` - method of event management. 65 | `moduleDispatcher` select method and transmits necessary data to it. 66 | 67 | For example: 68 | ```javascript 69 | import moduleInit from 'ck-dialogflow' 70 | const ckDialogflow = moduleInit(dlConfig) 71 | ckDialogflow.moduleDispatcher('chatInit', { clientConfig: { siteLang: 'ru' } }) 72 | ``` 73 | -------------------------------------------------------------------------------- /dist/index.d.ts: -------------------------------------------------------------------------------- 1 | import { DialogflowInfo, ModuleEvents, UiEvents, DialogflowConfig, DialogflowApi, DialogFlowEvents } from "../@types/dialogflow"; 2 | import { ChatInitData, ChatEventData, ChatRequestData, SetInfoData, ModuleEventsNames } from "../@types/moduleEvents"; 3 | import { UiEventsNames, UiEventsData } from "../@types/uiEvents"; 4 | import { DialogflowConfig as DialogflowConfig$0 } from './@types/dialogflow'; 5 | declare class DialogflowModule { 6 | name: string; 7 | info: DialogflowInfo; 8 | moduleEvents: ModuleEvents; 9 | uiEvents: UiEvents; 10 | api: DialogflowApi; 11 | events: DialogFlowEvents; 12 | constructor(config: DialogflowConfig); 13 | moduleDispatcher: (event: ModuleEventsNames, data?: SetInfoData | import("@types/moduleEvents").ResetData | ChatInitData | ChatRequestData | ChatEventData | undefined) => Promise; 14 | uiDispatcher: (event: UiEventsNames, data: UiEventsData) => void; 15 | } 16 | declare const ckModuleInit: (config: DialogflowConfig$0) => DialogflowModule; 17 | export { ckModuleInit as default }; 18 | -------------------------------------------------------------------------------- /dist/index.es.d.ts: -------------------------------------------------------------------------------- 1 | import { DialogflowInfo, ModuleEvents, UiEvents, DialogflowConfig, DialogflowApi, DialogFlowEvents } from "../@types/dialogflow"; 2 | import { ChatInitData, ChatEventData, ChatRequestData, SetInfoData, ModuleEventsNames } from "../@types/moduleEvents"; 3 | import { UiEventsNames, UiEventsData } from "../@types/uiEvents"; 4 | import { DialogflowConfig as DialogflowConfig$0 } from './@types/dialogflow'; 5 | declare class DialogflowModule { 6 | name: string; 7 | info: DialogflowInfo; 8 | moduleEvents: ModuleEvents; 9 | uiEvents: UiEvents; 10 | api: DialogflowApi; 11 | events: DialogFlowEvents; 12 | constructor(config: DialogflowConfig); 13 | moduleDispatcher: (event: ModuleEventsNames, data?: SetInfoData | import("@types/moduleEvents").ResetData | ChatInitData | ChatRequestData | ChatEventData | undefined) => Promise; 14 | uiDispatcher: (event: UiEventsNames, data: UiEventsData) => void; 15 | } 16 | declare const ckModuleInit: (config: DialogflowConfig$0) => DialogflowModule; 17 | export { ckModuleInit as default }; 18 | -------------------------------------------------------------------------------- /dist/index.es.js: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 8 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 9 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 10 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 11 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 12 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 13 | PERFORMANCE OF THIS SOFTWARE. 14 | ***************************************************************************** */ 15 | 16 | function __awaiter(thisArg, _arguments, P, generator) { 17 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 18 | return new (P || (P = Promise))(function (resolve, reject) { 19 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 20 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 21 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 22 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 23 | }); 24 | } 25 | 26 | function __generator(thisArg, body) { 27 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 28 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 29 | function verb(n) { return function (v) { return step([n, v]); }; } 30 | function step(op) { 31 | if (f) throw new TypeError("Generator is already executing."); 32 | while (_) try { 33 | 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; 34 | if (y = 0, t) op = [op[0] & 2, t.value]; 35 | switch (op[0]) { 36 | case 0: case 1: t = op; break; 37 | case 4: _.label++; return { value: op[1], done: false }; 38 | case 5: _.label++; y = op[1]; op = [0]; continue; 39 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 40 | default: 41 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 42 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 43 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 44 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 45 | if (t[2]) _.ops.pop(); 46 | _.trys.pop(); continue; 47 | } 48 | op = body.call(thisArg, _); 49 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 50 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 51 | } 52 | } 53 | 54 | var defaultSendMessage = function (data) { return console.log('no SendMessage'); }; 55 | var defaultUIManagment = function (uiManagmentEvent, data) { return console.log('no UIManagment'); }; 56 | var defaultNotifications = function (notificationsEvent, data) { 57 | return console.log('no Notifications'); 58 | }; 59 | var defaultModules = function (notificationsEvent, data) { return console.log('no modules'); }; 60 | 61 | var msgRegExpReplace = { 62 | links: { 63 | regexp: /href="event:/gim, 64 | replace: 'data-type="outbound" rel="noopener noreferrer" href="', 65 | }, 66 | userLinks: { 67 | regexp: /]*(?!data-request))?(data-request="([^"]+)?")?>(.*?)<\/userlink>/gim, 68 | replace: "$4", 69 | }, 70 | newPara: { 71 | regexp: / \(NEW_PARA\)|\(NEW_PARA\)/gim, 72 | replace: '', 73 | }, 74 | newParaButtons: { 75 | regexp: / \(NEW_PARA\)(.*)|\(NEW_PARA\)(.*)/gim, 76 | replace: "$1$2", 77 | }, 78 | userLinksAsButtons: { 79 | regexp: /]*(?!data-request))?(data-request="([^"]+)?")?>(.*?)<\/userlink>/gim, 80 | replace: "$4", 81 | }, 82 | }; 83 | var links = msgRegExpReplace.links; 84 | var userLinks = msgRegExpReplace.userLinks; 85 | var userLinksAsButtons = msgRegExpReplace.userLinksAsButtons; 86 | var newPara = msgRegExpReplace.newPara; 87 | var newParaButtons = msgRegExpReplace.newParaButtons; 88 | var msgPrepare = function (text, context) { 89 | if (/UserLinkAsButton/gim.test(context === null || context === void 0 ? void 0 : context.wcmd_show_mode)) { 90 | if (/\(NEW_PARA\)/gim.test(context === null || context === void 0 ? void 0 : context.wcmd_show_mode)) { 91 | return text 92 | .replace(links === null || links === void 0 ? void 0 : links.regexp, links === null || links === void 0 ? void 0 : links.replace) 93 | .replace(newParaButtons === null || newParaButtons === void 0 ? void 0 : newParaButtons.regexp, newParaButtons === null || newParaButtons === void 0 ? void 0 : newParaButtons.replace) 94 | .replace(userLinks === null || userLinks === void 0 ? void 0 : userLinks.regexp, userLinks === null || userLinks === void 0 ? void 0 : userLinks.replace); 95 | } 96 | else { 97 | return text 98 | .replace(links === null || links === void 0 ? void 0 : links.regexp, links === null || links === void 0 ? void 0 : links.replace) 99 | .replace(newPara === null || newPara === void 0 ? void 0 : newPara.regexp, newPara === null || newPara === void 0 ? void 0 : newPara.replace) 100 | .replace(userLinksAsButtons === null || userLinksAsButtons === void 0 ? void 0 : userLinksAsButtons.regexp, userLinksAsButtons === null || userLinksAsButtons === void 0 ? void 0 : userLinksAsButtons.replace); 101 | } 102 | } 103 | return text 104 | .replace(links === null || links === void 0 ? void 0 : links.regexp, links === null || links === void 0 ? void 0 : links.replace) 105 | .replace(newPara === null || newPara === void 0 ? void 0 : newPara.regexp, newPara === null || newPara === void 0 ? void 0 : newPara.replace) 106 | .replace(userLinks === null || userLinks === void 0 ? void 0 : userLinks.regexp, userLinks === null || userLinks === void 0 ? void 0 : userLinks.replace); 107 | }; 108 | 109 | var resultControl = function (module, result) { return __awaiter(void 0, void 0, void 0, function () { 110 | var queryResult, text, data, _a, data; 111 | var _b, _c; 112 | return __generator(this, function (_d) { 113 | switch (_d.label) { 114 | case 0: 115 | queryResult = result[0].queryResult; 116 | if (!(queryResult === null || queryResult === void 0 ? void 0 : queryResult.fulfillmentText)) return [3 /*break*/, 3]; 117 | text = msgPrepare(queryResult === null || queryResult === void 0 ? void 0 : queryResult.fulfillmentText); 118 | data = { 119 | text: text ? text : 'что-то не так', 120 | sender: 'request', 121 | showRate: (_b = result === null || result === void 0 ? void 0 : result.text) === null || _b === void 0 ? void 0 : _b.showRate, 122 | type: 'text', 123 | module: module.name 124 | }; 125 | _a = text; 126 | if (!_a) return [3 /*break*/, 2]; 127 | return [4 /*yield*/, module.uiDispatcher('sendMessage', data)]; 128 | case 1: 129 | _a = (_d.sent()); 130 | _d.label = 2; 131 | case 2: 132 | _d.label = 3; 133 | case 3: 134 | if (!((_c = result === null || result === void 0 ? void 0 : result.text) === null || _c === void 0 ? void 0 : _c.showRate)) return [3 /*break*/, 5]; 135 | data = { 136 | uiManagmentEvent: 'showRate', 137 | data: true, 138 | }; 139 | return [4 /*yield*/, module.uiDispatcher('uiManagment', data)]; 140 | case 4: 141 | _d.sent(); 142 | _d.label = 5; 143 | case 5: return [2 /*return*/]; 144 | } 145 | }); 146 | }); }; 147 | 148 | var postFetch = function (data, url) { return __awaiter(void 0, void 0, void 0, function () { 149 | var fetchResponse, fetchResult, error_1; 150 | return __generator(this, function (_a) { 151 | switch (_a.label) { 152 | case 0: 153 | _a.trys.push([0, 3, , 4]); 154 | return [4 /*yield*/, fetch(url, { 155 | headers: { 156 | 'Content-Type': 'application/json', 157 | Accept: 'application/json', 158 | }, 159 | method: 'POST', 160 | body: JSON.stringify({ data: data }), 161 | })]; 162 | case 1: 163 | fetchResponse = _a.sent(); 164 | return [4 /*yield*/, fetchResponse.json()]; 165 | case 2: 166 | fetchResult = _a.sent(); 167 | return [2 /*return*/, fetchResult.result]; 168 | case 3: 169 | error_1 = _a.sent(); 170 | console.log(error_1); 171 | return [3 /*break*/, 4]; 172 | case 4: return [2 /*return*/]; 173 | } 174 | }); 175 | }); }; 176 | 177 | var setInfo = function (module, data) { 178 | var sessionPath = data.sessionPath, sessionId = data.sessionId, projectId = data.projectId; 179 | if (sessionPath) 180 | module.info.sessionPath = sessionPath; 181 | if (sessionId) 182 | module.info.sessionId = sessionId; 183 | if (projectId) 184 | module.info.projectId = projectId; 185 | }; 186 | var reset = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 187 | return __generator(this, function (_a) { 188 | module.moduleDispatcher('chatInit', data); 189 | return [2 /*return*/]; 190 | }); 191 | }); }; 192 | var chatInit = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 193 | var _a, sessionId, projectId, eventName, infApiUrl, initData, url, result, eventData; 194 | return __generator(this, function (_b) { 195 | switch (_b.label) { 196 | case 0: 197 | _a = module.info, sessionId = _a.sessionId, projectId = _a.projectId; 198 | eventName = module.events.ready; 199 | infApiUrl = module.api.infApiUrl; 200 | initData = { 201 | sessionId: sessionId, 202 | projectId: projectId, 203 | }; 204 | url = infApiUrl + "/ckWebhook/dialogFLow/chatInit"; 205 | return [4 /*yield*/, postFetch(initData, url)]; 206 | case 1: 207 | result = _b.sent(); 208 | module.moduleDispatcher('setInfo', result); 209 | eventData = { 210 | eventName: eventName, 211 | context: data.clientConfig, 212 | }; 213 | module.moduleDispatcher('chatEvent', eventData); 214 | return [2 /*return*/]; 215 | } 216 | }); 217 | }); }; 218 | var chatRequest = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 219 | var sessionPath, infApiUrl, text, context, languageCode, requestData, url, result; 220 | return __generator(this, function (_a) { 221 | switch (_a.label) { 222 | case 0: 223 | sessionPath = module.info.sessionPath; 224 | infApiUrl = module.api.infApiUrl; 225 | text = data.text, context = data.context; 226 | languageCode = (context === null || context === void 0 ? void 0 : context.env_sitelang) ? context === null || context === void 0 ? void 0 : context.env_sitelang : 'ru'; 227 | requestData = { 228 | sessionPath: sessionPath, 229 | text: text, 230 | languageCode: languageCode, 231 | }; 232 | url = infApiUrl + "/ckWebhook/dialogFLow/chatRequest"; 233 | return [4 /*yield*/, postFetch(requestData, url)]; 234 | case 1: 235 | result = _a.sent(); 236 | resultControl(module, result); 237 | return [2 /*return*/]; 238 | } 239 | }); 240 | }); }; 241 | var chatEvent = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 242 | var sessionPath, infApiUrl, eventName, context, languageCode, requestData, url, result; 243 | return __generator(this, function (_a) { 244 | switch (_a.label) { 245 | case 0: 246 | sessionPath = module.info.sessionPath; 247 | infApiUrl = module.api.infApiUrl; 248 | eventName = data.eventName, context = data.context; 249 | languageCode = (context === null || context === void 0 ? void 0 : context.env_sitelang) ? context === null || context === void 0 ? void 0 : context.env_sitelang : 'ru'; 250 | requestData = { 251 | sessionPath: sessionPath, 252 | eventName: eventName, 253 | languageCode: languageCode, 254 | }; 255 | url = infApiUrl + "/ckWebhook/dialogFLow/chatEvent"; 256 | return [4 /*yield*/, postFetch(requestData, url)]; 257 | case 1: 258 | result = _a.sent(); 259 | resultControl(module, result); 260 | return [2 /*return*/]; 261 | } 262 | }); 263 | }); }; 264 | 265 | var INF_API_URL = { "env": { "INF_API_URL": "http://localhost:5000" } }.env.INF_API_URL; 266 | var DialogflowModule = /** @class */ (function () { 267 | function DialogflowModule(config) { 268 | var _this = this; 269 | this.moduleDispatcher = function (event, data) { return __awaiter(_this, void 0, void 0, function () { 270 | var _a, _b, _c, _d, _e; 271 | return __generator(this, function (_f) { 272 | switch (_f.label) { 273 | case 0: 274 | _a = event === 'chatInit' && data; 275 | if (!_a) return [3 /*break*/, 2]; 276 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 277 | case 1: 278 | _a = (_f.sent()); 279 | _f.label = 2; 280 | case 2: 281 | _b = event === 'chatEvent' && data; 282 | if (!_b) return [3 /*break*/, 4]; 283 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 284 | case 3: 285 | _b = (_f.sent()); 286 | _f.label = 4; 287 | case 4: 288 | _c = event === 'chatRequest' && data; 289 | if (!_c) return [3 /*break*/, 6]; 290 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 291 | case 5: 292 | _c = (_f.sent()); 293 | _f.label = 6; 294 | case 6: 295 | _d = event === 'setInfo' && data; 296 | if (!_d) return [3 /*break*/, 8]; 297 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 298 | case 7: 299 | _d = (_f.sent()); 300 | _f.label = 8; 301 | case 8: 302 | _e = event === 'reset' && data; 303 | if (!_e) return [3 /*break*/, 10]; 304 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 305 | case 9: 306 | _e = (_f.sent()); 307 | _f.label = 10; 308 | case 10: 309 | return [2 /*return*/]; 310 | } 311 | }); 312 | }); }; 313 | this.uiDispatcher = function (event, data) { 314 | event === 'sendMessage' && _this.uiEvents[event](data); 315 | event === 'uiManagment' && 316 | _this.uiEvents[event](data.uiManagmentEvent, data.data); 317 | event === 'notifications' && 318 | _this.uiEvents[event](data.notificationEvent, data.data); 319 | event === 'modules' && _this.uiEvents[event](data.modulesEvent, data.data); 320 | }; 321 | var info = config.info, moduleEvents = config.moduleEvents, uiEvents = config.uiEvents, api = config.api, events = config.events; 322 | this.name = 'dialogflow'; 323 | this.info = { 324 | sessionId: info.sessionId, 325 | projectId: info.projectId, 326 | sessionPath: '', 327 | }; 328 | this.events = { 329 | ready: (events === null || events === void 0 ? void 0 : events.ready) ? events.ready : 'ready', 330 | }; 331 | this.api = { 332 | infApiUrl: (api === null || api === void 0 ? void 0 : api.infApiUrl) || INF_API_URL || '', 333 | }; 334 | this.uiEvents = { 335 | sendMessage: (uiEvents === null || uiEvents === void 0 ? void 0 : uiEvents.sendMessage) || defaultSendMessage, 336 | uiManagment: (uiEvents === null || uiEvents === void 0 ? void 0 : uiEvents.uiManagment) || defaultUIManagment, 337 | notifications: (uiEvents === null || uiEvents === void 0 ? void 0 : uiEvents.notifications) || defaultNotifications, 338 | modules: (uiEvents === null || uiEvents === void 0 ? void 0 : uiEvents.modules) || defaultModules, 339 | }; 340 | this.moduleEvents = { 341 | setInfo: (moduleEvents === null || moduleEvents === void 0 ? void 0 : moduleEvents.setInfo) || setInfo, 342 | chatInit: (moduleEvents === null || moduleEvents === void 0 ? void 0 : moduleEvents.chatInit) || chatInit, 343 | chatEvent: (moduleEvents === null || moduleEvents === void 0 ? void 0 : moduleEvents.chatEvent) || chatEvent, 344 | chatRequest: (moduleEvents === null || moduleEvents === void 0 ? void 0 : moduleEvents.chatRequest) || chatRequest, 345 | reset: (moduleEvents === null || moduleEvents === void 0 ? void 0 : moduleEvents.reset) || reset, 346 | }; 347 | } 348 | return DialogflowModule; 349 | }()); 350 | 351 | var ckModuleInit = function (config) { return new DialogflowModule(config); }; 352 | 353 | export default ckModuleInit; 354 | //# sourceMappingURL=index.es.js.map 355 | -------------------------------------------------------------------------------- /dist/index.es.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.es.js","sources":["../node_modules/tslib/tslib.es6.js","../src/events/defaultUiEvents.ts","../src/utils/regExp.ts","../src/utils/resultControl.ts","../src/utils/fetch.ts","../src/events/moduleEvents.ts","../src/module/dialogflow.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 { SendMessageData, UIManagmentEvents, NotificationsEvents, ModulesEvents, ModulesData } from '../@types/uiEvents'\n\nexport const defaultSendMessage = (data: SendMessageData) => console.log('no SendMessage')\nexport const defaultUIManagment = (uiManagmentEvent: UIManagmentEvents, data: any) => console.log('no UIManagment')\nexport const defaultNotifications = (notificationsEvent: NotificationsEvents, data: any) =>\n console.log('no Notifications')\nexport const defaultModules = (notificationsEvent: ModulesEvents, data: any) => console.log('no modules')\n","const msgRegExpReplace = {\n links: {\n regexp: /href=\"event:/gim,\n replace: 'data-type=\"outbound\" rel=\"noopener noreferrer\" href=\"',\n },\n userLinks: {\n regexp: /]*(?!data-request))?(data-request=\"([^\"]+)?\")?>(.*?)<\\/userlink>/gim,\n replace: \"$4\",\n },\n newPara: {\n regexp: / \\(NEW_PARA\\)|\\(NEW_PARA\\)/gim,\n replace: '',\n },\n newParaButtons: {\n regexp: / \\(NEW_PARA\\)(.*)|\\(NEW_PARA\\)(.*)/gim,\n replace: \"$1$2\",\n },\n userLinksAsButtons: {\n regexp: /]*(?!data-request))?(data-request=\"([^\"]+)?\")?>(.*?)<\\/userlink>/gim,\n replace: \"$4\",\n },\n}\n\nconst links = msgRegExpReplace.links\nconst userLinks = msgRegExpReplace.userLinks\nconst userLinksAsButtons = msgRegExpReplace.userLinksAsButtons\nconst newPara = msgRegExpReplace.newPara\nconst newParaButtons = msgRegExpReplace.newParaButtons\n\nconst msgPrepare = (text: string, context?: any) => {\n if (/UserLinkAsButton/gim.test(context?.wcmd_show_mode)) {\n if (/\\(NEW_PARA\\)/gim.test(context?.wcmd_show_mode)) {\n return text\n .replace(links?.regexp, links?.replace)\n .replace(newParaButtons?.regexp, newParaButtons?.replace)\n .replace(userLinks?.regexp, userLinks?.replace)\n } else {\n return text\n .replace(links?.regexp, links?.replace)\n .replace(newPara?.regexp, newPara?.replace)\n .replace(userLinksAsButtons?.regexp, userLinksAsButtons?.replace)\n }\n }\n return text\n .replace(links?.regexp, links?.replace)\n .replace(newPara?.regexp, newPara?.replace)\n .replace(userLinks?.regexp, userLinks?.replace)\n}\n\nexport { msgPrepare }\n","import { DialogflowModule } from '../@types/dialogflow'\nimport { SendMessageData, UIManagmentData } from '../@types/uiEvents'\nimport { msgPrepare } from './regExp'\n\nexport const resultControl = async (module: DialogflowModule, result: any) => {\n const {queryResult} = result[0]\n if (queryResult?.fulfillmentText) {\n const text = msgPrepare(queryResult?.fulfillmentText)\n const data: SendMessageData = {\n text: text? text: 'что-то не так',\n sender: 'request',\n showRate: result?.text?.showRate,\n type: 'text',\n module: module.name\n }\n text && (await module.uiDispatcher('sendMessage', data))\n }\n if (result?.text?.showRate) {\n const data: UIManagmentData = {\n uiManagmentEvent: 'showRate',\n data: true,\n }\n await module.uiDispatcher('uiManagment', data)\n }\n}\n","import { ChatInitFetch, ChatRequestFetch, ChatEventFetch } from '../@types/common'\n\nexport const postFetch = async (data: ChatInitFetch | ChatRequestFetch | ChatEventFetch, url: string) => {\n try {\n const fetchResponse = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n },\n method: 'POST',\n body: JSON.stringify({ data }),\n })\n const fetchResult = await fetchResponse.json()\n return fetchResult.result\n } catch (error) {\n console.log(error)\n }\n}\n","import { SetInfoData, ChatInitData, ChatRequestData, ChatEventData, ResetData } from '../@types/moduleEvents'\nimport { DialogflowModule } from '../@types/dialogflow'\nimport { resultControl } from '../utils/resultControl'\nimport { postFetch } from '../utils/fetch'\nimport { ChatInitFetch, ChatRequestFetch, ChatEventFetch } from '../@types/common'\n\nexport const setInfo = (module: DialogflowModule, data: SetInfoData) => {\n const { sessionPath, sessionId, projectId } = data\n if (sessionPath) module.info.sessionPath = sessionPath\n if (sessionId) module.info.sessionId = sessionId\n if (projectId) module.info.projectId = projectId\n}\nexport const reset = async (module: DialogflowModule, data: ResetData) => {\n module.moduleDispatcher('chatInit', data)\n}\nexport const chatInit = async (module: DialogflowModule, data: ChatInitData) => {\n const { sessionId, projectId } = module.info\n const eventName = module.events.ready\n const { infApiUrl } = module.api\n const initData: ChatInitFetch = {\n sessionId,\n projectId,\n }\n const url = `${infApiUrl}/ckWebhook/dialogFLow/chatInit`\n const result = await postFetch(initData, url)\n module.moduleDispatcher('setInfo', result)\n const eventData = {\n eventName,\n context: data.clientConfig,\n }\n module.moduleDispatcher('chatEvent', eventData)\n}\n\nexport const chatRequest = async (module: DialogflowModule, data: ChatRequestData) => {\n const { sessionPath } = module.info\n const { infApiUrl } = module.api\n const { text, context } = data\n const languageCode = context?.env_sitelang ? context?.env_sitelang : 'ru'\n const requestData: ChatRequestFetch = {\n sessionPath,\n text,\n languageCode,\n }\n const url = `${infApiUrl}/ckWebhook/dialogFLow/chatRequest`\n const result = await postFetch(requestData, url)\n resultControl(module, result)\n}\nexport const chatEvent = async (module: DialogflowModule, data: ChatEventData) => {\n const { sessionPath } = module.info\n const { infApiUrl } = module.api\n const { eventName, context } = data\n const languageCode = context?.env_sitelang ? context?.env_sitelang : 'ru'\n const requestData: ChatEventFetch = {\n sessionPath,\n eventName,\n languageCode,\n }\n const url = `${infApiUrl}/ckWebhook/dialogFLow/chatEvent`\n const result = await postFetch(requestData, url)\n resultControl(module, result)\n}\n","import {\n DialogflowInfo,\n ModuleEvents,\n UiEvents,\n DialogflowConfig,\n DialogflowApi,\n DialogFlowEvents,\n} from '../@types/dialogflow'\n\nimport {\n ModuleEventsData,\n ChatInitData,\n ChatEventData,\n ChatRequestData,\n SetInfoData,\n ModuleEventsNames,\n} from '../@types/moduleEvents'\nimport {\n UiEventsNames,\n UiEventsData,\n SendMessageData,\n UIManagmentData,\n NotificationsData,\n ModulesData,\n} from '../@types/uiEvents'\nimport { defaultSendMessage, defaultUIManagment, defaultNotifications, defaultModules } from '../events/defaultUiEvents'\nimport { setInfo, chatInit, chatEvent, chatRequest, reset } from '../events/moduleEvents'\nconst { INF_API_URL } = process.env\nclass DialogflowModule {\n name: string\n info: DialogflowInfo\n moduleEvents: ModuleEvents\n uiEvents: UiEvents\n api: DialogflowApi\n events: DialogFlowEvents\n constructor(config: DialogflowConfig) {\n const { info, moduleEvents, uiEvents, api, events } = config\n this.name = 'dialogflow'\n this.info = {\n sessionId: info.sessionId,\n projectId: info.projectId,\n sessionPath: '',\n }\n this.events = {\n ready: events?.ready ? events.ready : 'ready',\n }\n this.api = {\n infApiUrl: api?.infApiUrl || INF_API_URL || '',\n }\n this.uiEvents = {\n sendMessage: uiEvents?.sendMessage || defaultSendMessage,\n uiManagment: uiEvents?.uiManagment || defaultUIManagment,\n notifications: uiEvents?.notifications || defaultNotifications,\n modules: uiEvents?.modules || defaultModules,\n }\n this.moduleEvents = {\n setInfo: moduleEvents?.setInfo || setInfo,\n chatInit: moduleEvents?.chatInit || chatInit,\n chatEvent: moduleEvents?.chatEvent || chatEvent,\n chatRequest: moduleEvents?.chatRequest || chatRequest,\n reset: moduleEvents?.reset || reset,\n }\n }\n moduleDispatcher = async (event: ModuleEventsNames, data?: ModuleEventsData) => {\n event === 'chatInit' && data && (await this.moduleEvents[event](this, data as ChatInitData))\n event === 'chatEvent' && data && (await this.moduleEvents[event](this, data as ChatEventData))\n event === 'chatRequest' && data && (await this.moduleEvents[event](this, data as ChatRequestData))\n event === 'setInfo' && data && (await this.moduleEvents[event](this, data as SetInfoData))\n event === 'reset' && data && (await this.moduleEvents[event](this, data as ChatInitData))\n }\n uiDispatcher = (event: UiEventsNames, data: UiEventsData) => {\n event === 'sendMessage' && this.uiEvents[event](data as SendMessageData)\n event === 'uiManagment' &&\n this.uiEvents[event]((data as UIManagmentData).uiManagmentEvent, (data as UIManagmentData).data)\n event === 'notifications' &&\n this.uiEvents[event]((data as NotificationsData).notificationEvent, (data as NotificationsData).data)\n event === 'modules' && this.uiEvents[event]((data as ModulesData).modulesEvent, (data as ModulesData).data)\n }\n}\nexport { DialogflowModule }\n","import { DialogflowModule } from './module/dialogflow'\nimport { DialogflowConfig } from './@types/dialogflow'\nconst ckModuleInit = (config: DialogflowConfig) => new DialogflowModule(config)\nexport default ckModuleInit\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAqDA;AACO,SAAS,SAAS,CAAC,OAAO,EAA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------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | /*! ***************************************************************************** 6 | Copyright (c) Microsoft Corporation. 7 | 8 | Permission to use, copy, modify, and/or distribute this software for any 9 | purpose with or without fee is hereby granted. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 12 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 13 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 14 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 16 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 | PERFORMANCE OF THIS SOFTWARE. 18 | ***************************************************************************** */ 19 | 20 | function __awaiter(thisArg, _arguments, P, generator) { 21 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 22 | return new (P || (P = Promise))(function (resolve, reject) { 23 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 24 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 25 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 26 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 27 | }); 28 | } 29 | 30 | function __generator(thisArg, body) { 31 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 32 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 33 | function verb(n) { return function (v) { return step([n, v]); }; } 34 | function step(op) { 35 | if (f) throw new TypeError("Generator is already executing."); 36 | while (_) try { 37 | 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; 38 | if (y = 0, t) op = [op[0] & 2, t.value]; 39 | switch (op[0]) { 40 | case 0: case 1: t = op; break; 41 | case 4: _.label++; return { value: op[1], done: false }; 42 | case 5: _.label++; y = op[1]; op = [0]; continue; 43 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 44 | default: 45 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 46 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 47 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 48 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 49 | if (t[2]) _.ops.pop(); 50 | _.trys.pop(); continue; 51 | } 52 | op = body.call(thisArg, _); 53 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 54 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 55 | } 56 | } 57 | 58 | var defaultSendMessage = function (data) { return console.log('no SendMessage'); }; 59 | var defaultUIManagment = function (uiManagmentEvent, data) { return console.log('no UIManagment'); }; 60 | var defaultNotifications = function (notificationsEvent, data) { 61 | return console.log('no Notifications'); 62 | }; 63 | var defaultModules = function (notificationsEvent, data) { return console.log('no modules'); }; 64 | 65 | var msgRegExpReplace = { 66 | links: { 67 | regexp: /href="event:/gim, 68 | replace: 'data-type="outbound" rel="noopener noreferrer" href="', 69 | }, 70 | userLinks: { 71 | regexp: /]*(?!data-request))?(data-request="([^"]+)?")?>(.*?)<\/userlink>/gim, 72 | replace: "$4", 73 | }, 74 | newPara: { 75 | regexp: / \(NEW_PARA\)|\(NEW_PARA\)/gim, 76 | replace: '', 77 | }, 78 | newParaButtons: { 79 | regexp: / \(NEW_PARA\)(.*)|\(NEW_PARA\)(.*)/gim, 80 | replace: "$1$2", 81 | }, 82 | userLinksAsButtons: { 83 | regexp: /]*(?!data-request))?(data-request="([^"]+)?")?>(.*?)<\/userlink>/gim, 84 | replace: "$4", 85 | }, 86 | }; 87 | var links = msgRegExpReplace.links; 88 | var userLinks = msgRegExpReplace.userLinks; 89 | var userLinksAsButtons = msgRegExpReplace.userLinksAsButtons; 90 | var newPara = msgRegExpReplace.newPara; 91 | var newParaButtons = msgRegExpReplace.newParaButtons; 92 | var msgPrepare = function (text, context) { 93 | if (/UserLinkAsButton/gim.test(context === null || context === void 0 ? void 0 : context.wcmd_show_mode)) { 94 | if (/\(NEW_PARA\)/gim.test(context === null || context === void 0 ? void 0 : context.wcmd_show_mode)) { 95 | return text 96 | .replace(links === null || links === void 0 ? void 0 : links.regexp, links === null || links === void 0 ? void 0 : links.replace) 97 | .replace(newParaButtons === null || newParaButtons === void 0 ? void 0 : newParaButtons.regexp, newParaButtons === null || newParaButtons === void 0 ? void 0 : newParaButtons.replace) 98 | .replace(userLinks === null || userLinks === void 0 ? void 0 : userLinks.regexp, userLinks === null || userLinks === void 0 ? void 0 : userLinks.replace); 99 | } 100 | else { 101 | return text 102 | .replace(links === null || links === void 0 ? void 0 : links.regexp, links === null || links === void 0 ? void 0 : links.replace) 103 | .replace(newPara === null || newPara === void 0 ? void 0 : newPara.regexp, newPara === null || newPara === void 0 ? void 0 : newPara.replace) 104 | .replace(userLinksAsButtons === null || userLinksAsButtons === void 0 ? void 0 : userLinksAsButtons.regexp, userLinksAsButtons === null || userLinksAsButtons === void 0 ? void 0 : userLinksAsButtons.replace); 105 | } 106 | } 107 | return text 108 | .replace(links === null || links === void 0 ? void 0 : links.regexp, links === null || links === void 0 ? void 0 : links.replace) 109 | .replace(newPara === null || newPara === void 0 ? void 0 : newPara.regexp, newPara === null || newPara === void 0 ? void 0 : newPara.replace) 110 | .replace(userLinks === null || userLinks === void 0 ? void 0 : userLinks.regexp, userLinks === null || userLinks === void 0 ? void 0 : userLinks.replace); 111 | }; 112 | 113 | var resultControl = function (module, result) { return __awaiter(void 0, void 0, void 0, function () { 114 | var queryResult, text, data, _a, data; 115 | var _b, _c; 116 | return __generator(this, function (_d) { 117 | switch (_d.label) { 118 | case 0: 119 | queryResult = result[0].queryResult; 120 | if (!(queryResult === null || queryResult === void 0 ? void 0 : queryResult.fulfillmentText)) return [3 /*break*/, 3]; 121 | text = msgPrepare(queryResult === null || queryResult === void 0 ? void 0 : queryResult.fulfillmentText); 122 | data = { 123 | text: text ? text : 'что-то не так', 124 | sender: 'request', 125 | showRate: (_b = result === null || result === void 0 ? void 0 : result.text) === null || _b === void 0 ? void 0 : _b.showRate, 126 | type: 'text', 127 | module: module.name 128 | }; 129 | _a = text; 130 | if (!_a) return [3 /*break*/, 2]; 131 | return [4 /*yield*/, module.uiDispatcher('sendMessage', data)]; 132 | case 1: 133 | _a = (_d.sent()); 134 | _d.label = 2; 135 | case 2: 136 | _d.label = 3; 137 | case 3: 138 | if (!((_c = result === null || result === void 0 ? void 0 : result.text) === null || _c === void 0 ? void 0 : _c.showRate)) return [3 /*break*/, 5]; 139 | data = { 140 | uiManagmentEvent: 'showRate', 141 | data: true, 142 | }; 143 | return [4 /*yield*/, module.uiDispatcher('uiManagment', data)]; 144 | case 4: 145 | _d.sent(); 146 | _d.label = 5; 147 | case 5: return [2 /*return*/]; 148 | } 149 | }); 150 | }); }; 151 | 152 | var postFetch = function (data, url) { return __awaiter(void 0, void 0, void 0, function () { 153 | var fetchResponse, fetchResult, error_1; 154 | return __generator(this, function (_a) { 155 | switch (_a.label) { 156 | case 0: 157 | _a.trys.push([0, 3, , 4]); 158 | return [4 /*yield*/, fetch(url, { 159 | headers: { 160 | 'Content-Type': 'application/json', 161 | Accept: 'application/json', 162 | }, 163 | method: 'POST', 164 | body: JSON.stringify({ data: data }), 165 | })]; 166 | case 1: 167 | fetchResponse = _a.sent(); 168 | return [4 /*yield*/, fetchResponse.json()]; 169 | case 2: 170 | fetchResult = _a.sent(); 171 | return [2 /*return*/, fetchResult.result]; 172 | case 3: 173 | error_1 = _a.sent(); 174 | console.log(error_1); 175 | return [3 /*break*/, 4]; 176 | case 4: return [2 /*return*/]; 177 | } 178 | }); 179 | }); }; 180 | 181 | var setInfo = function (module, data) { 182 | var sessionPath = data.sessionPath, sessionId = data.sessionId, projectId = data.projectId; 183 | if (sessionPath) 184 | module.info.sessionPath = sessionPath; 185 | if (sessionId) 186 | module.info.sessionId = sessionId; 187 | if (projectId) 188 | module.info.projectId = projectId; 189 | }; 190 | var reset = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 191 | return __generator(this, function (_a) { 192 | module.moduleDispatcher('chatInit', data); 193 | return [2 /*return*/]; 194 | }); 195 | }); }; 196 | var chatInit = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 197 | var _a, sessionId, projectId, eventName, infApiUrl, initData, url, result, eventData; 198 | return __generator(this, function (_b) { 199 | switch (_b.label) { 200 | case 0: 201 | _a = module.info, sessionId = _a.sessionId, projectId = _a.projectId; 202 | eventName = module.events.ready; 203 | infApiUrl = module.api.infApiUrl; 204 | initData = { 205 | sessionId: sessionId, 206 | projectId: projectId, 207 | }; 208 | url = infApiUrl + "/ckWebhook/dialogFLow/chatInit"; 209 | return [4 /*yield*/, postFetch(initData, url)]; 210 | case 1: 211 | result = _b.sent(); 212 | module.moduleDispatcher('setInfo', result); 213 | eventData = { 214 | eventName: eventName, 215 | context: data.clientConfig, 216 | }; 217 | module.moduleDispatcher('chatEvent', eventData); 218 | return [2 /*return*/]; 219 | } 220 | }); 221 | }); }; 222 | var chatRequest = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 223 | var sessionPath, infApiUrl, text, context, languageCode, requestData, url, result; 224 | return __generator(this, function (_a) { 225 | switch (_a.label) { 226 | case 0: 227 | sessionPath = module.info.sessionPath; 228 | infApiUrl = module.api.infApiUrl; 229 | text = data.text, context = data.context; 230 | languageCode = (context === null || context === void 0 ? void 0 : context.env_sitelang) ? context === null || context === void 0 ? void 0 : context.env_sitelang : 'ru'; 231 | requestData = { 232 | sessionPath: sessionPath, 233 | text: text, 234 | languageCode: languageCode, 235 | }; 236 | url = infApiUrl + "/ckWebhook/dialogFLow/chatRequest"; 237 | return [4 /*yield*/, postFetch(requestData, url)]; 238 | case 1: 239 | result = _a.sent(); 240 | resultControl(module, result); 241 | return [2 /*return*/]; 242 | } 243 | }); 244 | }); }; 245 | var chatEvent = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 246 | var sessionPath, infApiUrl, eventName, context, languageCode, requestData, url, result; 247 | return __generator(this, function (_a) { 248 | switch (_a.label) { 249 | case 0: 250 | sessionPath = module.info.sessionPath; 251 | infApiUrl = module.api.infApiUrl; 252 | eventName = data.eventName, context = data.context; 253 | languageCode = (context === null || context === void 0 ? void 0 : context.env_sitelang) ? context === null || context === void 0 ? void 0 : context.env_sitelang : 'ru'; 254 | requestData = { 255 | sessionPath: sessionPath, 256 | eventName: eventName, 257 | languageCode: languageCode, 258 | }; 259 | url = infApiUrl + "/ckWebhook/dialogFLow/chatEvent"; 260 | return [4 /*yield*/, postFetch(requestData, url)]; 261 | case 1: 262 | result = _a.sent(); 263 | resultControl(module, result); 264 | return [2 /*return*/]; 265 | } 266 | }); 267 | }); }; 268 | 269 | var INF_API_URL = { "env": { "INF_API_URL": "http://localhost:5000" } }.env.INF_API_URL; 270 | var DialogflowModule = /** @class */ (function () { 271 | function DialogflowModule(config) { 272 | var _this = this; 273 | this.moduleDispatcher = function (event, data) { return __awaiter(_this, void 0, void 0, function () { 274 | var _a, _b, _c, _d, _e; 275 | return __generator(this, function (_f) { 276 | switch (_f.label) { 277 | case 0: 278 | _a = event === 'chatInit' && data; 279 | if (!_a) return [3 /*break*/, 2]; 280 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 281 | case 1: 282 | _a = (_f.sent()); 283 | _f.label = 2; 284 | case 2: 285 | _b = event === 'chatEvent' && data; 286 | if (!_b) return [3 /*break*/, 4]; 287 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 288 | case 3: 289 | _b = (_f.sent()); 290 | _f.label = 4; 291 | case 4: 292 | _c = event === 'chatRequest' && data; 293 | if (!_c) return [3 /*break*/, 6]; 294 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 295 | case 5: 296 | _c = (_f.sent()); 297 | _f.label = 6; 298 | case 6: 299 | _d = event === 'setInfo' && data; 300 | if (!_d) return [3 /*break*/, 8]; 301 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 302 | case 7: 303 | _d = (_f.sent()); 304 | _f.label = 8; 305 | case 8: 306 | _e = event === 'reset' && data; 307 | if (!_e) return [3 /*break*/, 10]; 308 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 309 | case 9: 310 | _e = (_f.sent()); 311 | _f.label = 10; 312 | case 10: 313 | return [2 /*return*/]; 314 | } 315 | }); 316 | }); }; 317 | this.uiDispatcher = function (event, data) { 318 | event === 'sendMessage' && _this.uiEvents[event](data); 319 | event === 'uiManagment' && 320 | _this.uiEvents[event](data.uiManagmentEvent, data.data); 321 | event === 'notifications' && 322 | _this.uiEvents[event](data.notificationEvent, data.data); 323 | event === 'modules' && _this.uiEvents[event](data.modulesEvent, data.data); 324 | }; 325 | var info = config.info, moduleEvents = config.moduleEvents, uiEvents = config.uiEvents, api = config.api, events = config.events; 326 | this.name = 'dialogflow'; 327 | this.info = { 328 | sessionId: info.sessionId, 329 | projectId: info.projectId, 330 | sessionPath: '', 331 | }; 332 | this.events = { 333 | ready: (events === null || events === void 0 ? void 0 : events.ready) ? events.ready : 'ready', 334 | }; 335 | this.api = { 336 | infApiUrl: (api === null || api === void 0 ? void 0 : api.infApiUrl) || INF_API_URL || '', 337 | }; 338 | this.uiEvents = { 339 | sendMessage: (uiEvents === null || uiEvents === void 0 ? void 0 : uiEvents.sendMessage) || defaultSendMessage, 340 | uiManagment: (uiEvents === null || uiEvents === void 0 ? void 0 : uiEvents.uiManagment) || defaultUIManagment, 341 | notifications: (uiEvents === null || uiEvents === void 0 ? void 0 : uiEvents.notifications) || defaultNotifications, 342 | modules: (uiEvents === null || uiEvents === void 0 ? void 0 : uiEvents.modules) || defaultModules, 343 | }; 344 | this.moduleEvents = { 345 | setInfo: (moduleEvents === null || moduleEvents === void 0 ? void 0 : moduleEvents.setInfo) || setInfo, 346 | chatInit: (moduleEvents === null || moduleEvents === void 0 ? void 0 : moduleEvents.chatInit) || chatInit, 347 | chatEvent: (moduleEvents === null || moduleEvents === void 0 ? void 0 : moduleEvents.chatEvent) || chatEvent, 348 | chatRequest: (moduleEvents === null || moduleEvents === void 0 ? void 0 : moduleEvents.chatRequest) || chatRequest, 349 | reset: (moduleEvents === null || moduleEvents === void 0 ? void 0 : moduleEvents.reset) || reset, 350 | }; 351 | } 352 | return DialogflowModule; 353 | }()); 354 | 355 | var ckModuleInit = function (config) { return new DialogflowModule(config); }; 356 | 357 | exports.default = ckModuleInit; 358 | //# sourceMappingURL=index.js.map 359 | -------------------------------------------------------------------------------- /dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sources":["../node_modules/tslib/tslib.es6.js","../src/events/defaultUiEvents.ts","../src/utils/regExp.ts","../src/utils/resultControl.ts","../src/utils/fetch.ts","../src/events/moduleEvents.ts","../src/module/dialogflow.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 { SendMessageData, UIManagmentEvents, NotificationsEvents, ModulesEvents, ModulesData } from '../@types/uiEvents'\n\nexport const defaultSendMessage = (data: SendMessageData) => console.log('no SendMessage')\nexport const defaultUIManagment = (uiManagmentEvent: UIManagmentEvents, data: any) => console.log('no UIManagment')\nexport const defaultNotifications = (notificationsEvent: NotificationsEvents, data: any) =>\n console.log('no Notifications')\nexport const defaultModules = (notificationsEvent: ModulesEvents, data: any) => console.log('no modules')\n","const msgRegExpReplace = {\n links: {\n regexp: /href=\"event:/gim,\n replace: 'data-type=\"outbound\" rel=\"noopener noreferrer\" href=\"',\n },\n userLinks: {\n regexp: /]*(?!data-request))?(data-request=\"([^\"]+)?\")?>(.*?)<\\/userlink>/gim,\n replace: \"$4\",\n },\n newPara: {\n regexp: / \\(NEW_PARA\\)|\\(NEW_PARA\\)/gim,\n replace: '',\n },\n newParaButtons: {\n regexp: / \\(NEW_PARA\\)(.*)|\\(NEW_PARA\\)(.*)/gim,\n replace: \"$1$2\",\n },\n userLinksAsButtons: {\n regexp: /]*(?!data-request))?(data-request=\"([^\"]+)?\")?>(.*?)<\\/userlink>/gim,\n replace: \"$4\",\n },\n}\n\nconst links = msgRegExpReplace.links\nconst userLinks = msgRegExpReplace.userLinks\nconst userLinksAsButtons = msgRegExpReplace.userLinksAsButtons\nconst newPara = msgRegExpReplace.newPara\nconst newParaButtons = msgRegExpReplace.newParaButtons\n\nconst msgPrepare = (text: string, context?: any) => {\n if (/UserLinkAsButton/gim.test(context?.wcmd_show_mode)) {\n if (/\\(NEW_PARA\\)/gim.test(context?.wcmd_show_mode)) {\n return text\n .replace(links?.regexp, links?.replace)\n .replace(newParaButtons?.regexp, newParaButtons?.replace)\n .replace(userLinks?.regexp, userLinks?.replace)\n } else {\n return text\n .replace(links?.regexp, links?.replace)\n .replace(newPara?.regexp, newPara?.replace)\n .replace(userLinksAsButtons?.regexp, userLinksAsButtons?.replace)\n }\n }\n return text\n .replace(links?.regexp, links?.replace)\n .replace(newPara?.regexp, newPara?.replace)\n .replace(userLinks?.regexp, userLinks?.replace)\n}\n\nexport { msgPrepare }\n","import { DialogflowModule } from '../@types/dialogflow'\nimport { SendMessageData, UIManagmentData } from '../@types/uiEvents'\nimport { msgPrepare } from './regExp'\n\nexport const resultControl = async (module: DialogflowModule, result: any) => {\n const {queryResult} = result[0]\n if (queryResult?.fulfillmentText) {\n const text = msgPrepare(queryResult?.fulfillmentText)\n const data: SendMessageData = {\n text: text? text: 'что-то не так',\n sender: 'request',\n showRate: result?.text?.showRate,\n type: 'text',\n module: module.name\n }\n text && (await module.uiDispatcher('sendMessage', data))\n }\n if (result?.text?.showRate) {\n const data: UIManagmentData = {\n uiManagmentEvent: 'showRate',\n data: true,\n }\n await module.uiDispatcher('uiManagment', data)\n }\n}\n","import { ChatInitFetch, ChatRequestFetch, ChatEventFetch } from '../@types/common'\n\nexport const postFetch = async (data: ChatInitFetch | ChatRequestFetch | ChatEventFetch, url: string) => {\n try {\n const fetchResponse = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n },\n method: 'POST',\n body: JSON.stringify({ data }),\n })\n const fetchResult = await fetchResponse.json()\n return fetchResult.result\n } catch (error) {\n console.log(error)\n }\n}\n","import { SetInfoData, ChatInitData, ChatRequestData, ChatEventData, ResetData } from '../@types/moduleEvents'\nimport { DialogflowModule } from '../@types/dialogflow'\nimport { resultControl } from '../utils/resultControl'\nimport { postFetch } from '../utils/fetch'\nimport { ChatInitFetch, ChatRequestFetch, ChatEventFetch } from '../@types/common'\n\nexport const setInfo = (module: DialogflowModule, data: SetInfoData) => {\n const { sessionPath, sessionId, projectId } = data\n if (sessionPath) module.info.sessionPath = sessionPath\n if (sessionId) module.info.sessionId = sessionId\n if (projectId) module.info.projectId = projectId\n}\nexport const reset = async (module: DialogflowModule, data: ResetData) => {\n module.moduleDispatcher('chatInit', data)\n}\nexport const chatInit = async (module: DialogflowModule, data: ChatInitData) => {\n const { sessionId, projectId } = module.info\n const eventName = module.events.ready\n const { infApiUrl } = module.api\n const initData: ChatInitFetch = {\n sessionId,\n projectId,\n }\n const url = `${infApiUrl}/ckWebhook/dialogFLow/chatInit`\n const result = await postFetch(initData, url)\n module.moduleDispatcher('setInfo', result)\n const eventData = {\n eventName,\n context: data.clientConfig,\n }\n module.moduleDispatcher('chatEvent', eventData)\n}\n\nexport const chatRequest = async (module: DialogflowModule, data: ChatRequestData) => {\n const { sessionPath } = module.info\n const { infApiUrl } = module.api\n const { text, context } = data\n const languageCode = context?.env_sitelang ? context?.env_sitelang : 'ru'\n const requestData: ChatRequestFetch = {\n sessionPath,\n text,\n languageCode,\n }\n const url = `${infApiUrl}/ckWebhook/dialogFLow/chatRequest`\n const result = await postFetch(requestData, url)\n resultControl(module, result)\n}\nexport const chatEvent = async (module: DialogflowModule, data: ChatEventData) => {\n const { sessionPath } = module.info\n const { infApiUrl } = module.api\n const { eventName, context } = data\n const languageCode = context?.env_sitelang ? context?.env_sitelang : 'ru'\n const requestData: ChatEventFetch = {\n sessionPath,\n eventName,\n languageCode,\n }\n const url = `${infApiUrl}/ckWebhook/dialogFLow/chatEvent`\n const result = await postFetch(requestData, url)\n resultControl(module, result)\n}\n","import {\n DialogflowInfo,\n ModuleEvents,\n UiEvents,\n DialogflowConfig,\n DialogflowApi,\n DialogFlowEvents,\n} from '../@types/dialogflow'\n\nimport {\n ModuleEventsData,\n ChatInitData,\n ChatEventData,\n ChatRequestData,\n SetInfoData,\n ModuleEventsNames,\n} from '../@types/moduleEvents'\nimport {\n UiEventsNames,\n UiEventsData,\n SendMessageData,\n UIManagmentData,\n NotificationsData,\n ModulesData,\n} from '../@types/uiEvents'\nimport { defaultSendMessage, defaultUIManagment, defaultNotifications, defaultModules } from '../events/defaultUiEvents'\nimport { setInfo, chatInit, chatEvent, chatRequest, reset } from '../events/moduleEvents'\nconst { INF_API_URL } = process.env\nclass DialogflowModule {\n name: string\n info: DialogflowInfo\n moduleEvents: ModuleEvents\n uiEvents: UiEvents\n api: DialogflowApi\n events: DialogFlowEvents\n constructor(config: DialogflowConfig) {\n const { info, moduleEvents, uiEvents, api, events } = config\n this.name = 'dialogflow'\n this.info = {\n sessionId: info.sessionId,\n projectId: info.projectId,\n sessionPath: '',\n }\n this.events = {\n ready: events?.ready ? events.ready : 'ready',\n }\n this.api = {\n infApiUrl: api?.infApiUrl || INF_API_URL || '',\n }\n this.uiEvents = {\n sendMessage: uiEvents?.sendMessage || defaultSendMessage,\n uiManagment: uiEvents?.uiManagment || defaultUIManagment,\n notifications: uiEvents?.notifications || defaultNotifications,\n modules: uiEvents?.modules || defaultModules,\n }\n this.moduleEvents = {\n setInfo: moduleEvents?.setInfo || setInfo,\n chatInit: moduleEvents?.chatInit || chatInit,\n chatEvent: moduleEvents?.chatEvent || chatEvent,\n chatRequest: moduleEvents?.chatRequest || chatRequest,\n reset: moduleEvents?.reset || reset,\n }\n }\n moduleDispatcher = async (event: ModuleEventsNames, data?: ModuleEventsData) => {\n event === 'chatInit' && data && (await this.moduleEvents[event](this, data as ChatInitData))\n event === 'chatEvent' && data && (await this.moduleEvents[event](this, data as ChatEventData))\n event === 'chatRequest' && data && (await this.moduleEvents[event](this, data as ChatRequestData))\n event === 'setInfo' && data && (await this.moduleEvents[event](this, data as SetInfoData))\n event === 'reset' && data && (await this.moduleEvents[event](this, data as ChatInitData))\n }\n uiDispatcher = (event: UiEventsNames, data: UiEventsData) => {\n event === 'sendMessage' && this.uiEvents[event](data as SendMessageData)\n event === 'uiManagment' &&\n this.uiEvents[event]((data as UIManagmentData).uiManagmentEvent, (data as UIManagmentData).data)\n event === 'notifications' &&\n this.uiEvents[event]((data as NotificationsData).notificationEvent, (data as NotificationsData).data)\n event === 'modules' && this.uiEvents[event]((data as ModulesData).modulesEvent, (data as ModulesData).data)\n }\n}\nexport { DialogflowModule }\n","import { DialogflowModule } from './module/dialogflow'\nimport { DialogflowConfig } from './@types/dialogflow'\nconst ckModuleInit = (config: DialogflowConfig) => new DialogflowModule(config)\nexport default ckModuleInit\n"],"names":[],"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,EA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AAa,EAAE,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,aAAa,KAAI,oBAAoB;YAC9D,OAAO,EAAE,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,KAAI,cAAc;SAC7C,CAAA;QACD,IAAI,CAAC,YAAY,GAAG;YAClB,OAAO,EAAE,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,OAAO,KAAI,OAAO;YACzC,QAAQ,EAAE,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,QAAQ,KAAI,QAAQ;YAC5C,SAAS,EAAE,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,SAAS,KAAI,SAAS;YAC/C,WAAW,EAAE,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,WAAW,KAAI,WAAW;YACrD,KAAK,EAAE,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,KAAK,KAAI,KAAK;SACpC,CAAA;KACF;IAgBH,uBAAC;AAAD,CAAC;;IC5EK,YAAY,GAAG,UAAC,MAAwB,IAAK,OAAA,IAAI,gBAAgB,CAAC,MAAM,CAAC;;;;"} -------------------------------------------------------------------------------- /docs/apimethods/chatEvent.md: -------------------------------------------------------------------------------- 1 | # chatEvent 2 | Chat events 3 | 4 | ## Call of method 5 | `moduleDispatcher` - method of event management. 6 | `moduleDispatcher` switches to the selected method `chatEvent` and transmits necessary data to that. 7 | 8 | For example: 9 | ```javascript 10 | moduleDispatcher('chatEvent',{eventName: 'ready'}) 11 | ``` 12 | 13 | ## Typical data 14 | ```javascript 15 | ChatEventData { 16 | eventName: 17 | DialogLanguageEventsNames 18 | context?: RandomContext 19 | } 20 | ``` 21 | 22 | ## Example of data 23 | ```javascript 24 | data = { 25 | eventName: 'ready', 26 | } 27 | ``` 28 | 29 | ### options of events 30 | | event | | 31 | |--------------------------|----------------------| 32 | | 'ready' | chat is ready | 33 | | 'inactive' | user is active | 34 | | 'rate' | rate message | 35 | | 'notification' | send notification | 36 | | 'context' | change chat context | 37 | | 'click' | mouse click | 38 | | 'mouse' | move mouse | 39 | | 'operatorStatus' | operator status | 40 | | 'chatState' | chat state | 41 | | 'geolocationTimeout' | geolocation time out | 42 | | 'geolocationDenied' | geolocation denied | 43 | -------------------------------------------------------------------------------- /docs/apimethods/chatInit.md: -------------------------------------------------------------------------------- 1 | # chatInit 2 | Dialog Initialization 3 | 4 | ## Call of method 5 | `moduleDispatcher` - method of event management. 6 | `moduleDispatcher` switches to the selected method `chatInit` and transmits necessary data to that. 7 | 8 | For example: 9 | ```javascript 10 | moduleDispatcher('chatInit',{clientConfig:{env_site_lang: 'ru'}}) 11 | ``` 12 | 13 | ## Typical data 14 | ```javascript 15 | ChatInitData { 16 | clientConfig: RandomContext 17 | } 18 | ``` 19 | 20 | ## Example of data 21 | ```javascript 22 | data = { 23 | clientConfig: { 24 | env_site_lang: 'ru' 25 | } 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /docs/apimethods/chatRequest.md: -------------------------------------------------------------------------------- 1 | # chatRequest 2 | Sending user messages 3 | 4 | ## Call of method 5 | `moduleDispatcher` - method of event management. 6 | `moduleDispatcher` switches to the selected method `chatRequest` and transmits necessary data to that. 7 | 8 | For example: 9 | ```javascript 10 | moduleDispatcher('chatRequest',{text:'Hello World!!'}) 11 | ``` 12 | 13 | ## Typical data 14 | ```javascript 15 | ChatRequestData { 16 | text: string 17 | context?: RandomContext 18 | } 19 | ``` 20 | 21 | ## Example of data 22 | ```javascript 23 | data = { 24 | text: 'Hello World!!' 25 | } 26 | ``` 27 | -------------------------------------------------------------------------------- /docs/apimethods/reset.md: -------------------------------------------------------------------------------- 1 | # reset 2 | Reset dialogue 3 | 4 | ## Call of method 5 | `moduleDispatcher` - method of event management. 6 | `moduleDispatcher` switches to the selected method `reset` and transmits necessary next to that: 7 | 8 | ```javascript 9 | moduleDispatcher('reset') 10 | -------------------------------------------------------------------------------- /docs/apimethods/setInfo.md: -------------------------------------------------------------------------------- 1 | # setInfo 2 | Get information about events 3 | 4 | ## Call of method 5 | `moduleDispatcher` - method of event management. 6 | `moduleDispatcher` switches to the selected method `setInfo` and transmits necessary data to that. 7 | 8 | For example: 9 | 10 | ```javascript 11 | moduleDispatcher('setInfo',{cuid: '123446', events: ['1234', '1323']}) 12 | ``` 13 | 14 | ## Typical data 15 | ```javascript 16 | SetInfoData { 17 | cuid: string 18 | events: string[] 19 | } 20 | ``` 21 | 22 | ## Example of data 23 | ```javascript 24 | data = { 25 | cuid: '123446', 26 | events: ['1234', '1323'] 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /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", 3 | "version": "0.1.0", 4 | "description": "SOVA dialog module", 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 | "devDependencies": { 34 | "@rollup/plugin-commonjs": "^11.0.2", 35 | "@rollup/plugin-json": "^4.1.0", 36 | "@rollup/plugin-node-resolve": "^7.1.1", 37 | "@rollup/plugin-replace": "^2.3.3", 38 | "@types/dialogflow": "^4.0.4", 39 | "@types/node": "^13.13.15", 40 | "@typescript-eslint/eslint-plugin": "^2.24.0", 41 | "@typescript-eslint/parser": "^2.24.0", 42 | "@wessberg/rollup-plugin-ts": "^1.2.23", 43 | "commitizen": "^4.0.3", 44 | "conventional-changelog-cli": "^2.0.31", 45 | "cz-conventional-changelog": "^3.1.0", 46 | "dotenv": "^8.2.0", 47 | "eslint": "^6.8.0", 48 | "eslint-config-prettier": "^6.10.1", 49 | "eslint-config-react": "^1.1.7", 50 | "eslint-plugin-prettier": "^3.1.2", 51 | "immutable": "^4.0.0-rc.12", 52 | "jest": "^25.1.0", 53 | "prettier": "^1.19.1", 54 | "rollup": "^2.1.0", 55 | "rollup-plugin-peer-deps-external": "^2.2.2", 56 | "ts-jest": "^25.2.1", 57 | "ts-loader": "^6.2.2", 58 | "typescript": "^3.8.3" 59 | }, 60 | "repository": { 61 | "type": "git", 62 | "url": "git@github.com:sovaai/chatKit-dialogflow-module.git" 63 | }, 64 | "config": { 65 | "commitizen": { 66 | "path": "./node_modules/cz-conventional-changelog" 67 | } 68 | }, 69 | "dependencies": {} 70 | } 71 | -------------------------------------------------------------------------------- /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 replace from '@rollup/plugin-replace' 6 | import dotenv from 'dotenv' 7 | dotenv.config() 8 | import pkg from './package.json' 9 | const { INF_API_URL } = process.env 10 | export default { 11 | input: 'src/index.ts', 12 | output: [ 13 | { 14 | file: pkg.main, 15 | format: 'cjs', 16 | exports: 'named', 17 | sourcemap: true, 18 | }, 19 | { 20 | file: pkg.module, 21 | format: 'es', 22 | exports: 'named', 23 | sourcemap: true, 24 | }, 25 | ], 26 | plugins: [ 27 | replace({ 28 | process: JSON.stringify({ 29 | env: { 30 | INF_API_URL, 31 | }, 32 | }), 33 | }), 34 | peerDepsExternal(), 35 | resolve(), 36 | typescript(), 37 | commonjs(), 38 | ], 39 | } 40 | -------------------------------------------------------------------------------- /src/@types/common.d.ts: -------------------------------------------------------------------------------- 1 | export interface ChatInitFetch { 2 | sessionId: string 3 | projectId: string 4 | } 5 | export interface ChatRequestFetch { 6 | text: string 7 | languageCode: string 8 | sessionPath: string 9 | } 10 | export interface ChatEventFetch { 11 | eventName: string 12 | languageCode: string 13 | sessionPath: string 14 | } 15 | -------------------------------------------------------------------------------- /src/@types/dialogflow.d.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ModuleEventsData, 3 | ChatInitData, 4 | ChatRequestData, 5 | ChatEventData, 6 | SetInfoData, 7 | ChatRateData, 8 | ChatTrackData, 9 | NotificationDisplayData, 10 | ChatTimerAnnouncementsRequestData, 11 | ModuleEventsNames, 12 | ResetData, 13 | } from './moduleEvents' 14 | import { 15 | SendMessageData, 16 | UiData, 17 | NotificationsEvents, 18 | NotificationsData, 19 | UIManagmentData, 20 | ModulesEvents, 21 | ModulesData, 22 | } from './uiEvents' 23 | import { CKModule, InitConfig, UiEventsList } from './module' 24 | export interface DialogflowInfo { 25 | sessionId: string 26 | projectId: string 27 | sessionPath: string 28 | } 29 | export interface DialogflowApi { 30 | infApiUrl: string 31 | } 32 | export interface DialogFlowEvents { 33 | ready: string 34 | } 35 | 36 | export interface ModuleEvents { 37 | chatInit: (module: DialogflowModule, data: ChatInitData) => void 38 | chatRequest: (module: DialogflowModule, data: ChatRequestData) => void 39 | chatEvent: (module: DialogflowModule, data: ChatEventData) => void 40 | setInfo: (module: DialogflowModule, data: SetInfoData) => void 41 | reset: (module: DialogflowModule, data: ResetData) => void 42 | } 43 | export interface UiEvents { 44 | sendMessage: (data: SendMessageData) => void 45 | uiManagment: (uiManagmentEvent: uiManagmentEvents, data: UIManagmentData) => void 46 | notifications: (notificationsEvent: NotificationsEvents, data: NotificationsData) => void 47 | modules: (modulesEvent: ModulesEvents, data: ModulesData) => void 48 | } 49 | export interface DialogflowModule extends CKModule { 50 | info: DialogflowInfo 51 | api: DialogflowApi 52 | events: DialogFlowEvents 53 | moduleEvents: ModuleEvents 54 | uiEvents: UiEvents 55 | moduleDispatcher: (event: ModuleEventsNames, data?: ModuleEventsData) => void 56 | } 57 | export interface DialogflowConfig { 58 | info: { 59 | projectId: string 60 | sessionId: string 61 | } 62 | api?: { 63 | infApiUrl: string 64 | } 65 | events?: { 66 | ready?: string 67 | } 68 | moduleEvents?: ModuleEvents 69 | uiEvents?: UiEventsList 70 | } 71 | -------------------------------------------------------------------------------- /src/@types/module.d.ts: -------------------------------------------------------------------------------- 1 | import { SendMessageData, UiEventsData, UiEventsNames, UIManagmentEvents, UIManagmentData, ModulesEvents, ModulesData, NotificationsData } from './uiEvents' 2 | import { ModuleEventData, SetInfoData, ChatInitData, ChatEventData, ChatRequestData } from './moduleEvents' 3 | 4 | export interface ModuleEvents { 5 | chatRequest: (module: CKModule, data: RandomData) => void 6 | } 7 | export interface UiEventsList { 8 | sendMessage?: (data: SendMessageData) => void 9 | uiManagment?: (uiManagmentEvent: UIManagmentEvents, data: UIManagmentData) => void 10 | notifications?: (notificationsEvent: NotificationsEvents, data: NotificationsData) => void 11 | modules?: (modulesEvent: ModulesEvents , data: ModulesData)=> void 12 | 13 | } 14 | export interface CKModule { 15 | name: string 16 | info: RandomInfo 17 | uiEvents: UiEvents 18 | moduleEvents: ModuleEvents 19 | moduleDispatcher: (event: 'chatRequest', data?: ModuleEventData) => void 20 | uiDispatcher: (event: UiEventsNames, data: UiEventsData) => void 21 | } 22 | export interface InitConfig { 23 | info: RandomInfo 24 | customization: RandomInfo 25 | connectToStore: { 26 | getConfig: (moduleName: string) => RandomInfo 27 | } 28 | uiEvents: UiEventsList 29 | } 30 | export interface RandomData { 31 | [key: string]: any 32 | } 33 | export interface RandomInfo { 34 | [key: string]: any 35 | } 36 | export interface RandomApi { 37 | [key: string]: any 38 | } 39 | -------------------------------------------------------------------------------- /src/@types/moduleEvents.d.ts: -------------------------------------------------------------------------------- 1 | import { DialogflowEventsNames, DialogflowInfo } from './Dialogflow' 2 | 3 | export interface RandomContext { 4 | [key: string]: any 5 | } 6 | export interface ChatRequestData { 7 | text: string 8 | context?: RandomContext 9 | } 10 | export interface ChatInitData { 11 | moduleInfo?: DialogflowInfo 12 | clientConfig: RandomContext 13 | } 14 | export interface SetInfoData { 15 | sessionId?: string 16 | sessionPath?: string 17 | projectId?: string 18 | } 19 | export interface ChatEventData { 20 | eventName: string 21 | context?: RandomContext 22 | } 23 | export interface ResetData { 24 | moduleInfo?: DialogflowInfo 25 | clientConfig: RandomContext 26 | } 27 | 28 | export type ModuleEventsNames = 'chatInit' | 'chatRequest' | 'setInfo' | 'chatEvent' | 'reset' 29 | 30 | export type ModuleEventsData = ChatRequestData | ChatEventData | ChatInitData | SetInfoData | ResetData 31 | -------------------------------------------------------------------------------- /src/@types/uiEvents.d.ts: -------------------------------------------------------------------------------- 1 | export interface SendMessageData { 2 | text: string 3 | sender: 'user' | 'request' 4 | showRate: boolean 5 | type: string 6 | module: string 7 | } 8 | export type UIManagmentEvents = 9 | | 'setUpSender' 10 | | 'setUpHeader' 11 | | 'setUpBadge' 12 | | 'setUpMessage' 13 | | 'setUpDialog' 14 | | 'blockSender' 15 | | 'dialogLoading' 16 | | 'showRate' 17 | | 'showNotification' 18 | export type NotificationsEvents = 'addMessages' | 'addSettings' | 'shown' | 'clicked' | 'enabled' 19 | export interface UIManagmentData { 20 | uiManagmentEvent: UIManagmentEvents 21 | data: any 22 | } 23 | export interface NotificationsData { 24 | notificationEvent: NotificationsEvents 25 | data: any 26 | } 27 | export type ModulesEvents = 'initModule' | 'switchModule' | 'updateModule' | 'getModuleConfig' 28 | export interface ModulesData { 29 | modulesEvent: ModulesEvents 30 | data: any 31 | } 32 | export type UiEventsNames = 'sendMessage' | 'uiManagment' | 'notifications' | 'modules' 33 | export type UiEventsData = SendMessageData | UIManagmentData | NotificationsData | ModulesData 34 | -------------------------------------------------------------------------------- /src/events/defaultUiEvents.ts: -------------------------------------------------------------------------------- 1 | import { SendMessageData, UIManagmentEvents, NotificationsEvents, ModulesEvents, ModulesData } from '../@types/uiEvents' 2 | 3 | export const defaultSendMessage = (data: SendMessageData) => console.log('no SendMessage') 4 | export const defaultUIManagment = (uiManagmentEvent: UIManagmentEvents, data: any) => console.log('no UIManagment') 5 | export const defaultNotifications = (notificationsEvent: NotificationsEvents, data: any) => 6 | console.log('no Notifications') 7 | export const defaultModules = (notificationsEvent: ModulesEvents, data: any) => console.log('no modules') 8 | -------------------------------------------------------------------------------- /src/events/moduleEvents.ts: -------------------------------------------------------------------------------- 1 | import { SetInfoData, ChatInitData, ChatRequestData, ChatEventData, ResetData } from '../@types/moduleEvents' 2 | import { DialogflowModule } from '../@types/dialogflow' 3 | import { resultControl } from '../utils/resultControl' 4 | import { postFetch } from '../utils/fetch' 5 | import { ChatInitFetch, ChatRequestFetch, ChatEventFetch } from '../@types/common' 6 | 7 | export const setInfo = (module: DialogflowModule, data: SetInfoData) => { 8 | const { sessionPath, sessionId, projectId } = data 9 | if (sessionPath) module.info.sessionPath = sessionPath 10 | if (sessionId) module.info.sessionId = sessionId 11 | if (projectId) module.info.projectId = projectId 12 | } 13 | export const reset = async (module: DialogflowModule, data: ResetData) => { 14 | module.moduleDispatcher('chatInit', data) 15 | } 16 | export const chatInit = async (module: DialogflowModule, data: ChatInitData) => { 17 | const { sessionId, projectId } = module.info 18 | const eventName = module.events.ready 19 | const { infApiUrl } = module.api 20 | const initData: ChatInitFetch = { 21 | sessionId, 22 | projectId, 23 | } 24 | const url = `${infApiUrl}/ckWebhook/dialogFLow/chatInit` 25 | const result = await postFetch(initData, url) 26 | module.moduleDispatcher('setInfo', result) 27 | const eventData = { 28 | eventName, 29 | context: data.clientConfig, 30 | } 31 | module.moduleDispatcher('chatEvent', eventData) 32 | } 33 | 34 | export const chatRequest = async (module: DialogflowModule, data: ChatRequestData) => { 35 | const { sessionPath } = module.info 36 | const { infApiUrl } = module.api 37 | const { text, context } = data 38 | const languageCode = context?.env_sitelang ? context?.env_sitelang : 'ru' 39 | const requestData: ChatRequestFetch = { 40 | sessionPath, 41 | text, 42 | languageCode, 43 | } 44 | const url = `${infApiUrl}/ckWebhook/dialogFLow/chatRequest` 45 | const result = await postFetch(requestData, url) 46 | resultControl(module, result) 47 | } 48 | export const chatEvent = async (module: DialogflowModule, data: ChatEventData) => { 49 | const { sessionPath } = module.info 50 | const { infApiUrl } = module.api 51 | const { eventName, context } = data 52 | const languageCode = context?.env_sitelang ? context?.env_sitelang : 'ru' 53 | const requestData: ChatEventFetch = { 54 | sessionPath, 55 | eventName, 56 | languageCode, 57 | } 58 | const url = `${infApiUrl}/ckWebhook/dialogFLow/chatEvent` 59 | const result = await postFetch(requestData, url) 60 | resultControl(module, result) 61 | } 62 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { DialogflowModule } from './module/dialogflow' 2 | import { DialogflowConfig } from './@types/dialogflow' 3 | const ckModuleInit = (config: DialogflowConfig) => new DialogflowModule(config) 4 | export default ckModuleInit 5 | -------------------------------------------------------------------------------- /src/module/dialogflow.ts: -------------------------------------------------------------------------------- 1 | import { 2 | DialogflowInfo, 3 | ModuleEvents, 4 | UiEvents, 5 | DialogflowConfig, 6 | DialogflowApi, 7 | DialogFlowEvents, 8 | } from '../@types/dialogflow' 9 | 10 | import { 11 | ModuleEventsData, 12 | ChatInitData, 13 | ChatEventData, 14 | ChatRequestData, 15 | SetInfoData, 16 | ModuleEventsNames, 17 | } from '../@types/moduleEvents' 18 | import { 19 | UiEventsNames, 20 | UiEventsData, 21 | SendMessageData, 22 | UIManagmentData, 23 | NotificationsData, 24 | ModulesData, 25 | } from '../@types/uiEvents' 26 | import { defaultSendMessage, defaultUIManagment, defaultNotifications, defaultModules } from '../events/defaultUiEvents' 27 | import { setInfo, chatInit, chatEvent, chatRequest, reset } from '../events/moduleEvents' 28 | const { INF_API_URL } = process.env 29 | class DialogflowModule { 30 | name: string 31 | info: DialogflowInfo 32 | moduleEvents: ModuleEvents 33 | uiEvents: UiEvents 34 | api: DialogflowApi 35 | events: DialogFlowEvents 36 | constructor(config: DialogflowConfig) { 37 | const { info, moduleEvents, uiEvents, api, events } = config 38 | this.name = 'dialogflow' 39 | this.info = { 40 | sessionId: info.sessionId, 41 | projectId: info.projectId, 42 | sessionPath: '', 43 | } 44 | this.events = { 45 | ready: events?.ready ? events.ready : 'ready', 46 | } 47 | this.api = { 48 | infApiUrl: api?.infApiUrl || INF_API_URL || '', 49 | } 50 | this.uiEvents = { 51 | sendMessage: uiEvents?.sendMessage || defaultSendMessage, 52 | uiManagment: uiEvents?.uiManagment || defaultUIManagment, 53 | notifications: uiEvents?.notifications || defaultNotifications, 54 | modules: uiEvents?.modules || defaultModules, 55 | } 56 | this.moduleEvents = { 57 | setInfo: moduleEvents?.setInfo || setInfo, 58 | chatInit: moduleEvents?.chatInit || chatInit, 59 | chatEvent: moduleEvents?.chatEvent || chatEvent, 60 | chatRequest: moduleEvents?.chatRequest || chatRequest, 61 | reset: moduleEvents?.reset || reset, 62 | } 63 | } 64 | moduleDispatcher = async (event: ModuleEventsNames, data?: ModuleEventsData) => { 65 | event === 'chatInit' && data && (await this.moduleEvents[event](this, data as ChatInitData)) 66 | event === 'chatEvent' && data && (await this.moduleEvents[event](this, data as ChatEventData)) 67 | event === 'chatRequest' && data && (await this.moduleEvents[event](this, data as ChatRequestData)) 68 | event === 'setInfo' && data && (await this.moduleEvents[event](this, data as SetInfoData)) 69 | event === 'reset' && data && (await this.moduleEvents[event](this, data as ChatInitData)) 70 | } 71 | uiDispatcher = (event: UiEventsNames, data: UiEventsData) => { 72 | event === 'sendMessage' && this.uiEvents[event](data as SendMessageData) 73 | event === 'uiManagment' && 74 | this.uiEvents[event]((data as UIManagmentData).uiManagmentEvent, (data as UIManagmentData).data) 75 | event === 'notifications' && 76 | this.uiEvents[event]((data as NotificationsData).notificationEvent, (data as NotificationsData).data) 77 | event === 'modules' && this.uiEvents[event]((data as ModulesData).modulesEvent, (data as ModulesData).data) 78 | } 79 | } 80 | export { DialogflowModule } 81 | -------------------------------------------------------------------------------- /src/utils/fetch.ts: -------------------------------------------------------------------------------- 1 | import { ChatInitFetch, ChatRequestFetch, ChatEventFetch } from '../@types/common' 2 | 3 | export const postFetch = async (data: ChatInitFetch | ChatRequestFetch | ChatEventFetch, url: string) => { 4 | try { 5 | const fetchResponse = await fetch(url, { 6 | headers: { 7 | 'Content-Type': 'application/json', 8 | Accept: 'application/json', 9 | }, 10 | method: 'POST', 11 | body: JSON.stringify({ data }), 12 | }) 13 | const fetchResult = await fetchResponse.json() 14 | return fetchResult.result 15 | } catch (error) { 16 | console.log(error) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/utils/regExp.ts: -------------------------------------------------------------------------------- 1 | const msgRegExpReplace = { 2 | links: { 3 | regexp: /href="event:/gim, 4 | replace: 'data-type="outbound" rel="noopener noreferrer" href="', 5 | }, 6 | userLinks: { 7 | regexp: /]*(?!data-request))?(data-request="([^"]+)?")?>(.*?)<\/userlink>/gim, 8 | replace: "$4", 9 | }, 10 | newPara: { 11 | regexp: / \(NEW_PARA\)|\(NEW_PARA\)/gim, 12 | replace: '', 13 | }, 14 | newParaButtons: { 15 | regexp: / \(NEW_PARA\)(.*)|\(NEW_PARA\)(.*)/gim, 16 | replace: "$1$2", 17 | }, 18 | userLinksAsButtons: { 19 | regexp: /]*(?!data-request))?(data-request="([^"]+)?")?>(.*?)<\/userlink>/gim, 20 | replace: "$4", 21 | }, 22 | } 23 | 24 | const links = msgRegExpReplace.links 25 | const userLinks = msgRegExpReplace.userLinks 26 | const userLinksAsButtons = msgRegExpReplace.userLinksAsButtons 27 | const newPara = msgRegExpReplace.newPara 28 | const newParaButtons = msgRegExpReplace.newParaButtons 29 | 30 | const msgPrepare = (text: string, context?: any) => { 31 | if (/UserLinkAsButton/gim.test(context?.wcmd_show_mode)) { 32 | if (/\(NEW_PARA\)/gim.test(context?.wcmd_show_mode)) { 33 | return text 34 | .replace(links?.regexp, links?.replace) 35 | .replace(newParaButtons?.regexp, newParaButtons?.replace) 36 | .replace(userLinks?.regexp, userLinks?.replace) 37 | } else { 38 | return text 39 | .replace(links?.regexp, links?.replace) 40 | .replace(newPara?.regexp, newPara?.replace) 41 | .replace(userLinksAsButtons?.regexp, userLinksAsButtons?.replace) 42 | } 43 | } 44 | return text 45 | .replace(links?.regexp, links?.replace) 46 | .replace(newPara?.regexp, newPara?.replace) 47 | .replace(userLinks?.regexp, userLinks?.replace) 48 | } 49 | 50 | export { msgPrepare } 51 | -------------------------------------------------------------------------------- /src/utils/resultControl.ts: -------------------------------------------------------------------------------- 1 | import { DialogflowModule } from '../@types/dialogflow' 2 | import { SendMessageData, UIManagmentData } from '../@types/uiEvents' 3 | import { msgPrepare } from './regExp' 4 | 5 | export const resultControl = async (module: DialogflowModule, result: any) => { 6 | const {queryResult} = result[0] 7 | if (queryResult?.fulfillmentText) { 8 | const text = msgPrepare(queryResult?.fulfillmentText) 9 | const data: SendMessageData = { 10 | text: text? text: 'что-то не так', 11 | sender: 'request', 12 | showRate: result?.text?.showRate, 13 | type: 'text', 14 | module: module.name 15 | } 16 | text && (await module.uiDispatcher('sendMessage', data)) 17 | } 18 | if (result?.text?.showRate) { 19 | const data: UIManagmentData = { 20 | uiManagmentEvent: 'showRate', 21 | data: true, 22 | } 23 | await module.uiDispatcher('uiManagment', data) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /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 | "include": ["src", "src/store/@types/modules.d.ts"], 22 | "exclude": ["node_modules"] 23 | } 24 | --------------------------------------------------------------------------------