├── .editorconfig ├── .env-template ├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ └── npm-publish.yml ├── .gitignore ├── .prettierignore ├── .prettierrc ├── .vscode └── settings.json ├── 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 │ ├── chatInit.md │ ├── chatRequest.md │ └── reset.md ├── jest.config.js ├── package-lock.json ├── package.json ├── rollup.config.js ├── src ├── @types │ ├── module.d.ts │ ├── moduleEvents.d.ts │ ├── rasa.d.ts │ └── uiEvents.d.ts ├── events │ ├── defaultUIEvents.ts │ └── moduleEvents.ts ├── index.ts ├── module │ └── rasaModule.ts └── utils │ ├── helpers.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 | RASA_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': ['error', { trailingComma: 'es5', semi: false, singleQuote: true, printWidth: 120 }], 18 | '@typescript-eslint/explicit-function-return-type': 'off', 19 | }, 20 | settings: { 21 | react: { 22 | pragma: 'React', 23 | version: 'detect', 24 | }, 25 | }, 26 | parser: '@typescript-eslint/parser', 27 | parserOptions: { 28 | ecmaFeatures: { 29 | jsx: false, 30 | }, 31 | }, 32 | } 33 | -------------------------------------------------------------------------------- /.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 | /node_modules 2 | 3 | /storybook-static 4 | 5 | 6 | rasa 7 | .env -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | rasa/**/*.md 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "semi": false, 4 | "singleQuote": true, 5 | "printWidth": 120 6 | } 7 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "**/.git": false 4 | }, 5 | "editor.formatOnSave": true, 6 | "cSpell.words": [ 7 | "Crosstab", 8 | "coverage", 9 | "crosstabs", 10 | "js", 11 | "lcov", 12 | "persistor", 13 | "remotedev", 14 | "report", 15 | "svgr", 16 | "wessberg" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /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 [2020] [Virtual Assistant, LLC] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **ck-rasa** is separate module that connects to the widget. It is used to describe scripts and dialog rules. 2 | 3 | ## Install 4 | For install `ck-rasa` enter next command: 5 | ```javascript 6 | npm i ck-rasa 7 | ``` 8 | 9 | ## Quick start 10 | For quick start `ck-rasa` enter next command: 11 | ``` 12 | import ckModuleInit from 'ck-rasa' 13 | const rasaModule = ckRasaInit(rasaConfig) 14 | ``` 15 | 16 | # Description 17 | ## Rasa config 18 | Configuration file includes: 19 | ```javascript 20 | const rasaConfig = { 21 | info: { 22 | greetingPhrase: string, 23 | }, 24 | api?: { 25 | rasaURL?: string, 26 | }, 27 | moduleEvents?: { 28 | chatInit: (module: RasaModule, data: ChatInitData) => void, 29 | chatRequest: (module: RasaModule, data: ChatRequestData) => void, 30 | reset: (module: RasaModule, data: ChatInitData) => void, 31 | }, 32 | uiEvents?: { 33 | sendMessage?: (data: SendMessageData) => void, 34 | uiManagment?: (uiManagmentEvent: UIManagmentEvents, data: UIManagmentData) => void, 35 | notifications?: (notificationsEvent: NotificationsEvents, data: NotificationsData) => void, 36 | modules?: (modulesEvent: ModulesEvents , data: ModulesData)=> void, 37 | } 38 | } 39 | ``` 40 | 41 | ## API methods 42 | `ck-rasa` has next API methods: 43 | 44 | | API method | | 45 | |-----------------------------------------------------------------------------------------------------------------------------------|----------------------------------| 46 | | [chatInit](https://github.com/sovaai/chatKit-rasa-module/blob/master/docs/apimethods/chatInit.md "Read about this method") | Dialog Initialization | 47 | | [chatRequest](https://github.com/sovaai/chatKit-rasa-module/blob/master/docs/apimethods/chatRequest.md "Read about this method") | Sending user messages | 48 | | [reset](https://github.com/sovaai/chatKit-rasa-module/blob/master/docs/apimethods/reset.md "Read about this method") | Reset dialogue | 49 | 50 | 51 | ## Rasa.ModuleDispatcher 52 | `moduleDispatcher` - method of event management. 53 | `moduleDispatcher` select method and transmits necessary data to it. 54 | 55 | For example: 56 | ```javascript 57 | import moduleInit from 'ck-rasa' 58 | const ckRasa = moduleInit(dlConfig) 59 | ckRasa.moduleDispatcher('chatInit', { clientConfig: { siteLang: 'ru' } }) 60 | ``` 61 | -------------------------------------------------------------------------------- /dist/index.d.ts: -------------------------------------------------------------------------------- 1 | import { RasaInfo, ModuleEvents, UIEvents, RasaConfig, RasaApi } from "../@types/rasa"; 2 | import { ModuleEventsData, ModuleEventsNames } from "../@types/moduleEvents"; 3 | import { UIEventsNames, UIEventsData } from "../@types/UIEvents"; 4 | import { RasaConfig as RasaConfig$0 } from './@types/rasa'; 5 | declare class RasaModule { 6 | name: string; 7 | api: RasaApi; 8 | info: RasaInfo; 9 | moduleEvents: ModuleEvents; 10 | UIEvents: UIEvents; 11 | constructor(config: RasaConfig); 12 | moduleDispatcher: (event: ModuleEventsNames, data?: ModuleEventsData) => Promise; 13 | uiDispatcher: (event: UIEventsNames, data: UIEventsData) => void; 14 | } 15 | declare const ckRasaInit: (config: RasaConfig$0) => RasaModule; 16 | export { ckRasaInit as default }; 17 | -------------------------------------------------------------------------------- /dist/index.es.d.ts: -------------------------------------------------------------------------------- 1 | import { RasaInfo, ModuleEvents, UIEvents, RasaConfig, RasaApi } from "../@types/rasa"; 2 | import { ModuleEventsData, ModuleEventsNames } from "../@types/moduleEvents"; 3 | import { UIEventsNames, UIEventsData } from "../@types/UIEvents"; 4 | import { RasaConfig as RasaConfig$0 } from './@types/rasa'; 5 | declare class RasaModule { 6 | name: string; 7 | api: RasaApi; 8 | info: RasaInfo; 9 | moduleEvents: ModuleEvents; 10 | UIEvents: UIEvents; 11 | constructor(config: RasaConfig); 12 | moduleDispatcher: (event: ModuleEventsNames, data?: ModuleEventsData) => Promise; 13 | uiDispatcher: (event: UIEventsNames, data: UIEventsData) => void; 14 | } 15 | declare const ckRasaInit: (config: RasaConfig$0) => RasaModule; 16 | export { ckRasaInit as default }; 17 | -------------------------------------------------------------------------------- /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 | var __assign = function() { 17 | __assign = Object.assign || function __assign(t) { 18 | for (var s, i = 1, n = arguments.length; i < n; i++) { 19 | s = arguments[i]; 20 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; 21 | } 22 | return t; 23 | }; 24 | return __assign.apply(this, arguments); 25 | }; 26 | 27 | function __awaiter(thisArg, _arguments, P, generator) { 28 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 29 | return new (P || (P = Promise))(function (resolve, reject) { 30 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 31 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 32 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 33 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 34 | }); 35 | } 36 | 37 | function __generator(thisArg, body) { 38 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 39 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 40 | function verb(n) { return function (v) { return step([n, v]); }; } 41 | function step(op) { 42 | if (f) throw new TypeError("Generator is already executing."); 43 | while (_) try { 44 | 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; 45 | if (y = 0, t) op = [op[0] & 2, t.value]; 46 | switch (op[0]) { 47 | case 0: case 1: t = op; break; 48 | case 4: _.label++; return { value: op[1], done: false }; 49 | case 5: _.label++; y = op[1]; op = [0]; continue; 50 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 51 | default: 52 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 53 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 54 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 55 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 56 | if (t[2]) _.ops.pop(); 57 | _.trys.pop(); continue; 58 | } 59 | op = body.call(thisArg, _); 60 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 61 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 62 | } 63 | } 64 | 65 | var defaultSendMessage = function (data) { return console.log('no SendMessage'); }; 66 | var defaultUIManagment = function (uiManagmentEvent, data) { return console.log('no UIManagment'); }; 67 | var defaultNotifications = function (notificationsEvent, data) { 68 | return console.log('no Notifications'); 69 | }; 70 | var defaultModules = function (notificationsEvent, data) { return console.log('no modules'); }; 71 | var defaultUIEvents = { 72 | sendMessage: defaultSendMessage, 73 | uiManagment: defaultUIManagment, 74 | notifications: defaultNotifications, 75 | modules: defaultModules, 76 | }; 77 | 78 | var postFetch = function (body, url) { return __awaiter(void 0, void 0, void 0, function () { 79 | var fetchResponse, fetchResult, error_1; 80 | return __generator(this, function (_a) { 81 | switch (_a.label) { 82 | case 0: 83 | _a.trys.push([0, 3, , 4]); 84 | return [4 /*yield*/, fetch(url, { 85 | method: 'POST', 86 | body: JSON.stringify(body), 87 | })]; 88 | case 1: 89 | fetchResponse = _a.sent(); 90 | return [4 /*yield*/, fetchResponse.json()]; 91 | case 2: 92 | fetchResult = _a.sent(); 93 | return [2 /*return*/, fetchResult]; 94 | case 3: 95 | error_1 = _a.sent(); 96 | console.log(error_1); 97 | return [3 /*break*/, 4]; 98 | case 4: return [2 /*return*/]; 99 | } 100 | }); 101 | }); }; 102 | 103 | var resultControl = function (module, result) { return __awaiter(void 0, void 0, void 0, function () { 104 | var text, data; 105 | return __generator(this, function (_a) { 106 | switch (_a.label) { 107 | case 0: 108 | text = result.reduce(function (string, _a) { 109 | var text = _a.text, image = _a.image; 110 | if (image) 111 | return string + ""; 112 | return string + "" + text + ""; 113 | }, ''); 114 | data = { 115 | text: text, 116 | sender: 'request', 117 | showRate: false, 118 | }; 119 | return [4 /*yield*/, module.uiDispatcher('sendMessage', data)]; 120 | case 1: 121 | _a.sent(); 122 | return [2 /*return*/]; 123 | } 124 | }); 125 | }); }; 126 | 127 | var reset = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 128 | return __generator(this, function (_a) { 129 | module.uiDispatcher('modules', { 130 | modulesEvent: 'updateModule', 131 | data: { moduleName: module.name, config: { info: module.info, api: module.api } }, 132 | }); 133 | return [2 /*return*/]; 134 | }); 135 | }); }; 136 | var chatRequest = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 137 | var rasaURL, text, url, body, result; 138 | return __generator(this, function (_a) { 139 | switch (_a.label) { 140 | case 0: 141 | rasaURL = module.api.rasaURL; 142 | text = data.text; 143 | url = "" + rasaURL; 144 | body = { 145 | sender: 'Rasa', 146 | message: text, 147 | }; 148 | return [4 /*yield*/, postFetch(body, url)]; 149 | case 1: 150 | result = _a.sent(); 151 | resultControl(module, result); 152 | return [2 /*return*/]; 153 | } 154 | }); 155 | }); }; 156 | var chatInit = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 157 | var message; 158 | return __generator(this, function (_a) { 159 | message = { 160 | text: 'Hi', 161 | }; 162 | chatRequest(module, message); 163 | return [2 /*return*/]; 164 | }); 165 | }); }; 166 | var defaultModuleEvents = { chatRequest: chatRequest, reset: reset, chatInit: chatInit }; 167 | 168 | var RASA_URL = { "env": { "RASA_URL": "" } }.env.RASA_URL; 169 | var RasaModule = /** @class */ (function () { 170 | function RasaModule(config) { 171 | var _this = this; 172 | this.moduleDispatcher = function (event, data) { return __awaiter(_this, void 0, void 0, function () { 173 | var _a, _b, _c; 174 | return __generator(this, function (_d) { 175 | switch (_d.label) { 176 | case 0: 177 | _a = event === 'chatRequest' && data; 178 | if (!_a) return [3 /*break*/, 2]; 179 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 180 | case 1: 181 | _a = (_d.sent()); 182 | _d.label = 2; 183 | case 2: 184 | _b = event === 'reset'; 185 | if (!_b) return [3 /*break*/, 4]; 186 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 187 | case 3: 188 | _b = (_d.sent()); 189 | _d.label = 4; 190 | case 4: 191 | _c = event === 'chatInit'; 192 | if (!_c) return [3 /*break*/, 6]; 193 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 194 | case 5: 195 | _c = (_d.sent()); 196 | _d.label = 6; 197 | case 6: 198 | return [2 /*return*/]; 199 | } 200 | }); 201 | }); }; 202 | this.uiDispatcher = function (event, data) { 203 | event === 'sendMessage' && _this.UIEvents[event](data); 204 | event === 'uiManagment' && 205 | _this.UIEvents[event](data.uiManagmentEvent, data.data); 206 | event === 'notifications' && 207 | _this.UIEvents[event](data.notificationEvent, data.data); 208 | event === 'modules' && _this.UIEvents[event](data.modulesEvent, data.data); 209 | }; 210 | var info = config.info, api = config.api, moduleEvents = config.moduleEvents, uiEvents = config.uiEvents; 211 | this.name = 'rasaModule'; 212 | this.info = __assign({}, info); 213 | this.api = __assign({ rasaURL: (api === null || api === void 0 ? void 0 : api.rasaURL) || RASA_URL || '' }, api); 214 | this.UIEvents = __assign(__assign({}, defaultUIEvents), uiEvents); 215 | this.moduleEvents = __assign(__assign({}, defaultModuleEvents), moduleEvents); 216 | } 217 | return RasaModule; 218 | }()); 219 | 220 | var ckRasaInit = function (config) { return new RasaModule(config); }; 221 | 222 | export default ckRasaInit; 223 | //# sourceMappingURL=index.es.js.map 224 | -------------------------------------------------------------------------------- /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/helpers.ts","../src/utils/resultControl.ts","../src/events/moduleEvents.ts","../src/module/rasaModule.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\nconst defaultUIEvents = {\n sendMessage: defaultSendMessage,\n uiManagment: defaultUIManagment,\n notifications: defaultNotifications,\n modules: defaultModules,\n}\n\nexport default defaultUIEvents\n","import { RasaEvents } from '../@types/rasa'\nexport interface EventList {\n [key: string]: string\n}\nexport const eventList: EventList = {\n '00b2fcbe-f27f-437b-a0d5-91072d840ed3': 'ready',\n '29e75851-6cae-44f4-8a9c-f6489c4dca88': 'inactive',\n '11d10788-4789-11e3-9b0b-080027ab4d7b': 'rate',\n 'bffaa961-9ad3-4ecd-9254-f9e2fc06f28c': 'notification',\n '7330d8fc-4c64-11e3-af49-080027ab4d7b': 'context',\n 'd825476d-bc08-4038-9ecf-e6b2b267c7b8': 'click',\n '6819087d-a7d0-4c67-acd4-47d40b233cc9': 'mouse',\n '2bbff8e2-3c75-4f4b-bd61-c29017257c00': 'cardReady',\n '4e729f9a-0aa2-4d37-87d2-bed2b2b39c00': 'operatorStatus',\n 'c189c2f1-43b6-424b-866b-03e562ba9d33': 'chatState',\n '409b58e1-595b-4c02-81be-3f31dfe4639d': 'geolocationTimeout',\n 'b92e3bcc-44b5-4019-9594-54b69afdaf77': 'geolocationDenied',\n}\nexport const postFetch = async (body: any, url: string) => {\n try {\n const fetchResponse = await fetch(url, {\n method: 'POST',\n body: JSON.stringify(body),\n })\n const fetchResult = await fetchResponse.json()\n return fetchResult\n } catch (error) {\n console.log(error)\n }\n}\nexport const postFetchWithHeaders = async (body: any, url: string) => {\n try {\n const fetchResponse = await fetch(url, {\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n body: JSON.stringify(body),\n })\n const fetchResult = await fetchResponse.json()\n return fetchResult\n } catch (error) {\n console.log(error)\n }\n}\n\n// export const eventsParser = (activeEvents: string[]) => {\n// const events: RasaEvents = {}\n// activeEvents.forEach(activeEvent => {\n// const eventName = eventList[activeEvent]\n// events[eventName] = activeEvent\n// })\n\n// return events\n// }\nexport const isDevice = () => window && window.innerWidth && window.innerWidth < 1025\n","import { RasaModule } from '../@types/rasa'\nimport { SendMessageData, UIManagmentData } from '../@types/UIEvents'\nimport { msgPrepare } from './regExp'\n\nexport const resultControl = async (module: RasaModule, result: any) => {\n const text = result.reduce((string: string, { text, image }: { text: string; image: string }) => {\n if (image)\n return `${string}`\n\n return `${string}${text}`\n }, '')\n const data: SendMessageData = {\n text: text,\n sender: 'request',\n showRate: false,\n }\n await module.uiDispatcher('sendMessage', data)\n}\n","import { postFetch, } from '../utils/helpers'\n\nimport { ChatInitData, ChatRequestData } from '../@types/moduleEvents'\nimport { RasaModule } from '../@types/rasa'\nimport { resultControl } from '../utils/resultControl'\n\nexport const reset = async (module: RasaModule, data: ChatInitData) => {\n module.uiDispatcher('modules', {\n modulesEvent: 'updateModule',\n data: { moduleName: module.name, config: { info: module.info, api: module.api } },\n })\n}\n\nexport const chatRequest = async (module: RasaModule, data: ChatRequestData) => {\n const { rasaURL } = module.api\n const { text } = data\n const url = `${rasaURL}`\n const body = {\n sender: 'Rasa',\n message: text,\n }\n const result = await postFetch(body, url)\n resultControl(module, result)\n}\nexport const chatInit = async (module: RasaModule, data: any) => {\n const message = {\n text: 'Hi',\n }\n chatRequest(module, message)\n}\nconst defaultModuleEvents = { chatRequest, reset, chatInit }\n\nexport default defaultModuleEvents\n","import { RasaInfo, ModuleEvents, UIEvents, RasaConfig, RasaApi } from '../@types/rasa'\n\nimport { ModuleEventsData, ChatInitData, ChatRequestData, SetInfoData, ModuleEventsNames } from '../@types/moduleEvents'\n\nimport {\n UIEventsNames,\n UIEventsData,\n SendMessageData,\n UIManagmentData,\n NotificationsData,\n ModulesData,\n} from '../@types/UIEvents'\nimport defaultUIEvents from '../events/defaultUIEvents'\nimport defaultModuleEvents from '../events/moduleEvents'\nconst { RASA_URL } = process.env\nclass RasaModule {\n name: string\n api: RasaApi\n info: RasaInfo\n moduleEvents: ModuleEvents\n UIEvents: UIEvents\n\n constructor(config: RasaConfig) {\n const { info, api, moduleEvents, uiEvents } = config\n this.name = 'rasaModule'\n this.info = {\n ...info,\n }\n this.api = {\n rasaURL: api?.rasaURL || RASA_URL || '',\n ...api,\n }\n this.UIEvents = {\n ...defaultUIEvents,\n ...uiEvents,\n }\n this.moduleEvents = {\n ...defaultModuleEvents,\n ...moduleEvents,\n }\n }\n\n moduleDispatcher = async (event: ModuleEventsNames, data?: ModuleEventsData) => {\n event === 'chatRequest' && data && (await this.moduleEvents[event](this, data as ChatRequestData))\n event === 'reset' && (await this.moduleEvents[event](this, data as ChatInitData))\n event === 'chatInit' && (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 default RasaModule\n","import RasaModule from './module/rasaModule'\nimport { RasaConfig } from './@types/rasa'\nconst ckRasaInit = (config: RasaConfig) => new RasaModule(config)\nexport default ckRasaInit\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAeA;AACO,IAAI,QAAQ,GAAG,WAAW;AACjC,IAAI,QAAQ,GAAG,MAAM,CAAC,MAAM,IAAI,SAAS,QAAQ,CAAC,CAAC,EAAE;AACrD,QAAQ,KAAK,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;AAC7D,YAAY,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAC7B,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACzF,SAAS;AACT,QAAQ,OAAO,CAAC,CAAC;AACjB,MAAK;AACL,IAAI,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AAC3C,EAAC;AA4BD;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,CA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,IAAI,CAAC,CAAA;SAC5G,CAAA;QA/BS,IAAA,IAAI,GAAkC,MAAM,KAAxC,EAAE,GAAG,GAA6B,MAAM,IAAnC,EAAE,YAAY,GAAe,MAAM,aAArB,EAAE,QAAQ,GAAK,MAAM,SAAX,CAAW;QACpD,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;QACxB,IAAI,CAAC,IAAI,gBACJ,IAAI,CACR,CAAA;QACD,IAAI,CAAC,GAAG,cACN,OAAO,EAAE,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,KAAI,QAAQ,IAAI,EAAE,IACpC,GAAG,CACP,CAAA;QACD,IAAI,CAAC,QAAQ,yBACR,eAAe,GACf,QAAQ,CACZ,CAAA;QACD,IAAI,CAAC,YAAY,yBACZ,mBAAmB,GACnB,YAAY,CAChB,CAAA;KACF;IAeH,iBAAC;AAAD,CAAC;;ICrDK,UAAU,GAAG,UAAC,MAAkB,IAAK,OAAA,IAAI,UAAU,CAAC,MAAM,CAAC;;;;"} -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 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 | var __assign = function() { 21 | __assign = Object.assign || function __assign(t) { 22 | for (var s, i = 1, n = arguments.length; i < n; i++) { 23 | s = arguments[i]; 24 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; 25 | } 26 | return t; 27 | }; 28 | return __assign.apply(this, arguments); 29 | }; 30 | 31 | function __awaiter(thisArg, _arguments, P, generator) { 32 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 33 | return new (P || (P = Promise))(function (resolve, reject) { 34 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 35 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 36 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 37 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 38 | }); 39 | } 40 | 41 | function __generator(thisArg, body) { 42 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 43 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 44 | function verb(n) { return function (v) { return step([n, v]); }; } 45 | function step(op) { 46 | if (f) throw new TypeError("Generator is already executing."); 47 | while (_) try { 48 | 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; 49 | if (y = 0, t) op = [op[0] & 2, t.value]; 50 | switch (op[0]) { 51 | case 0: case 1: t = op; break; 52 | case 4: _.label++; return { value: op[1], done: false }; 53 | case 5: _.label++; y = op[1]; op = [0]; continue; 54 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 55 | default: 56 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 57 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 58 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 59 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 60 | if (t[2]) _.ops.pop(); 61 | _.trys.pop(); continue; 62 | } 63 | op = body.call(thisArg, _); 64 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 65 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 66 | } 67 | } 68 | 69 | var defaultSendMessage = function (data) { return console.log('no SendMessage'); }; 70 | var defaultUIManagment = function (uiManagmentEvent, data) { return console.log('no UIManagment'); }; 71 | var defaultNotifications = function (notificationsEvent, data) { 72 | return console.log('no Notifications'); 73 | }; 74 | var defaultModules = function (notificationsEvent, data) { return console.log('no modules'); }; 75 | var defaultUIEvents = { 76 | sendMessage: defaultSendMessage, 77 | uiManagment: defaultUIManagment, 78 | notifications: defaultNotifications, 79 | modules: defaultModules, 80 | }; 81 | 82 | var postFetch = function (body, url) { return __awaiter(void 0, void 0, void 0, function () { 83 | var fetchResponse, fetchResult, error_1; 84 | return __generator(this, function (_a) { 85 | switch (_a.label) { 86 | case 0: 87 | _a.trys.push([0, 3, , 4]); 88 | return [4 /*yield*/, fetch(url, { 89 | method: 'POST', 90 | body: JSON.stringify(body), 91 | })]; 92 | case 1: 93 | fetchResponse = _a.sent(); 94 | return [4 /*yield*/, fetchResponse.json()]; 95 | case 2: 96 | fetchResult = _a.sent(); 97 | return [2 /*return*/, fetchResult]; 98 | case 3: 99 | error_1 = _a.sent(); 100 | console.log(error_1); 101 | return [3 /*break*/, 4]; 102 | case 4: return [2 /*return*/]; 103 | } 104 | }); 105 | }); }; 106 | 107 | var resultControl = function (module, result) { return __awaiter(void 0, void 0, void 0, function () { 108 | var text, data; 109 | return __generator(this, function (_a) { 110 | switch (_a.label) { 111 | case 0: 112 | text = result.reduce(function (string, _a) { 113 | var text = _a.text, image = _a.image; 114 | if (image) 115 | return string + ""; 116 | return string + "" + text + ""; 117 | }, ''); 118 | data = { 119 | text: text, 120 | sender: 'request', 121 | showRate: false, 122 | }; 123 | return [4 /*yield*/, module.uiDispatcher('sendMessage', data)]; 124 | case 1: 125 | _a.sent(); 126 | return [2 /*return*/]; 127 | } 128 | }); 129 | }); }; 130 | 131 | var reset = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 132 | return __generator(this, function (_a) { 133 | module.uiDispatcher('modules', { 134 | modulesEvent: 'updateModule', 135 | data: { moduleName: module.name, config: { info: module.info, api: module.api } }, 136 | }); 137 | return [2 /*return*/]; 138 | }); 139 | }); }; 140 | var chatRequest = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 141 | var rasaURL, text, url, body, result; 142 | return __generator(this, function (_a) { 143 | switch (_a.label) { 144 | case 0: 145 | rasaURL = module.api.rasaURL; 146 | text = data.text; 147 | url = "" + rasaURL; 148 | body = { 149 | sender: 'Rasa', 150 | message: text, 151 | }; 152 | return [4 /*yield*/, postFetch(body, url)]; 153 | case 1: 154 | result = _a.sent(); 155 | resultControl(module, result); 156 | return [2 /*return*/]; 157 | } 158 | }); 159 | }); }; 160 | var chatInit = function (module, data) { return __awaiter(void 0, void 0, void 0, function () { 161 | var message; 162 | return __generator(this, function (_a) { 163 | message = { 164 | text: 'Hi', 165 | }; 166 | chatRequest(module, message); 167 | return [2 /*return*/]; 168 | }); 169 | }); }; 170 | var defaultModuleEvents = { chatRequest: chatRequest, reset: reset, chatInit: chatInit }; 171 | 172 | var RASA_URL = { "env": { "RASA_URL": "" } }.env.RASA_URL; 173 | var RasaModule = /** @class */ (function () { 174 | function RasaModule(config) { 175 | var _this = this; 176 | this.moduleDispatcher = function (event, data) { return __awaiter(_this, void 0, void 0, function () { 177 | var _a, _b, _c; 178 | return __generator(this, function (_d) { 179 | switch (_d.label) { 180 | case 0: 181 | _a = event === 'chatRequest' && data; 182 | if (!_a) return [3 /*break*/, 2]; 183 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 184 | case 1: 185 | _a = (_d.sent()); 186 | _d.label = 2; 187 | case 2: 188 | _b = event === 'reset'; 189 | if (!_b) return [3 /*break*/, 4]; 190 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 191 | case 3: 192 | _b = (_d.sent()); 193 | _d.label = 4; 194 | case 4: 195 | _c = event === 'chatInit'; 196 | if (!_c) return [3 /*break*/, 6]; 197 | return [4 /*yield*/, this.moduleEvents[event](this, data)]; 198 | case 5: 199 | _c = (_d.sent()); 200 | _d.label = 6; 201 | case 6: 202 | return [2 /*return*/]; 203 | } 204 | }); 205 | }); }; 206 | this.uiDispatcher = function (event, data) { 207 | event === 'sendMessage' && _this.UIEvents[event](data); 208 | event === 'uiManagment' && 209 | _this.UIEvents[event](data.uiManagmentEvent, data.data); 210 | event === 'notifications' && 211 | _this.UIEvents[event](data.notificationEvent, data.data); 212 | event === 'modules' && _this.UIEvents[event](data.modulesEvent, data.data); 213 | }; 214 | var info = config.info, api = config.api, moduleEvents = config.moduleEvents, uiEvents = config.uiEvents; 215 | this.name = 'rasaModule'; 216 | this.info = __assign({}, info); 217 | this.api = __assign({ rasaURL: (api === null || api === void 0 ? void 0 : api.rasaURL) || RASA_URL || '' }, api); 218 | this.UIEvents = __assign(__assign({}, defaultUIEvents), uiEvents); 219 | this.moduleEvents = __assign(__assign({}, defaultModuleEvents), moduleEvents); 220 | } 221 | return RasaModule; 222 | }()); 223 | 224 | var ckRasaInit = function (config) { return new RasaModule(config); }; 225 | 226 | exports.default = ckRasaInit; 227 | //# sourceMappingURL=index.js.map 228 | -------------------------------------------------------------------------------- /dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sources":["../node_modules/tslib/tslib.es6.js","../src/events/defaultUIEvents.ts","../src/utils/helpers.ts","../src/utils/resultControl.ts","../src/events/moduleEvents.ts","../src/module/rasaModule.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\nconst defaultUIEvents = {\n sendMessage: defaultSendMessage,\n uiManagment: defaultUIManagment,\n notifications: defaultNotifications,\n modules: defaultModules,\n}\n\nexport default defaultUIEvents\n","import { RasaEvents } from '../@types/rasa'\nexport interface EventList {\n [key: string]: string\n}\nexport const eventList: EventList = {\n '00b2fcbe-f27f-437b-a0d5-91072d840ed3': 'ready',\n '29e75851-6cae-44f4-8a9c-f6489c4dca88': 'inactive',\n '11d10788-4789-11e3-9b0b-080027ab4d7b': 'rate',\n 'bffaa961-9ad3-4ecd-9254-f9e2fc06f28c': 'notification',\n '7330d8fc-4c64-11e3-af49-080027ab4d7b': 'context',\n 'd825476d-bc08-4038-9ecf-e6b2b267c7b8': 'click',\n '6819087d-a7d0-4c67-acd4-47d40b233cc9': 'mouse',\n '2bbff8e2-3c75-4f4b-bd61-c29017257c00': 'cardReady',\n '4e729f9a-0aa2-4d37-87d2-bed2b2b39c00': 'operatorStatus',\n 'c189c2f1-43b6-424b-866b-03e562ba9d33': 'chatState',\n '409b58e1-595b-4c02-81be-3f31dfe4639d': 'geolocationTimeout',\n 'b92e3bcc-44b5-4019-9594-54b69afdaf77': 'geolocationDenied',\n}\nexport const postFetch = async (body: any, url: string) => {\n try {\n const fetchResponse = await fetch(url, {\n method: 'POST',\n body: JSON.stringify(body),\n })\n const fetchResult = await fetchResponse.json()\n return fetchResult\n } catch (error) {\n console.log(error)\n }\n}\nexport const postFetchWithHeaders = async (body: any, url: string) => {\n try {\n const fetchResponse = await fetch(url, {\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n body: JSON.stringify(body),\n })\n const fetchResult = await fetchResponse.json()\n return fetchResult\n } catch (error) {\n console.log(error)\n }\n}\n\n// export const eventsParser = (activeEvents: string[]) => {\n// const events: RasaEvents = {}\n// activeEvents.forEach(activeEvent => {\n// const eventName = eventList[activeEvent]\n// events[eventName] = activeEvent\n// })\n\n// return events\n// }\nexport const isDevice = () => window && window.innerWidth && window.innerWidth < 1025\n","import { RasaModule } from '../@types/rasa'\nimport { SendMessageData, UIManagmentData } from '../@types/UIEvents'\nimport { msgPrepare } from './regExp'\n\nexport const resultControl = async (module: RasaModule, result: any) => {\n const text = result.reduce((string: string, { text, image }: { text: string; image: string }) => {\n if (image)\n return `${string}`\n\n return `${string}${text}`\n }, '')\n const data: SendMessageData = {\n text: text,\n sender: 'request',\n showRate: false,\n }\n await module.uiDispatcher('sendMessage', data)\n}\n","import { postFetch, } from '../utils/helpers'\n\nimport { ChatInitData, ChatRequestData } from '../@types/moduleEvents'\nimport { RasaModule } from '../@types/rasa'\nimport { resultControl } from '../utils/resultControl'\n\nexport const reset = async (module: RasaModule, data: ChatInitData) => {\n module.uiDispatcher('modules', {\n modulesEvent: 'updateModule',\n data: { moduleName: module.name, config: { info: module.info, api: module.api } },\n })\n}\n\nexport const chatRequest = async (module: RasaModule, data: ChatRequestData) => {\n const { rasaURL } = module.api\n const { text } = data\n const url = `${rasaURL}`\n const body = {\n sender: 'Rasa',\n message: text,\n }\n const result = await postFetch(body, url)\n resultControl(module, result)\n}\nexport const chatInit = async (module: RasaModule, data: any) => {\n const message = {\n text: 'Hi',\n }\n chatRequest(module, message)\n}\nconst defaultModuleEvents = { chatRequest, reset, chatInit }\n\nexport default defaultModuleEvents\n","import { RasaInfo, ModuleEvents, UIEvents, RasaConfig, RasaApi } from '../@types/rasa'\n\nimport { ModuleEventsData, ChatInitData, ChatRequestData, SetInfoData, ModuleEventsNames } from '../@types/moduleEvents'\n\nimport {\n UIEventsNames,\n UIEventsData,\n SendMessageData,\n UIManagmentData,\n NotificationsData,\n ModulesData,\n} from '../@types/UIEvents'\nimport defaultUIEvents from '../events/defaultUIEvents'\nimport defaultModuleEvents from '../events/moduleEvents'\nconst { RASA_URL } = process.env\nclass RasaModule {\n name: string\n api: RasaApi\n info: RasaInfo\n moduleEvents: ModuleEvents\n UIEvents: UIEvents\n\n constructor(config: RasaConfig) {\n const { info, api, moduleEvents, uiEvents } = config\n this.name = 'rasaModule'\n this.info = {\n ...info,\n }\n this.api = {\n rasaURL: api?.rasaURL || RASA_URL || '',\n ...api,\n }\n this.UIEvents = {\n ...defaultUIEvents,\n ...uiEvents,\n }\n this.moduleEvents = {\n ...defaultModuleEvents,\n ...moduleEvents,\n }\n }\n\n moduleDispatcher = async (event: ModuleEventsNames, data?: ModuleEventsData) => {\n event === 'chatRequest' && data && (await this.moduleEvents[event](this, data as ChatRequestData))\n event === 'reset' && (await this.moduleEvents[event](this, data as ChatInitData))\n event === 'chatInit' && (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 default RasaModule\n","import RasaModule from './module/rasaModule'\nimport { RasaConfig } from './@types/rasa'\nconst ckRasaInit = (config: RasaConfig) => new RasaModule(config)\nexport default ckRasaInit\n"],"names":[],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAeA;AACO,IAAI,QAAQ,GAAG,WAAW;AACjC,IAAI,QAAQ,GAAG,MAAM,CAAC,MAAM,IAAI,SAAS,QAAQ,CAAC,CAAC,EAAE;AACrD,QAAQ,KAAK,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;AAC7D,YAAY,CA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AA0D,CAAC,CAAA;;;;;;aACrF,CAAA;QACD,iBAAY,GAAG,UAAC,KAAoB,EAAE,IAAkB;YACtD,KAAK,KAAK,aAAa,IAAI,KAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAuB,CAAC,CAAA;YACxE,KAAK,KAAK,aAAa;gBACrB,KAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAE,IAAwB,CAAC,gBAAgB,EAAG,IAAwB,CAAC,IAAI,CAAC,CAAA;YAClG,KAAK,KAAK,eAAe;gBACvB,KAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAE,IAA0B,CAAC,iBAAiB,EAAG,IAA0B,CAAC,IAAI,CAAC,CAAA;YACvG,KAAK,KAAK,SAAS,IAAI,KAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAE,IAAoB,CAAC,YAAY,EAAG,IAAoB,CAAC,IAAI,CAAC,CAAA;SAC5G,CAAA;QA/BS,IAAA,IAAI,GAAkC,MAAM,KAAxC,EAAE,GAAG,GAA6B,MAAM,IAAnC,EAAE,YAAY,GAAe,MAAM,aAArB,EAAE,QAAQ,GAAK,MAAM,SAAX,CAAW;QACpD,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;QACxB,IAAI,CAAC,IAAI,gBACJ,IAAI,CACR,CAAA;QACD,IAAI,CAAC,GAAG,cACN,OAAO,EAAE,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,KAAI,QAAQ,IAAI,EAAE,IACpC,GAAG,CACP,CAAA;QACD,IAAI,CAAC,QAAQ,yBACR,eAAe,GACf,QAAQ,CACZ,CAAA;QACD,IAAI,CAAC,YAAY,yBACZ,mBAAmB,GACnB,YAAY,CAChB,CAAA;KACF;IAeH,iBAAC;AAAD,CAAC;;ICrDK,UAAU,GAAG,UAAC,MAAkB,IAAK,OAAA,IAAI,UAAU,CAAC,MAAM,CAAC;;;;"} -------------------------------------------------------------------------------- /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 | 29 | -------------------------------------------------------------------------------- /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 | ``` 11 | 12 | -------------------------------------------------------------------------------- /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-rasa", 3 | "version": "0.1.0", 4 | "description": "SOVA dialog module opensoucre lib", 5 | "homepage": "https://sova.ai", 6 | "author": { 7 | "name": "sova.ai", 8 | "gitHub": "https://github.com/sovaai" 9 | }, 10 | "main": "dist/index.js", 11 | "module": "dist/index.es.js", 12 | "files": [ 13 | "dist" 14 | ], 15 | "engines": { 16 | "node": ">=10", 17 | "npm": ">=5" 18 | }, 19 | "scripts": { 20 | "build": "rollup -c", 21 | "start": "rollup -c -w", 22 | "commit-all": "git add . && git-cz", 23 | "changelog": "./node_modules/.bin/conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md" 24 | }, 25 | "keywords": [ 26 | "SOVA", 27 | "chat-kit-module" 28 | ], 29 | "license": "Apache-2.0", 30 | "peerDependencies": {}, 31 | "devDependencies": { 32 | "@rollup/plugin-commonjs": "^11.0.2", 33 | "@rollup/plugin-node-resolve": "^7.1.1", 34 | "@rollup/plugin-replace": "^2.3.3", 35 | "@types/node": "^13.9.1", 36 | "@typescript-eslint/eslint-plugin": "^2.23.0", 37 | "@typescript-eslint/parser": "^2.23.0", 38 | "@wessberg/rollup-plugin-ts": "^1.2.21", 39 | "commitizen": "^4.0.3", 40 | "concurrently": "^5.1.0", 41 | "conventional-changelog-cli": "^2.0.31", 42 | "cz-conventional-changelog": "^3.1.0", 43 | "dotenv": "^8.2.0", 44 | "eslint": "^6.8.0", 45 | "eslint-config-prettier": "^6.10.0", 46 | "eslint-config-react": "^1.1.7", 47 | "eslint-plugin-prettier": "^3.1.2", 48 | "jest": "^25.1.0", 49 | "prettier": "^1.19.1", 50 | "rollup": "^2.0.6", 51 | "rollup-plugin-peer-deps-external": "^2.2.2", 52 | "ts-jest": "^25.2.1", 53 | "ts-loader": "^6.2.1", 54 | "typescript": "^3.8.3" 55 | }, 56 | "repository": { 57 | "type": "git", 58 | "url": "git@gitlab.nanosemantics.ru:sova.ai/sova-chat-kit/ck-rasa.git" 59 | }, 60 | "config": { 61 | "commitizen": { 62 | "path": "./node_modules/cz-conventional-changelog" 63 | } 64 | }, 65 | "dependencies": {} 66 | } 67 | -------------------------------------------------------------------------------- /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 | const { RASA_URL } = process.env 9 | import pkg from './package.json' 10 | 11 | export default { 12 | input: 'src/index.ts', 13 | output: [ 14 | { 15 | file: pkg.main, 16 | format: 'cjs', 17 | exports: 'named', 18 | sourcemap: true, 19 | }, 20 | { 21 | file: pkg.module, 22 | format: 'es', 23 | exports: 'named', 24 | sourcemap: true, 25 | }, 26 | ], 27 | plugins: [ 28 | replace({ 29 | process: JSON.stringify({ 30 | env: { 31 | RASA_URL 32 | }, 33 | }), 34 | }), 35 | peerDepsExternal(), 36 | resolve(), 37 | typescript(), 38 | commonjs(), 39 | ], 40 | } 41 | -------------------------------------------------------------------------------- /src/@types/module.d.ts: -------------------------------------------------------------------------------- 1 | import { 2 | SendMessageData, 3 | UIEventsData, 4 | UIEventsNames, 5 | UIManagmentEvents, 6 | UIManagmentData, 7 | ModulesEvents, 8 | ModulesData, 9 | NotificationsData, 10 | } from './UIEvents' 11 | import { ModuleEventData, SetInfoData, ChatInitData, ChatEventData, ChatRequestData } from './moduleEvents' 12 | 13 | export interface ModuleEvents { 14 | chatRequest: (module: CKModule, data: RandomData) => void 15 | } 16 | export interface UIEventsList { 17 | sendMessage?: (data: SendMessageData) => void 18 | uiManagment?: (uiManagmentEvent: UIManagmentEvents, data: UIManagmentData) => void 19 | notifications?: (notificationsEvent: NotificationsEvents, data: NotificationsData) => void 20 | modules?: (modulesEvent: ModulesEvents, data: ModulesData) => void 21 | } 22 | export interface CKModule { 23 | name: string 24 | info: RandomInfo 25 | api: RandomApi 26 | UIEvents: UIEvents 27 | moduleEvents: ModuleEvents 28 | moduleDispatcher: (event: 'chatRequest', data?: ModuleEventData) => void 29 | uiDispatcher: (event: UIEventsNames, data: UIEventsData) => void 30 | } 31 | export interface InitConfig { 32 | info: RandomInfo 33 | customization: RandomInfo 34 | connectToStore: { 35 | getConfig: (moduleName: string) => RandomInfo 36 | } 37 | UIEvents: UIEventsList 38 | } 39 | export interface RandomData { 40 | [key: string]: any 41 | } 42 | export interface RandomInfo { 43 | [key: string]: any 44 | } 45 | export interface RandomApi { 46 | [key: string]: any 47 | } 48 | -------------------------------------------------------------------------------- /src/@types/moduleEvents.d.ts: -------------------------------------------------------------------------------- 1 | import { RasaEventsNames, RasaInfo } from './rasa' 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?: RasaInfo 12 | clientConfig: RandomContext 13 | } 14 | export interface SetInfoData { 15 | cuid: string 16 | events: string[] 17 | } 18 | export interface ChatEventData { 19 | eventName: RasaEventsNames 20 | context?: RandomContext 21 | } 22 | export interface ChatRateData { 23 | rating: number 24 | } 25 | 26 | export interface ChatTrackData { 27 | action: string 28 | args: { 29 | id: string 30 | url: string 31 | text: string 32 | } 33 | } 34 | 35 | export type ModuleEventsNames = 36 | | 'chatInit' 37 | | 'chatRequest' 38 | | 'chatEvent' 39 | | 'chatRate' 40 | | 'chatTrack' 41 | | 'reset' 42 | 43 | export type ModuleEventsData = 44 | | ChatRequestData 45 | | ChatEventData 46 | | ChatInitData 47 | | SetInfoData 48 | | ChatRateData 49 | | ChatTimerAnnouncementsRequestData 50 | | NotificationDisplayData 51 | | ChatTrackData 52 | -------------------------------------------------------------------------------- /src/@types/rasa.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 | } from './moduleEvents' 13 | import { 14 | SendMessageData, 15 | UiData, 16 | NotificationsEvents, 17 | NotificationsData, 18 | UIManagmentData, 19 | ModulesEvents, 20 | ModulesData, 21 | } from './UIEvents' 22 | import { CKModule, InitConfig, UIEventsList } from './module' 23 | 24 | export interface RasaInfo { 25 | greetingPhrase: string 26 | } 27 | export interface RasaApi { 28 | rasaURL: string 29 | } 30 | 31 | 32 | export interface RasaEvents {} 33 | export interface ModuleEvents { 34 | chatRequest: (module: RasaModule, data: ChatRequestData) => void 35 | reset: (module: RasaModule, data: ChatInitData) => void 36 | chatInit: (module: RasaModule, data: any) => void 37 | } 38 | export interface UIEvents { 39 | sendMessage: (data: SendMessageData) => void 40 | uiManagment: (uiManagmentEvent: uiManagmentEvents, data: UIManagmentData) => void 41 | notifications: (notificationsEvent: NotificationsEvents, data: NotificationsData) => void 42 | modules: (modulesEvent: ModulesEvents, data: ModulesData) => void 43 | } 44 | export interface RasaModule extends CKModule { 45 | info: RasaInfo 46 | moduleEvents: ModuleEvents 47 | api: RasaApi 48 | UIEvents: UIEvents 49 | moduleDispatcher: (event: ModuleEventsNames, data?: ModuleEventsData) => void 50 | } 51 | export interface RasaConfig { 52 | info: { 53 | greetingPhrase: string 54 | } 55 | api?: { 56 | rasaURL?: string 57 | } 58 | moduleEvents?: ModuleEvents 59 | uiEvents?: UIEventsList 60 | } 61 | -------------------------------------------------------------------------------- /src/@types/uiEvents.d.ts: -------------------------------------------------------------------------------- 1 | export interface SendMessageData { 2 | text: string 3 | sender: 'user' | 'request' 4 | showRate: boolean 5 | } 6 | export type UIManagmentEvents = 7 | | 'setUpSender' 8 | | 'setUpHeader' 9 | | 'setUpBadge' 10 | | 'setUpMessage' 11 | | 'setUpDialog' 12 | | 'blockSender' 13 | | 'dialogLoading' 14 | | 'showRate' 15 | | 'showNotification' 16 | export type NotificationsEvents = 'addMessages' | 'addSettings' | 'shown' | 'clicked' | 'enabled' 17 | export interface UIManagmentData { 18 | uiManagmentEvent: UIManagmentEvents 19 | data: any 20 | } 21 | export interface NotificationsData { 22 | notificationEvent: NotificationsEvents 23 | data: any 24 | } 25 | export type ModulesEvents = 'initModule' | 'switchModule' | 'updateModule' | 'getModuleConfig' 26 | export interface ModulesData { 27 | modulesEvent: ModulesEvents 28 | data: any 29 | } 30 | export type UIEventsNames = 'sendMessage' | 'uiManagment' | 'notifications' | 'modules' 31 | export type UIEventsData = SendMessageData | UIManagmentData | NotificationsData | ModulesData 32 | -------------------------------------------------------------------------------- /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 | 9 | const defaultUIEvents = { 10 | sendMessage: defaultSendMessage, 11 | uiManagment: defaultUIManagment, 12 | notifications: defaultNotifications, 13 | modules: defaultModules, 14 | } 15 | 16 | export default defaultUIEvents 17 | -------------------------------------------------------------------------------- /src/events/moduleEvents.ts: -------------------------------------------------------------------------------- 1 | import { postFetch, } from '../utils/helpers' 2 | 3 | import { ChatInitData, ChatRequestData } from '../@types/moduleEvents' 4 | import { RasaModule } from '../@types/rasa' 5 | import { resultControl } from '../utils/resultControl' 6 | 7 | export const reset = async (module: RasaModule, data: ChatInitData) => { 8 | module.uiDispatcher('modules', { 9 | modulesEvent: 'updateModule', 10 | data: { moduleName: module.name, config: { info: module.info, api: module.api } }, 11 | }) 12 | } 13 | 14 | export const chatRequest = async (module: RasaModule, data: ChatRequestData) => { 15 | const { rasaURL } = module.api 16 | const { text } = data 17 | const url = `${rasaURL}` 18 | const body = { 19 | sender: 'Rasa', 20 | message: text, 21 | } 22 | const result = await postFetch(body, url) 23 | resultControl(module, result) 24 | } 25 | export const chatInit = async (module: RasaModule, data: any) => { 26 | const message = { 27 | text: 'Hi', 28 | } 29 | chatRequest(module, message) 30 | } 31 | const defaultModuleEvents = { chatRequest, reset, chatInit } 32 | 33 | export default defaultModuleEvents 34 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import RasaModule from './module/rasaModule' 2 | import { RasaConfig } from './@types/rasa' 3 | const ckRasaInit = (config: RasaConfig) => new RasaModule(config) 4 | export default ckRasaInit 5 | -------------------------------------------------------------------------------- /src/module/rasaModule.ts: -------------------------------------------------------------------------------- 1 | import { RasaInfo, ModuleEvents, UIEvents, RasaConfig, RasaApi } from '../@types/rasa' 2 | 3 | import { ModuleEventsData, ChatInitData, ChatRequestData, SetInfoData, ModuleEventsNames } from '../@types/moduleEvents' 4 | 5 | import { 6 | UIEventsNames, 7 | UIEventsData, 8 | SendMessageData, 9 | UIManagmentData, 10 | NotificationsData, 11 | ModulesData, 12 | } from '../@types/UIEvents' 13 | import defaultUIEvents from '../events/defaultUIEvents' 14 | import defaultModuleEvents from '../events/moduleEvents' 15 | const { RASA_URL } = process.env 16 | class RasaModule { 17 | name: string 18 | api: RasaApi 19 | info: RasaInfo 20 | moduleEvents: ModuleEvents 21 | UIEvents: UIEvents 22 | 23 | constructor(config: RasaConfig) { 24 | const { info, api, moduleEvents, uiEvents } = config 25 | this.name = 'rasaModule' 26 | this.info = { 27 | ...info, 28 | } 29 | this.api = { 30 | rasaURL: api?.rasaURL || RASA_URL || '', 31 | ...api, 32 | } 33 | this.UIEvents = { 34 | ...defaultUIEvents, 35 | ...uiEvents, 36 | } 37 | this.moduleEvents = { 38 | ...defaultModuleEvents, 39 | ...moduleEvents, 40 | } 41 | } 42 | 43 | moduleDispatcher = async (event: ModuleEventsNames, data?: ModuleEventsData) => { 44 | event === 'chatRequest' && data && (await this.moduleEvents[event](this, data as ChatRequestData)) 45 | event === 'reset' && (await this.moduleEvents[event](this, data as ChatInitData)) 46 | event === 'chatInit' && (await this.moduleEvents[event](this, data as ChatInitData)) 47 | } 48 | uiDispatcher = (event: UIEventsNames, data: UIEventsData) => { 49 | event === 'sendMessage' && this.UIEvents[event](data as SendMessageData) 50 | event === 'uiManagment' && 51 | this.UIEvents[event]((data as UIManagmentData).uiManagmentEvent, (data as UIManagmentData).data) 52 | event === 'notifications' && 53 | this.UIEvents[event]((data as NotificationsData).notificationEvent, (data as NotificationsData).data) 54 | event === 'modules' && this.UIEvents[event]((data as ModulesData).modulesEvent, (data as ModulesData).data) 55 | } 56 | } 57 | export default RasaModule 58 | -------------------------------------------------------------------------------- /src/utils/helpers.ts: -------------------------------------------------------------------------------- 1 | import { RasaEvents } from '../@types/rasa' 2 | export interface EventList { 3 | [key: string]: string 4 | } 5 | export const eventList: EventList = { 6 | '00b2fcbe-f27f-437b-a0d5-91072d840ed3': 'ready', 7 | '29e75851-6cae-44f4-8a9c-f6489c4dca88': 'inactive', 8 | '11d10788-4789-11e3-9b0b-080027ab4d7b': 'rate', 9 | 'bffaa961-9ad3-4ecd-9254-f9e2fc06f28c': 'notification', 10 | '7330d8fc-4c64-11e3-af49-080027ab4d7b': 'context', 11 | 'd825476d-bc08-4038-9ecf-e6b2b267c7b8': 'click', 12 | '6819087d-a7d0-4c67-acd4-47d40b233cc9': 'mouse', 13 | '2bbff8e2-3c75-4f4b-bd61-c29017257c00': 'cardReady', 14 | '4e729f9a-0aa2-4d37-87d2-bed2b2b39c00': 'operatorStatus', 15 | 'c189c2f1-43b6-424b-866b-03e562ba9d33': 'chatState', 16 | '409b58e1-595b-4c02-81be-3f31dfe4639d': 'geolocationTimeout', 17 | 'b92e3bcc-44b5-4019-9594-54b69afdaf77': 'geolocationDenied', 18 | } 19 | export const postFetch = async (body: any, url: string) => { 20 | try { 21 | const fetchResponse = await fetch(url, { 22 | method: 'POST', 23 | body: JSON.stringify(body), 24 | }) 25 | const fetchResult = await fetchResponse.json() 26 | return fetchResult 27 | } catch (error) { 28 | console.log(error) 29 | } 30 | } 31 | export const postFetchWithHeaders = async (body: any, url: string) => { 32 | try { 33 | const fetchResponse = await fetch(url, { 34 | headers: { 35 | Accept: 'application/json', 36 | 'Content-Type': 'application/json', 37 | }, 38 | method: 'POST', 39 | body: JSON.stringify(body), 40 | }) 41 | const fetchResult = await fetchResponse.json() 42 | return fetchResult 43 | } catch (error) { 44 | console.log(error) 45 | } 46 | } 47 | 48 | // export const eventsParser = (activeEvents: string[]) => { 49 | // const events: RasaEvents = {} 50 | // activeEvents.forEach(activeEvent => { 51 | // const eventName = eventList[activeEvent] 52 | // events[eventName] = activeEvent 53 | // }) 54 | 55 | // return events 56 | // } 57 | export const isDevice = () => window && window.innerWidth && window.innerWidth < 1025 58 | -------------------------------------------------------------------------------- /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 { RasaModule } from '../@types/rasa' 2 | import { SendMessageData, UIManagmentData } from '../@types/UIEvents' 3 | import { msgPrepare } from './regExp' 4 | 5 | export const resultControl = async (module: RasaModule, result: any) => { 6 | const text = result.reduce((string: string, { text, image }: { text: string; image: string }) => { 7 | if (image) 8 | return `${string}` 9 | 10 | return `${string}${text}` 11 | }, '') 12 | const data: SendMessageData = { 13 | text: text, 14 | sender: 'request', 15 | showRate: false, 16 | } 17 | await module.uiDispatcher('sendMessage', data) 18 | } 19 | -------------------------------------------------------------------------------- /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"], 22 | "exclude": ["node_modules"] 23 | } 24 | --------------------------------------------------------------------------------