├── .idea ├── Angular-AI-Chat-Bot.iml ├── modules.xml ├── vcs.xml └── workspace.xml └── chat-bot ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e ├── protractor.conf.js ├── src │ └── app.po.ts └── tsconfig.e2e.json ├── index.js ├── index.ts ├── package.json ├── src ├── app │ ├── chat-input │ │ ├── chat-input.component.css │ │ ├── chat-input.component.html │ │ ├── chat-input.component.js │ │ └── chat-input.component.ts │ ├── chat-msg │ │ ├── chat-msg.component.css │ │ ├── chat-msg.component.html │ │ ├── chat-msg.component.js │ │ └── chat-msg.component.ts │ ├── chat-window │ │ ├── chat-window.component.css │ │ ├── chat-window.component.html │ │ ├── chat-window.component.js │ │ └── chat-window.component.ts │ ├── client │ │ ├── ApiAiClient.js │ │ ├── ApiAiClient.ts │ │ ├── ApiAiConstants.js │ │ ├── ApiAiConstants.ts │ │ ├── Errors.js │ │ ├── Errors.ts │ │ ├── Interfaces.js │ │ ├── Interfaces.ts │ │ ├── Request.js │ │ ├── Request.ts │ │ ├── TextRequest.js │ │ ├── TextRequest.ts │ │ ├── XhrRequest.js │ │ └── XhrRequest.ts │ └── services │ │ ├── data.service.js │ │ └── data.service.ts ├── demo │ ├── app.component.css │ ├── app.component.html │ ├── app.component.ts │ ├── app.module.ts │ ├── assets │ │ ├── .gitkeep │ │ └── scss │ │ │ └── base │ │ │ └── _variables.scss │ ├── browserslist │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── karma.conf.js │ ├── main.ts │ ├── polyfills.ts │ ├── styles.scss │ └── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── tslint.json ├── tsconfig.json └── tslint.json /.idea/Angular-AI-Chat-Bot.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | sent 178 | 179 | 180 | 181 | 183 | 184 | 203 | 204 | 205 | 206 | 207 | true 208 | DEFINITION_ORDER 209 | 210 | 211 | 212 | 213 | 214 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 212 | 213 | ``` 214 | 215 | ```typescript 216 | class MyComponent { 217 | public accessToken = 'YOUR_ACCESS_TOKEN'; 218 | public message: Subject = new Subject(); 219 | public onChange(message: string) { 220 | this.message.next(message); 221 | } 222 | } 223 | ``` 224 | 225 | Or you can import `chat-input` component from `angular-ai-chat-bot` module and use it 226 | 227 | ```html 228 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | ``` 242 | 243 | ```typescript 244 | class MyComponent { 245 | public accessToken = 'YOUR_ACCESS_TOKEN'; 246 | public message: Subject = new Subject(); 247 | public onChange(message: string) { 248 | this.message.next(message); 249 | } 250 | } 251 | ``` 252 | 253 | Add the `ChatInput` to your application's module `declarations` section: 254 | 255 | ```typescript 256 | import { NgModule } from '@angular/core'; 257 | import { AppComponent } from './app.component'; 258 | import { BrowserModule } from '@angular/platform-browser'; 259 | import {ChatBot} from 'angular-ai-chat-bot'; 260 | // Add the following component 261 | import { ChatInput } from 'angular-ai-chat-bot'; 262 | 263 | 264 | @NgModule({ 265 | declarations: [MyComponent, ChatBot, ChatInput], 266 | imports: [BrowserModule], 267 | bootstrap: [MyComponent] 268 | }) 269 | export class MyModule {} 270 | ``` 271 | ## Events 272 | 273 | ### (onMsgReceive) 274 | 275 | You can subscribe to the message receive event by attaching listener to the (onMsgReceive) attribute. 276 | 277 | ```html 278 | 280 | 281 | 282 | 283 | 284 | ``` 285 | `onMsgReceive` has just one property: recived message context 286 | 287 | 288 | 289 | ## :bulb: Want to help? 290 | 291 | I am very appreciate for your ideas, proposals and found bugs which you can put in [github issues](https://github.com/PoghosyanHayk/Angular-AI-Chat-Bot/issues). Thanks in advance! 292 | 293 | **P.S.** If you find it hard going through the documentation, please, let me know which parts of it was difficult to grasp and I will improve them. 294 | 295 | 296 | 297 | 298 | 299 | -------------------------------------------------------------------------------- /chat-bot/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "ngx-ai": { 7 | "root": "", 8 | "sourceRoot": "src/demo", 9 | "projectType": "application", 10 | "architect": { 11 | "build": { 12 | "builder": "@angular-devkit/build-angular:browser", 13 | "options": { 14 | "outputPath": "dist", 15 | "index": "src/demo/index.html", 16 | "main": "src/demo/main.ts", 17 | "tsConfig": "src/tsconfig.app.json", 18 | "polyfills": "src/demo/polyfills.ts", 19 | "assets": [ 20 | "src/demo/assets", 21 | "src/demo/favicon.ico" 22 | ], 23 | "styles": [ 24 | "src/demo/styles.scss" 25 | ], 26 | "scripts": [] 27 | }, 28 | "configurations": { 29 | "production": { 30 | "optimization": true, 31 | "outputHashing": "all", 32 | "sourceMap": false, 33 | "extractCss": true, 34 | "namedChunks": false, 35 | "aot": true, 36 | "extractLicenses": true, 37 | "vendorChunk": false, 38 | "buildOptimizer": true, 39 | "fileReplacements": [ 40 | { 41 | "replace": "src/environments/environment.ts", 42 | "with": "src/environments/environment.prod.ts" 43 | } 44 | ] 45 | } 46 | } 47 | }, 48 | "serve": { 49 | "builder": "@angular-devkit/build-angular:dev-server", 50 | "options": { 51 | "browserTarget": "ngx-ai:build" 52 | }, 53 | "configurations": { 54 | "production": { 55 | "browserTarget": "ngx-ai:build:production" 56 | } 57 | } 58 | }, 59 | "extract-i18n": { 60 | "builder": "@angular-devkit/build-angular:extract-i18n", 61 | "options": { 62 | "browserTarget": "ngx-ai:build" 63 | } 64 | }, 65 | "test": { 66 | "builder": "@angular-devkit/build-angular:karma", 67 | "options": { 68 | "main": "src/demo/test.ts", 69 | "karmaConfig": "src/demo/karma.conf.js", 70 | "tsConfig": "src/tsconfig.spec.json", 71 | "polyfills": "src/demo/polyfills.ts", 72 | "scripts": [], 73 | "styles": [ 74 | "src/demo/styles.scss" 75 | ], 76 | "assets": [ 77 | "src/demo/assets", 78 | "src/demo/favicon.ico" 79 | ] 80 | } 81 | }, 82 | "lint": { 83 | "builder": "@angular-devkit/build-angular:tslint", 84 | "options": { 85 | "tsConfig": [ 86 | "src/tsconfig.app.json", 87 | "src/tsconfig.spec.json" 88 | ], 89 | "exclude": [] 90 | } 91 | } 92 | } 93 | }, 94 | "ngx-ai-e2e": { 95 | "root": "./e2e", 96 | "sourceRoot": "", 97 | "projectType": "application", 98 | "architect": { 99 | "e2e": { 100 | "builder": "@angular-devkit/build-angular:protractor", 101 | "options": { 102 | "protractorConfig": "e2e/protractor.conf.js", 103 | "devServerTarget": "ngx-ai:serve" 104 | } 105 | }, 106 | "lint": { 107 | "builder": "@angular-devkit/build-angular:tslint", 108 | "options": { 109 | "tsConfig": [ 110 | "e2e/tsconfig.json" 111 | ], 112 | "exclude": ["**/node_modules/**"] 113 | } 114 | } 115 | } 116 | } 117 | }, 118 | "defaultProject": "ngx-ai", 119 | "cli": { 120 | "warnings": { 121 | "typescriptMismatch": false 122 | } 123 | }, 124 | "schematics": { 125 | "@schematics/angular:component": { 126 | "prefix": "app", 127 | "styleext": "scss" 128 | }, 129 | "@schematics/angular:directive": { 130 | "prefix": "app" 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /chat-bot/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /chat-bot/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /chat-bot/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /chat-bot/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | var chat_window_component_1 = require("./src/app/chat-window/chat-window.component"); 4 | exports.ChatBot = chat_window_component_1.ChatWindowComponent; 5 | var data_service_1 = require("./src/app/services/data.service"); 6 | exports.ChatService = data_service_1.DataService; 7 | var chat_input_component_1 = require("./src/app/chat-input/chat-input.component"); 8 | exports.ChatInput = chat_input_component_1.ChatInputComponent; 9 | var chat_msg_component_1 = require("./src/app/chat-msg/chat-msg.component"); 10 | exports.ChatMsg = chat_msg_component_1.ChatMsgComponent; 11 | -------------------------------------------------------------------------------- /chat-bot/index.ts: -------------------------------------------------------------------------------- 1 | import {ChatWindowComponent as ChatBot} from './src/app/chat-window/chat-window.component'; 2 | import {DataService as ChatService} from "./src/app/services/data.service"; 3 | import {ChatInputComponent as ChatInput} from "./src/app/chat-input/chat-input.component"; 4 | import {ChatMsgComponent as ChatMsg} from "./src/app/chat-msg/chat-msg.component"; 5 | 6 | export {ChatService, ChatBot, ChatMsg, ChatInput }; 7 | -------------------------------------------------------------------------------- /chat-bot/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-ai-chat-bot", 3 | "version": "1.1.0", 4 | "author": { 5 | "name": "Hayk Poghosyan", 6 | "email": "poghosyanhayk1@gmail.com" 7 | }, 8 | "description": "Angular 6 AI Chat Bot module with Google Api", 9 | "keywords": [ 10 | "angular", 11 | "dialogflow", 12 | "web speech api", 13 | "nlp", 14 | "material-design", 15 | "chatbot", 16 | "bot", 17 | "ai", 18 | "ngx", 19 | "rxjs", 20 | "observables", 21 | "custom design", 22 | "google", 23 | "api" 24 | ], 25 | "repository": "https://github.com/PoghosyanHayk/Angular-AI-Chat-Bot", 26 | "license": "MIT", 27 | "angular-cli": {}, 28 | "scripts": { 29 | "ng": "ng", 30 | "start": "ng serve", 31 | "dist": "ng build", 32 | "prod": "ng build --prod", 33 | "prod:hashless": "ng build --prod --output-hashing none", 34 | "prod:src": "ng build --prod --sourcemaps" 35 | }, 36 | "dependencies": { 37 | "@angular/animations": "^6.1.2", 38 | "@angular/cdk": "^6.4.3", 39 | "@angular/common": "^6.0.2", 40 | "@angular/compiler": "^6.0.2", 41 | "@angular/core": "^6.0.2", 42 | "@angular/forms": "^6.0.2", 43 | "@angular/http": "^6.0.2", 44 | "@angular/material": "^6.4.3", 45 | "@angular/platform-browser": "^6.0.2", 46 | "@angular/platform-browser-dynamic": "^6.0.2", 47 | "@angular/platform-server": "^6.0.2", 48 | "@angular/router": "^6.0.2", 49 | "@material-ui/core": "^1.4.3", 50 | "@types/lodash": "^4.14.109", 51 | "core-js": "^2.5.6", 52 | "hammerjs": "^2.0.8", 53 | "rxjs": "^6.1.0", 54 | "rxjs-compat": "^6.1.0", 55 | "ts-helpers": "^1.1.2", 56 | "zone.js": "^0.8.26" 57 | }, 58 | "devDependencies": { 59 | "@angular-devkit/build-angular": "~0.6.3", 60 | "@angular/cli": "^6.1.3", 61 | "@angular/compiler-cli": "^6.0.2", 62 | "@angular/language-service": "^6.0.2", 63 | "@types/jasmine": "^2.8.7", 64 | "@types/node": "^10.1.2", 65 | "@types/webaudioapi": "0.0.27", 66 | "codelyzer": "^4.3.0", 67 | "jasmine-core": "^3.1.0", 68 | "jasmine-spec-reporter": "^4.2.1", 69 | "karma": "^2.0.2", 70 | "karma-chrome-launcher": "^2.2.0", 71 | "karma-cli": "^1.0.1", 72 | "karma-coverage-istanbul-reporter": "^1.3.0", 73 | "karma-jasmine": "^1.1.2", 74 | "karma-jasmine-html-reporter": "^1.1.0", 75 | "protractor": "^5.3.2", 76 | "rxjs-tslint": "^0.1.4", 77 | "ts-node": "^3.3.0", 78 | "tslint": "^5.10.0", 79 | "typescript": "2.7.2" 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-input/chat-input.component.css: -------------------------------------------------------------------------------- 1 | .full-width { 2 | width: 100%; 3 | color: #3f51c0; 4 | } 5 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-input/chat-input.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 |
6 | 7 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-input/chat-input.component.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | 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; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | exports.__esModule = true; 9 | var core_1 = require("@angular/core"); 10 | var ChatInputComponent = /** @class */ (function () { 11 | function ChatInputComponent() { 12 | } 13 | ChatInputComponent.prototype.ngOnInit = function () { 14 | }; 15 | ChatInputComponent = __decorate([ 16 | core_1.Component({ 17 | selector: 'chat-input', 18 | templateUrl: './chat-input.component.html', 19 | styleUrls: ['./chat-input.component.css'] 20 | }) 21 | ], ChatInputComponent); 22 | return ChatInputComponent; 23 | }()); 24 | exports.ChatInputComponent = ChatInputComponent; 25 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-input/chat-input.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'chat-input', 5 | templateUrl: './chat-input.component.html', 6 | styleUrls: ['./chat-input.component.css'] 7 | }) 8 | export class ChatInputComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-msg/chat-msg.component.css: -------------------------------------------------------------------------------- 1 | .msg { 2 | display: flex; 3 | position: relative; 4 | margin-right: 40px; 5 | margin-bottom: 2px; 6 | margin-bottom: 2px; 7 | margin-left: 10px; 8 | margin-top: 5px; 9 | opacity: 0; 10 | transform: scale(0.5); 11 | transition-property: transform,opacity; 12 | transition-duration: 0.5s; 13 | transition-timing-function: ease-in; 14 | } 15 | 16 | .show { 17 | transform: scale(1); 18 | opacity:1; 19 | } 20 | 21 | .card { 22 | height: fit-content; 23 | border-radius: 10px 20px 0px 20px; 24 | padding: 10px 25px; 25 | justify-content: center; 26 | text-align: center; 27 | } 28 | 29 | .icon { 30 | margin-top: 10px; 31 | color: white; 32 | background: #3f51c0; 33 | border-radius: 35px; 34 | width: 35px !important; 35 | height: 35px !important; 36 | display: flex; 37 | justify-content: center; 38 | padding: 0px; 39 | align-items: center; 40 | position: absolute; 41 | z-index: 1; 42 | margin-left: -35px; 43 | } 44 | 45 | .user { 46 | background-color: #3f51c0; 47 | color: white; 48 | } 49 | 50 | .bot { 51 | border-radius: 20px 10px 20px 0px; 52 | background-color: white; 53 | color: #3f51c0; 54 | } 55 | 56 | .user-msg { 57 | margin-left: 40px; 58 | margin-right: 10px; 59 | flex-direction: row-reverse; 60 | } 61 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-msg/chat-msg.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 5 | 6 | android 7 | 8 | 9 | 10 | {{msg.text}} 11 | 12 | 13 |
14 |
15 | 16 | 17 | {{msg.text}} 18 | 19 | 20 |
21 |
22 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-msg/chat-msg.component.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | 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; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | exports.__esModule = true; 9 | var core_1 = require("@angular/core"); 10 | var ChatMsgComponent = /** @class */ (function () { 11 | function ChatMsgComponent() { 12 | this.isVisible = false; 13 | } 14 | ChatMsgComponent.prototype.ngOnInit = function () { 15 | var _this = this; 16 | setTimeout(function () { _this.isVisible = true; }, 0); 17 | }; 18 | __decorate([ 19 | core_1.Input() 20 | ], ChatMsgComponent.prototype, "msg"); 21 | ChatMsgComponent = __decorate([ 22 | core_1.Component({ 23 | selector: 'chat-msg', 24 | templateUrl: './chat-msg.component.html', 25 | styleUrls: ['./chat-msg.component.css'] 26 | }) 27 | ], ChatMsgComponent); 28 | return ChatMsgComponent; 29 | }()); 30 | exports.ChatMsgComponent = ChatMsgComponent; 31 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-msg/chat-msg.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, Input, OnInit} from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'chat-msg', 5 | templateUrl: './chat-msg.component.html', 6 | styleUrls: ['./chat-msg.component.css'], 7 | }) 8 | export class ChatMsgComponent implements OnInit { 9 | @Input() msg: object; 10 | public isVisible = false; 11 | constructor() { } 12 | 13 | ngOnInit() { 14 | setTimeout(() => {this.isVisible = true}, 0) 15 | } 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-window/chat-window.component.css: -------------------------------------------------------------------------------- 1 | .chat-window { 2 | display: flex; 3 | flex-direction: column; 4 | justify-content: space-between; 5 | width: 100%; 6 | background-color: #d219192e; 7 | padding: 5px; 8 | } 9 | 10 | .msgArea { 11 | display: flex; 12 | flex-direction: column; 13 | overflow: auto; 14 | height: 100%; 15 | } 16 | .input-area { 17 | display: flex; 18 | width: 100%; 19 | } 20 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-window/chat-window.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 11 | 12 | 13 |
14 |
15 | 16 |
17 |
18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-window/chat-window.component.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | 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; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | exports.__esModule = true; 9 | var core_1 = require("@angular/core"); 10 | var operators_1 = require("rxjs/internal/operators"); 11 | var ChatWindowComponent = /** @class */ (function () { 12 | function ChatWindowComponent(dataService) { 13 | this.dataService = dataService; 14 | } 15 | ChatWindowComponent.prototype.ngOnInit = function () { 16 | var _this = this; 17 | this.dataService.init(this.token); 18 | this.allMessages = this.dataService.conversation.asObservable() 19 | .pipe(operators_1.scan(function (acc, val) { 20 | setTimeout(function () { 21 | _this.msgArea.nativeElement.scrollTop = _this.msgArea.nativeElement.scrollHeight; 22 | }); 23 | return acc.concat(val); 24 | })); 25 | this.msg.subscribe(function (msg) { 26 | _this.dataService.converse(msg); 27 | }); 28 | }; 29 | __decorate([ 30 | core_1.ContentChild(core_1.TemplateRef) 31 | ], ChatWindowComponent.prototype, "template"); 32 | __decorate([ 33 | core_1.Input() 34 | ], ChatWindowComponent.prototype, "msgTemplate"); 35 | __decorate([ 36 | core_1.Input() 37 | ], ChatWindowComponent.prototype, "inputTemplate"); 38 | __decorate([ 39 | core_1.Input() 40 | ], ChatWindowComponent.prototype, "msg"); 41 | __decorate([ 42 | core_1.Input() 43 | ], ChatWindowComponent.prototype, "token"); 44 | __decorate([ 45 | core_1.ViewChild('msgArea') 46 | ], ChatWindowComponent.prototype, "msgArea"); 47 | ChatWindowComponent = __decorate([ 48 | core_1.Component({ 49 | selector: 'Chat-bot', 50 | templateUrl: './chat-window.component.html', 51 | styleUrls: ['./chat-window.component.css'] 52 | }) 53 | ], ChatWindowComponent); 54 | return ChatWindowComponent; 55 | }()); 56 | exports.ChatWindowComponent = ChatWindowComponent; 57 | -------------------------------------------------------------------------------- /chat-bot/src/app/chat-window/chat-window.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Component, ContentChild, ElementRef, EventEmitter, Input, OnInit, Output, TemplateRef, 3 | ViewChild 4 | } from '@angular/core'; 5 | import { Observable, Subject } from 'rxjs'; 6 | import {DataService, ESendBy, Message} from '../services/data.service'; 7 | import {scan} from 'rxjs/internal/operators'; 8 | 9 | @Component({ 10 | selector: 'Chat-bot', 11 | templateUrl: './chat-window.component.html', 12 | styleUrls: ['./chat-window.component.css'] 13 | }) 14 | export class ChatWindowComponent implements OnInit { 15 | 16 | @ContentChild(TemplateRef) template: TemplateRef; 17 | @Input() msgTemplate: TemplateRef; 18 | @Input() inputTemplate: TemplateRef; 19 | @Input() msg: Subject; 20 | @Input() token: string; 21 | @Output() onMsgReceive = new EventEmitter(); 22 | @ViewChild('msgArea') msgArea: ElementRef; 23 | @ViewChild('defaultMsgTemplate') defaultMsgTemplate: TemplateRef; 24 | @ViewChild('defaultInputTemplate') defaultInputTemplate: TemplateRef; 25 | 26 | allMessages: Observable; 27 | 28 | 29 | constructor(public dataService: DataService) { } 30 | 31 | ngOnInit() { 32 | this.msgTemplate = this.msgTemplate ? this.msgTemplate : this.defaultMsgTemplate; 33 | this.inputTemplate = this.inputTemplate ? this.inputTemplate : this.defaultInputTemplate; 34 | this.dataService.init(this.token); 35 | this.allMessages = this.dataService.conversation.asObservable() 36 | .pipe( 37 | scan((acc, val) => { 38 | setTimeout(() => { 39 | this.msgArea.nativeElement.scrollTop = this.msgArea.nativeElement.scrollHeight; 40 | }); 41 | if (ESendBy.bot === val[0].sendBy) { 42 | this.onMsgReceive.emit(val[0].content); 43 | } 44 | return acc.concat(val); 45 | } ) 46 | ) 47 | this.msg.subscribe((msg) => { 48 | this.dataService.converse(msg); 49 | }) 50 | 51 | } 52 | 53 | public onChange(target: any) { 54 | this.msg.next(target.value); 55 | target.value = ''; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/ApiAiClient.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | var ApiAiConstants_1 = require("./ApiAiConstants"); 4 | var TextRequest_1 = require("./TextRequest"); 5 | var Errors_1 = require("./Errors"); 6 | var ApiAiConstants_2 = require("./ApiAiConstants"); 7 | exports.ApiAiConstants = ApiAiConstants_2.ApiAiConstants; 8 | var ApiAiClient = /** @class */ (function () { 9 | function ApiAiClient(options) { 10 | if (!options || !options.accessToken) { 11 | throw new Errors_1.ApiAiClientConfigurationError("Access token is required for new ApiAi.Client instance"); 12 | } 13 | this.accessToken = options.accessToken; 14 | this.apiLang = options.lang || ApiAiConstants_1.ApiAiConstants.DEFAULT_CLIENT_LANG; 15 | this.apiVersion = options.version || ApiAiConstants_1.ApiAiConstants.DEFAULT_API_VERSION; 16 | this.apiBaseUrl = options.baseUrl || ApiAiConstants_1.ApiAiConstants.DEFAULT_BASE_URL; 17 | this.sessionId = options.sessionId || this.guid(); 18 | } 19 | ApiAiClient.prototype.textRequest = function (query, options) { 20 | if (options === void 0) { options = {}; } 21 | if (!query) { 22 | throw new Errors_1.ApiAiClientConfigurationError("Query should not be empty"); 23 | } 24 | options.query = query; 25 | return new TextRequest_1["default"](this, options).perform(); 26 | }; 27 | ApiAiClient.prototype.getAccessToken = function () { 28 | return this.accessToken; 29 | }; 30 | ApiAiClient.prototype.getApiVersion = function () { 31 | return (this.apiVersion) ? this.apiVersion : ApiAiConstants_1.ApiAiConstants.DEFAULT_API_VERSION; 32 | }; 33 | ApiAiClient.prototype.getApiLang = function () { 34 | return (this.apiLang) ? this.apiLang : ApiAiConstants_1.ApiAiConstants.DEFAULT_CLIENT_LANG; 35 | }; 36 | ApiAiClient.prototype.getApiBaseUrl = function () { 37 | return (this.apiBaseUrl) ? this.apiBaseUrl : ApiAiConstants_1.ApiAiConstants.DEFAULT_BASE_URL; 38 | }; 39 | ApiAiClient.prototype.setSessionId = function (sessionId) { 40 | this.sessionId = sessionId; 41 | }; 42 | ApiAiClient.prototype.getSessionId = function () { 43 | return this.sessionId; 44 | }; 45 | /** 46 | * generates new random UUID 47 | * @returns {string} 48 | */ 49 | ApiAiClient.prototype.guid = function () { 50 | var s4 = function () { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); }; 51 | return s4() + s4() + "-" + s4() + "-" + s4() + "-" + 52 | s4() + "-" + s4() + s4() + s4(); 53 | }; 54 | return ApiAiClient; 55 | }()); 56 | exports.ApiAiClient = ApiAiClient; 57 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/ApiAiClient.ts: -------------------------------------------------------------------------------- 1 | import { ApiAiConstants } from "./ApiAiConstants"; 2 | import TextRequest from "./TextRequest"; 3 | import { ApiAiClientConfigurationError } from "./Errors"; 4 | 5 | 6 | import { IApiClientOptions, IRequestOptions, IServerResponse } from "./Interfaces"; 7 | 8 | export * from "./Interfaces"; 9 | export {ApiAiConstants} from "./ApiAiConstants"; 10 | 11 | export class ApiAiClient { 12 | 13 | private apiLang: ApiAiConstants.AVAILABLE_LANGUAGES; 14 | private apiVersion: string; 15 | private apiBaseUrl: string; 16 | private sessionId: string; 17 | private accessToken: string; 18 | 19 | constructor(options: IApiClientOptions) { 20 | 21 | if (!options || !options.accessToken) { 22 | throw new ApiAiClientConfigurationError("Access token is required for new ApiAi.Client instance"); 23 | } 24 | 25 | this.accessToken = options.accessToken; 26 | this.apiLang = options.lang || ApiAiConstants.DEFAULT_CLIENT_LANG; 27 | this.apiVersion = options.version || ApiAiConstants.DEFAULT_API_VERSION; 28 | this.apiBaseUrl = options.baseUrl || ApiAiConstants.DEFAULT_BASE_URL; 29 | this.sessionId = options.sessionId || this.guid(); 30 | } 31 | 32 | public textRequest(query, options: IRequestOptions = {}): Promise { 33 | if (!query) { 34 | throw new ApiAiClientConfigurationError("Query should not be empty"); 35 | } 36 | options.query = query; 37 | return new TextRequest(this, options).perform(); 38 | } 39 | 40 | public getAccessToken(): string { 41 | return this.accessToken; 42 | } 43 | 44 | public getApiVersion(): string { 45 | return (this.apiVersion) ? this.apiVersion : ApiAiConstants.DEFAULT_API_VERSION; 46 | } 47 | 48 | public getApiLang(): ApiAiConstants.AVAILABLE_LANGUAGES { 49 | return (this.apiLang) ? this.apiLang : ApiAiConstants.DEFAULT_CLIENT_LANG; 50 | } 51 | 52 | public getApiBaseUrl(): string { 53 | return (this.apiBaseUrl) ? this.apiBaseUrl : ApiAiConstants.DEFAULT_BASE_URL; 54 | } 55 | 56 | public setSessionId(sessionId: string) { 57 | this.sessionId = sessionId; 58 | } 59 | 60 | public getSessionId(): string { 61 | return this.sessionId; 62 | } 63 | 64 | /** 65 | * generates new random UUID 66 | * @returns {string} 67 | */ 68 | private guid(): string { 69 | const s4 = () => Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); 70 | return s4() + s4() + "-" + s4() + "-" + s4() + "-" + 71 | s4() + "-" + s4() + s4() + s4(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/ApiAiConstants.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | var ApiAiConstants; 4 | (function (ApiAiConstants) { 5 | var AVAILABLE_LANGUAGES; 6 | (function (AVAILABLE_LANGUAGES) { 7 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["EN"] = "en"] = "EN"; 8 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["DE"] = "de"] = "DE"; 9 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["ES"] = "es"] = "ES"; 10 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["PT_BR"] = "pt-BR"] = "PT_BR"; 11 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["ZH_HK"] = "zh-HK"] = "ZH_HK"; 12 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["ZH_CN"] = "zh-CN"] = "ZH_CN"; 13 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["ZH_TW"] = "zh-TW"] = "ZH_TW"; 14 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["NL"] = "nl"] = "NL"; 15 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["FR"] = "fr"] = "FR"; 16 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["IT"] = "it"] = "IT"; 17 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["JA"] = "ja"] = "JA"; 18 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["KO"] = "ko"] = "KO"; 19 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["PT"] = "pt"] = "PT"; 20 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["RU"] = "ru"] = "RU"; 21 | AVAILABLE_LANGUAGES[AVAILABLE_LANGUAGES["UK"] = "uk"] = "UK"; 22 | })(AVAILABLE_LANGUAGES = ApiAiConstants.AVAILABLE_LANGUAGES || (ApiAiConstants.AVAILABLE_LANGUAGES = {})); 23 | ApiAiConstants.DEFAULT_BASE_URL = "https://api.dialogflow.com/v1/"; 24 | ApiAiConstants.DEFAULT_API_VERSION = "20150910"; 25 | ApiAiConstants.DEFAULT_CLIENT_LANG = AVAILABLE_LANGUAGES.EN; 26 | })(ApiAiConstants = exports.ApiAiConstants || (exports.ApiAiConstants = {})); 27 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/ApiAiConstants.ts: -------------------------------------------------------------------------------- 1 | export namespace ApiAiConstants { 2 | export enum AVAILABLE_LANGUAGES { 3 | EN = "en" as any, DE = "de" as any, ES = "es" as any, PT_BR = "pt-BR" as any, ZH_HK = "zh-HK" as any, 4 | ZH_CN = "zh-CN" as any, ZH_TW = "zh-TW" as any, NL = "nl" as any, FR = "fr" as any, IT = "it" as any, 5 | JA = "ja" as any, KO = "ko" as any, PT = "pt" as any, RU = "ru" as any, UK = "uk" as any 6 | } 7 | 8 | export const DEFAULT_BASE_URL: string = "https://api.dialogflow.com/v1/"; 9 | export const DEFAULT_API_VERSION: string = "20150910"; 10 | export const DEFAULT_CLIENT_LANG: AVAILABLE_LANGUAGES = AVAILABLE_LANGUAGES.EN; 11 | } 12 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/Errors.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = Object.setPrototypeOf || 4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 6 | return function (d, b) { 7 | extendStatics(d, b); 8 | function __() { this.constructor = d; } 9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 10 | }; 11 | })(); 12 | exports.__esModule = true; 13 | var ApiAiBaseError = /** @class */ (function (_super) { 14 | __extends(ApiAiBaseError, _super); 15 | function ApiAiBaseError(message) { 16 | var _this = _super.call(this, message) || this; 17 | _this.message = message; 18 | _this.stack = new Error().stack; 19 | return _this; 20 | } 21 | return ApiAiBaseError; 22 | }(Error)); 23 | exports.ApiAiBaseError = ApiAiBaseError; 24 | var ApiAiClientConfigurationError = /** @class */ (function (_super) { 25 | __extends(ApiAiClientConfigurationError, _super); 26 | function ApiAiClientConfigurationError(message) { 27 | var _this = _super.call(this, message) || this; 28 | _this.name = "ApiAiClientConfigurationError"; 29 | return _this; 30 | } 31 | return ApiAiClientConfigurationError; 32 | }(ApiAiBaseError)); 33 | exports.ApiAiClientConfigurationError = ApiAiClientConfigurationError; 34 | var ApiAiRequestError = /** @class */ (function (_super) { 35 | __extends(ApiAiRequestError, _super); 36 | function ApiAiRequestError(message, code) { 37 | if (code === void 0) { code = null; } 38 | var _this = _super.call(this, message) || this; 39 | _this.message = message; 40 | _this.code = code; 41 | _this.name = "ApiAiRequestError"; 42 | return _this; 43 | } 44 | return ApiAiRequestError; 45 | }(ApiAiBaseError)); 46 | exports.ApiAiRequestError = ApiAiRequestError; 47 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/Errors.ts: -------------------------------------------------------------------------------- 1 | export abstract class ApiAiBaseError extends Error { 2 | 3 | public abstract name: string; 4 | public stack: string; 5 | constructor(public message: string) { 6 | super(message); 7 | this.stack = new Error().stack; 8 | } 9 | } 10 | 11 | export class ApiAiClientConfigurationError extends ApiAiBaseError { 12 | 13 | public name: string = "ApiAiClientConfigurationError"; 14 | 15 | constructor(message: string) { 16 | super(message); 17 | } 18 | } 19 | 20 | export class ApiAiRequestError extends ApiAiBaseError { 21 | 22 | public name: string = "ApiAiRequestError"; 23 | 24 | constructor(public message: string, public code: number = null) { 25 | super(message); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/Interfaces.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/Interfaces.ts: -------------------------------------------------------------------------------- 1 | import {ApiAiConstants} from "./ApiAiConstants"; 2 | 3 | export interface IRequestOptions { 4 | query?: string; 5 | event?: {name: string, data?: IStringMap}; 6 | sessionId?: string; 7 | lang?: ApiAiConstants.AVAILABLE_LANGUAGES; 8 | } 9 | 10 | export interface IServerResponse { 11 | id?: string; 12 | result?: { 13 | action: string, 14 | resolvedQuery: string, 15 | speech: string; 16 | fulfillment?: { 17 | speech: string 18 | } 19 | }; 20 | status: { 21 | code: number, 22 | errorDetails?: string, 23 | errorID?: string, 24 | errorType: string 25 | }; 26 | } 27 | 28 | export interface IStringMap { [s: string]: string; } 29 | 30 | export interface IApiClientOptions { 31 | lang?: ApiAiConstants.AVAILABLE_LANGUAGES; 32 | version?: string; 33 | baseUrl?: string; 34 | sessionId?: string; 35 | streamClientClass?: IStreamClientConstructor; 36 | accessToken: string; 37 | } 38 | 39 | export interface IStreamClientConstructor { 40 | new (options: IStreamClientOptions): IStreamClient; 41 | } 42 | 43 | export interface IStreamClient { 44 | init(): void; 45 | open(): void; 46 | close(): void; 47 | startListening(): void; 48 | stopListening(): void; 49 | } 50 | 51 | export interface IStreamClientOptions { 52 | server?: string; 53 | token?: string; 54 | sessionId?: string; 55 | lang?: ApiAiConstants.AVAILABLE_LANGUAGES; 56 | contentType?: string; 57 | readingInterval?: string; 58 | onOpen?: () => void; 59 | onClose?: () => void; 60 | onInit?: () => void; 61 | onStartListening?: () => void; 62 | onStopListening?: () => void; 63 | onResults?: (data: IServerResponse) => void; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/Request.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | var Errors_1 = require("./Errors"); 4 | var XhrRequest_1 = require("./XhrRequest"); 5 | var Request = /** @class */ (function () { 6 | function Request(apiAiClient, options) { 7 | this.apiAiClient = apiAiClient; 8 | this.options = options; 9 | this.uri = this.apiAiClient.getApiBaseUrl() + "query?v=" + this.apiAiClient.getApiVersion(); 10 | this.requestMethod = XhrRequest_1["default"].Method.POST; 11 | this.headers = { 12 | Authorization: "Bearer " + this.apiAiClient.getAccessToken() 13 | }; 14 | this.options.lang = this.apiAiClient.getApiLang(); 15 | this.options.sessionId = this.apiAiClient.getSessionId(); 16 | } 17 | Request.handleSuccess = function (xhr) { 18 | return Promise.resolve(JSON.parse(xhr.responseText)); 19 | }; 20 | Request.handleError = function (xhr) { 21 | var error = new Errors_1.ApiAiRequestError(null); 22 | try { 23 | var serverResponse = JSON.parse(xhr.responseText); 24 | if (serverResponse.status && serverResponse.status.errorDetails) { 25 | error = new Errors_1.ApiAiRequestError(serverResponse.status.errorDetails, serverResponse.status.code); 26 | } 27 | else { 28 | error = new Errors_1.ApiAiRequestError(xhr.statusText, xhr.status); 29 | } 30 | } 31 | catch (e) { 32 | error = new Errors_1.ApiAiRequestError(xhr.statusText, xhr.status); 33 | } 34 | return Promise.reject(error); 35 | }; 36 | Request.prototype.perform = function (overrideOptions) { 37 | if (overrideOptions === void 0) { overrideOptions = null; } 38 | var options = overrideOptions ? overrideOptions : this.options; 39 | return XhrRequest_1["default"].ajax(this.requestMethod, this.uri, options, this.headers) 40 | .then(Request.handleSuccess.bind(this))["catch"](Request.handleError.bind(this)); 41 | }; 42 | return Request; 43 | }()); 44 | exports["default"] = Request; 45 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/Request.ts: -------------------------------------------------------------------------------- 1 | import {ApiAiClient} from "./ApiAiClient"; 2 | import {ApiAiRequestError} from "./Errors"; 3 | import {IRequestOptions, IServerResponse, IStringMap} from "./Interfaces"; 4 | import XhrRequest from "./XhrRequest"; 5 | 6 | abstract class Request { 7 | 8 | private static handleSuccess(xhr: XMLHttpRequest): Promise { 9 | return Promise.resolve(JSON.parse(xhr.responseText)); 10 | } 11 | 12 | private static handleError(xhr: XMLHttpRequest): Promise { 13 | 14 | let error = new ApiAiRequestError(null); 15 | try { 16 | const serverResponse: IServerResponse = JSON.parse(xhr.responseText); 17 | if (serverResponse.status && serverResponse.status.errorDetails) { 18 | error = new ApiAiRequestError(serverResponse.status.errorDetails, serverResponse.status.code); 19 | } else { 20 | error = new ApiAiRequestError(xhr.statusText, xhr.status); 21 | } 22 | } catch (e) { 23 | error = new ApiAiRequestError(xhr.statusText, xhr.status); 24 | } 25 | 26 | return Promise.reject(error); 27 | } 28 | 29 | protected uri; 30 | protected requestMethod; 31 | protected headers; 32 | 33 | constructor(protected apiAiClient: ApiAiClient, protected options: IRequestOptions) { 34 | 35 | this.uri = this.apiAiClient.getApiBaseUrl() + "query?v=" + this.apiAiClient.getApiVersion(); 36 | this.requestMethod = XhrRequest.Method.POST; 37 | this.headers = { 38 | Authorization: "Bearer " + this.apiAiClient.getAccessToken(), 39 | }; 40 | 41 | this.options.lang = this.apiAiClient.getApiLang(); 42 | this.options.sessionId = this.apiAiClient.getSessionId(); 43 | 44 | } 45 | 46 | public perform(overrideOptions = null): Promise { 47 | 48 | const options = overrideOptions ? overrideOptions : this.options; 49 | 50 | return XhrRequest.ajax(this.requestMethod, this.uri, options as IStringMap, this.headers) 51 | .then(Request.handleSuccess.bind(this)) 52 | .catch(Request.handleError.bind(this)); 53 | } 54 | } 55 | 56 | export default Request; 57 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/TextRequest.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = Object.setPrototypeOf || 4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 6 | return function (d, b) { 7 | extendStatics(d, b); 8 | function __() { this.constructor = d; } 9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 10 | }; 11 | })(); 12 | exports.__esModule = true; 13 | var Request_1 = require("./Request"); 14 | var TextRequest = /** @class */ (function (_super) { 15 | __extends(TextRequest, _super); 16 | function TextRequest() { 17 | return _super !== null && _super.apply(this, arguments) || this; 18 | } 19 | return TextRequest; 20 | }(Request_1["default"])); 21 | exports["default"] = TextRequest; 22 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/TextRequest.ts: -------------------------------------------------------------------------------- 1 | import Request from "./Request"; 2 | export default class TextRequest extends Request { 3 | 4 | } 5 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/XhrRequest.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | var XhrRequest = /** @class */ (function () { 4 | function XhrRequest() { 5 | } 6 | // Method that performs the ajax request 7 | XhrRequest.ajax = function (method, url, args, headers, options) { 8 | if (args === void 0) { args = null; } 9 | if (headers === void 0) { headers = null; } 10 | if (options === void 0) { options = {}; } 11 | // Creating a promise 12 | return new Promise(function (resolve, reject) { 13 | // Instantiates the XMLHttpRequest 14 | var client = XhrRequest.createXMLHTTPObject(); 15 | var uri = url; 16 | var payload = null; 17 | // Add given payload to get request 18 | if (args && (method === XhrRequest.Method.GET)) { 19 | uri += "?"; 20 | var argcount = 0; 21 | for (var key in args) { 22 | if (args.hasOwnProperty(key)) { 23 | if (argcount++) { 24 | uri += "&"; 25 | } 26 | uri += encodeURIComponent(key) + "=" + encodeURIComponent(args[key]); 27 | } 28 | } 29 | } 30 | else if (args) { 31 | if (!headers) { 32 | headers = {}; 33 | } 34 | headers["Content-Type"] = "application/json; charset=utf-8"; 35 | payload = JSON.stringify(args); 36 | } 37 | for (var key in options) { 38 | if (key in client) { 39 | client[key] = options[key]; 40 | } 41 | } 42 | // hack: method[method] is somewhat like .toString for enum Method 43 | // should be made in normal way 44 | client.open(XhrRequest.Method[method], uri, true); 45 | // Add given headers 46 | if (headers) { 47 | for (var key in headers) { 48 | if (headers.hasOwnProperty(key)) { 49 | client.setRequestHeader(key, headers[key]); 50 | } 51 | } 52 | } 53 | payload ? client.send(payload) : client.send(); 54 | client.onload = function () { 55 | if (client.status >= 200 && client.status < 300) { 56 | // Performs the function "resolve" when this.status is equal to 2xx 57 | resolve(client); 58 | } 59 | else { 60 | // Performs the function "reject" when this.status is different than 2xx 61 | reject(client); 62 | } 63 | }; 64 | client.onerror = function () { 65 | reject(client); 66 | }; 67 | }); 68 | }; 69 | XhrRequest.get = function (url, payload, headers, options) { 70 | if (payload === void 0) { payload = null; } 71 | if (headers === void 0) { headers = null; } 72 | if (options === void 0) { options = {}; } 73 | return XhrRequest.ajax(XhrRequest.Method.GET, url, payload, headers, options); 74 | }; 75 | XhrRequest.post = function (url, payload, headers, options) { 76 | if (payload === void 0) { payload = null; } 77 | if (headers === void 0) { headers = null; } 78 | if (options === void 0) { options = {}; } 79 | return XhrRequest.ajax(XhrRequest.Method.POST, url, payload, headers, options); 80 | }; 81 | XhrRequest.put = function (url, payload, headers, options) { 82 | if (payload === void 0) { payload = null; } 83 | if (headers === void 0) { headers = null; } 84 | if (options === void 0) { options = {}; } 85 | return XhrRequest.ajax(XhrRequest.Method.PUT, url, payload, headers, options); 86 | }; 87 | XhrRequest["delete"] = function (url, payload, headers, options) { 88 | if (payload === void 0) { payload = null; } 89 | if (headers === void 0) { headers = null; } 90 | if (options === void 0) { options = {}; } 91 | return XhrRequest.ajax(XhrRequest.Method.DELETE, url, payload, headers, options); 92 | }; 93 | XhrRequest.createXMLHTTPObject = function () { 94 | var xmlhttp = null; 95 | for (var _i = 0, _a = XhrRequest.XMLHttpFactories; _i < _a.length; _i++) { 96 | var i = _a[_i]; 97 | try { 98 | xmlhttp = i(); 99 | } 100 | catch (e) { 101 | continue; 102 | } 103 | break; 104 | } 105 | return xmlhttp; 106 | }; 107 | XhrRequest.XMLHttpFactories = [ 108 | function () { return new XMLHttpRequest(); }, 109 | function () { return new window["ActiveXObject"]("Msxml2.XMLHTTP"); }, 110 | function () { return new window["ActiveXObject"]("Msxml3.XMLHTTP"); }, 111 | function () { return new window["ActiveXObject"]("Microsoft.XMLHTTP"); } 112 | ]; 113 | return XhrRequest; 114 | }()); 115 | (function (XhrRequest) { 116 | var Method; 117 | (function (Method) { 118 | Method[Method["GET"] = "GET"] = "GET"; 119 | Method[Method["POST"] = "POST"] = "POST"; 120 | Method[Method["PUT"] = "PUT"] = "PUT"; 121 | Method[Method["DELETE"] = "DELETE"] = "DELETE"; 122 | })(Method = XhrRequest.Method || (XhrRequest.Method = {})); 123 | })(XhrRequest || (XhrRequest = {})); 124 | exports["default"] = XhrRequest; 125 | -------------------------------------------------------------------------------- /chat-bot/src/app/client/XhrRequest.ts: -------------------------------------------------------------------------------- 1 | import {IStringMap} from "./Interfaces"; 2 | class XhrRequest { 3 | // Method that performs the ajax request 4 | public static ajax( 5 | method: XhrRequest.Method, 6 | url: string, 7 | args: IStringMap = null, 8 | headers: IStringMap = null, 9 | options: IStringMap = {} 10 | ): Promise { 11 | 12 | // Creating a promise 13 | return new Promise((resolve, reject) => { 14 | 15 | // Instantiates the XMLHttpRequest 16 | const client: XMLHttpRequest = XhrRequest.createXMLHTTPObject(); 17 | let uri: string = url; 18 | let payload = null; 19 | 20 | // Add given payload to get request 21 | if (args && (method === XhrRequest.Method.GET)) { 22 | uri += "?"; 23 | let argcount = 0; 24 | for (const key in args) { 25 | if (args.hasOwnProperty(key)) { 26 | if (argcount++) { 27 | uri += "&"; 28 | } 29 | uri += encodeURIComponent(key) + "=" + encodeURIComponent(args[key]); 30 | } 31 | } 32 | } else if (args) { 33 | if (!headers) { 34 | headers = {}; 35 | } 36 | headers["Content-Type"] = "application/json; charset=utf-8"; 37 | payload = JSON.stringify(args); 38 | } 39 | 40 | for (const key in options) { 41 | if (key in client) { 42 | client[key] = options[key]; 43 | } 44 | } 45 | 46 | // hack: method[method] is somewhat like .toString for enum Method 47 | // should be made in normal way 48 | client.open(XhrRequest.Method[method], uri, true); 49 | // Add given headers 50 | 51 | if (headers) { 52 | for (const key in headers) { 53 | if (headers.hasOwnProperty(key)) { 54 | client.setRequestHeader(key, headers[key]); 55 | } 56 | } 57 | } 58 | 59 | payload ? client.send(payload) : client.send(); 60 | 61 | client.onload = () => { 62 | if (client.status >= 200 && client.status < 300) { 63 | // Performs the function "resolve" when this.status is equal to 2xx 64 | resolve(client); 65 | } else { 66 | // Performs the function "reject" when this.status is different than 2xx 67 | reject(client); 68 | } 69 | }; 70 | client.onerror = () => { 71 | reject(client); 72 | }; 73 | }); 74 | 75 | } 76 | 77 | public static get(url, payload: IStringMap = null, headers: IStringMap = null, options = {}): Promise { 78 | return XhrRequest.ajax(XhrRequest.Method.GET, url, payload, headers, options); 79 | } 80 | 81 | public static post(url: string, payload: IStringMap = null, headers: IStringMap = null, 82 | options = {}): Promise { 83 | return XhrRequest.ajax(XhrRequest.Method.POST, url, payload, headers, options); 84 | } 85 | 86 | public static put(url: string, payload: IStringMap = null, headers: IStringMap = null, 87 | options = {}): Promise { 88 | return XhrRequest.ajax(XhrRequest.Method.PUT, url, payload, headers, options); 89 | } 90 | 91 | public static delete(url: string, payload: IStringMap = null, headers: IStringMap = null, 92 | options = {}): Promise { 93 | return XhrRequest.ajax(XhrRequest.Method.DELETE, url, payload, headers, options); 94 | } 95 | 96 | private static XMLHttpFactories: Function[] = [ 97 | () => new XMLHttpRequest(), 98 | () => new window["ActiveXObject"]("Msxml2.XMLHTTP"), 99 | () => new window["ActiveXObject"]("Msxml3.XMLHTTP"), 100 | () => new window["ActiveXObject"]("Microsoft.XMLHTTP") 101 | ]; 102 | 103 | private static createXMLHTTPObject(): XMLHttpRequest { 104 | let xmlhttp: XMLHttpRequest = null; 105 | for (const i of XhrRequest.XMLHttpFactories) { 106 | try { 107 | xmlhttp = i(); 108 | } catch (e) { 109 | continue; 110 | } 111 | break; 112 | } 113 | 114 | return xmlhttp; 115 | } 116 | } 117 | 118 | namespace XhrRequest { 119 | export enum Method { 120 | GET = "GET" as any, 121 | POST = "POST" as any, 122 | PUT = "PUT" as any, 123 | DELETE = "DELETE" as any 124 | } 125 | } 126 | 127 | export default XhrRequest; 128 | -------------------------------------------------------------------------------- /chat-bot/src/app/services/data.service.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | 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; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | exports.__esModule = true; 9 | var core_1 = require("@angular/core"); 10 | // Ai api Client 11 | var ApiAiClient_1 = require("../client/ApiAiClient"); 12 | // RxJs modules 13 | var rxjs_1 = require("rxjs"); 14 | var Message = /** @class */ (function () { 15 | function Message(content, sendBy) { 16 | this.content = content; 17 | this.sendBy = sendBy; 18 | } 19 | return Message; 20 | }()); 21 | exports.Message = Message; 22 | var ESendBy; 23 | (function (ESendBy) { 24 | ESendBy["user"] = "user"; 25 | ESendBy["bot"] = "bot"; 26 | })(ESendBy = exports.ESendBy || (exports.ESendBy = {})); 27 | var DataService = /** @class */ (function () { 28 | function DataService() { 29 | this.conversation = new rxjs_1.BehaviorSubject([]); 30 | } 31 | DataService.prototype.converse = function (msg) { 32 | var _this = this; 33 | var userMessage = new Message(msg, ESendBy.user); 34 | this.update(userMessage); 35 | return this.client.textRequest(msg) 36 | .then(function (res) { 37 | var speech = res.result.fulfillment.speech; 38 | var botMessage = new Message(speech, ESendBy.bot); 39 | _this.update(botMessage); 40 | }); 41 | }; 42 | DataService.prototype.update = function (msg) { 43 | this.conversation.next([msg]); 44 | }; 45 | DataService.prototype.init = function (token) { 46 | this.client = new ApiAiClient_1.ApiAiClient({ accessToken: token }); 47 | }; 48 | DataService = __decorate([ 49 | core_1.Injectable({ 50 | providedIn: 'root' 51 | }) 52 | ], DataService); 53 | return DataService; 54 | }()); 55 | exports.DataService = DataService; 56 | -------------------------------------------------------------------------------- /chat-bot/src/app/services/data.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | // Ai api Client 4 | import { ApiAiClient } from '../client/ApiAiClient'; 5 | 6 | // RxJs modules 7 | import { BehaviorSubject } from 'rxjs'; 8 | 9 | export class Message { 10 | constructor(public content: string, public sendBy: ESendBy) {} 11 | } 12 | 13 | export enum ESendBy { 14 | user = 'user', 15 | bot = 'bot' 16 | } 17 | 18 | @Injectable({ 19 | providedIn: 'root' 20 | }) 21 | export class DataService { 22 | 23 | private client; 24 | 25 | conversation = new BehaviorSubject([]); 26 | 27 | constructor() {} 28 | 29 | 30 | public converse(msg: string) { 31 | const userMessage = new Message(msg, ESendBy.user); 32 | this.update(userMessage); 33 | 34 | return this.client.textRequest(msg) 35 | .then(res => { 36 | const speech = res.result.fulfillment.speech; 37 | const botMessage = new Message(speech, ESendBy.bot); 38 | this.update(botMessage); 39 | }); 40 | } 41 | 42 | public update(msg: Message) { 43 | this.conversation.next([msg]); 44 | } 45 | 46 | public init(token: string) { 47 | this.client = new ApiAiClient({ accessToken: token }); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /chat-bot/src/demo/app.component.css: -------------------------------------------------------------------------------- 1 | .chat-window { 2 | display: flex; 3 | min-height: 500px; 4 | max-height: 500px; 5 | width: 35%; 6 | } 7 | 8 | .container { 9 | display: flex; 10 | height: 200px; 11 | width: 100px; 12 | } 13 | 14 | .message { 15 | display: flex; 16 | border-radius: 50px; 17 | justify-content: center; 18 | align-items: center; 19 | padding: 5px 10px; 20 | } 21 | -------------------------------------------------------------------------------- /chat-bot/src/demo/app.component.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /chat-bot/src/demo/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import {Observable, Subject, from } from 'rxjs'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.css'] 8 | }) 9 | export class AppComponent { 10 | 11 | public msg: Subject = new Subject(); 12 | public msgArray: Observable> = new Observable>(); 13 | 14 | constructor() { 15 | } 16 | 17 | public onChange(target: any) { 18 | this.msg.next(target.value); 19 | target.value = ''; 20 | } 21 | 22 | public onMsgReceive(msg: string) { } 23 | } 24 | -------------------------------------------------------------------------------- /chat-bot/src/demo/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppComponent } from './app.component'; 5 | import { ChatWindowComponent } from '../app/chat-window/chat-window.component'; 6 | import { ChatMsgComponent } from '../app/chat-msg/chat-msg.component'; 7 | import { ChatInputComponent } from '../app/chat-input/chat-input.component'; 8 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 9 | import { MatInputModule } from '@angular/material/input'; 10 | import { MatCardModule } from '@angular/material/card'; 11 | 12 | @NgModule({ 13 | declarations: [ 14 | AppComponent, 15 | ChatWindowComponent, 16 | ChatMsgComponent, 17 | ChatInputComponent 18 | ], 19 | imports: [ 20 | BrowserModule, 21 | BrowserAnimationsModule, 22 | MatInputModule, 23 | MatCardModule 24 | ], 25 | providers: [], 26 | bootstrap: [AppComponent] 27 | }) 28 | export class AppModule { } 29 | -------------------------------------------------------------------------------- /chat-bot/src/demo/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoghosyanHayk/Angular-AI-Chat-Bot/c5f6d121687fb044c648fe347952f405be85f853/chat-bot/src/demo/assets/.gitkeep -------------------------------------------------------------------------------- /chat-bot/src/demo/assets/scss/base/_variables.scss: -------------------------------------------------------------------------------- 1 | $darkblue: #303F9F; 2 | $blue: #3f51b5; 3 | $lightblue: #03A9F4; 4 | 5 | $pink: #FF4081; 6 | 7 | $bluegray: #607D8B; 8 | $lightgray: #C5CAE9; 9 | $darkgray: #212121; 10 | 11 | $white: #FFFFFF; -------------------------------------------------------------------------------- /chat-bot/src/demo/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # For IE 9-11 support, please uncomment the last line of the file and adjust as needed 5 | > 0.5% 6 | last 2 versions 7 | Firefox ESR 8 | not dead 9 | # IE 9-11 -------------------------------------------------------------------------------- /chat-bot/src/demo/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /chat-bot/src/demo/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * In development mode, to ignore zone related error stack frames such as 11 | * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can 12 | * import the following file, but please comment it out in production mode 13 | * because it will have performance impact when throw error 14 | */ 15 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 16 | -------------------------------------------------------------------------------- /chat-bot/src/demo/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoghosyanHayk/Angular-AI-Chat-Bot/c5f6d121687fb044c648fe347952f405be85f853/chat-bot/src/demo/favicon.ico -------------------------------------------------------------------------------- /chat-bot/src/demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ChatBot 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /chat-bot/src/demo/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '../', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /chat-bot/src/demo/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.log(err)); 13 | 14 | 15 | -------------------------------------------------------------------------------- /chat-bot/src/demo/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** IE10 and IE11 requires the following for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Web Animations `@angular/platform-browser/animations` 51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 53 | **/ 54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 55 | 56 | /** 57 | * By default, zone.js will patch all possible macroTask and DomEvents 58 | * user can disable parts of macroTask/DomEvents patch by setting following flags 59 | */ 60 | 61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 64 | 65 | /* 66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 68 | */ 69 | // (window as any).__Zone_enable_cross_context_check = true; 70 | 71 | /*************************************************************************************************** 72 | * Zone JS is required by default for Angular itself. 73 | */ 74 | import 'zone.js/dist/zone'; // Included with Angular CLI. 75 | 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /chat-bot/src/demo/styles.scss: -------------------------------------------------------------------------------- 1 | @import "../../node_modules/@angular/material/prebuilt-themes/indigo-pink.css"; 2 | 3 | .input-area > * { 4 | width: 100%; 5 | } 6 | 7 | 8 | ::-webkit-scrollbar 9 | { 10 | width: 0px; /* for vertical scrollbars */ 11 | height: 0px; /* for horizontal scrollbars */ 12 | } 13 | 14 | -------------------------------------------------------------------------------- /chat-bot/src/demo/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /chat-bot/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "es2015", 6 | "types": [], 7 | "forceConsistentCasingInFileNames": false 8 | }, 9 | "include": [ 10 | "./demo/main.ts", 11 | "./demo/polyfills.ts" 12 | ], 13 | "exclude": [ 14 | "./demo/test.ts" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /chat-bot/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "types": [ 7 | "jasmine", 8 | "node" 9 | ] 10 | }, 11 | "files": [ 12 | "./demo/test.ts", 13 | "./demo/polyfills.ts" 14 | ], 15 | "include": [ 16 | "**/*.spec.ts", 17 | "**/*.d.ts" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /chat-bot/src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /chat-bot/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "moduleResolution": "node", 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "forceConsistentCasingInFileNames": false, 12 | "typeRoots": [ 13 | "node_modules/@types" 14 | ], 15 | "lib": ["es5", "es2017", "dom"], 16 | "target": "ES5" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /chat-bot/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "callable-types": true, 7 | "class-name": true, 8 | "comment-format": [ 9 | true, 10 | "check-space" 11 | ], 12 | "curly": true, 13 | "eofline": true, 14 | "forin": true, 15 | "import-blacklist": [true], 16 | "import-spacing": true, 17 | "indent": [ 18 | true, 19 | "spaces" 20 | ], 21 | "interface-over-type-literal": true, 22 | "label-position": true, 23 | "max-line-length": [ 24 | true, 25 | 140 26 | ], 27 | "member-access": false, 28 | "member-ordering": [ 29 | true, 30 | "static-before-instance", 31 | "variables-before-functions" 32 | ], 33 | "no-arg": true, 34 | "no-bitwise": true, 35 | "no-console": [ 36 | true, 37 | "debug", 38 | "info", 39 | "time", 40 | "timeEnd", 41 | "trace" 42 | ], 43 | "no-construct": true, 44 | "no-debugger": true, 45 | "no-duplicate-variable": true, 46 | "no-empty": false, 47 | "no-empty-interface": true, 48 | "no-eval": true, 49 | "no-inferrable-types": true, 50 | "no-shadowed-variable": true, 51 | "no-string-literal": false, 52 | "no-string-throw": true, 53 | "no-switch-case-fall-through": true, 54 | "no-trailing-whitespace": true, 55 | "no-unused-expression": true, 56 | "no-use-before-declare": true, 57 | "no-var-keyword": true, 58 | "object-literal-sort-keys": false, 59 | "one-line": [ 60 | true, 61 | "check-open-brace", 62 | "check-catch", 63 | "check-else", 64 | "check-whitespace" 65 | ], 66 | "prefer-const": true, 67 | "quotemark": [ 68 | true, 69 | "single" 70 | ], 71 | "radix": true, 72 | "semicolon": [ 73 | "always" 74 | ], 75 | "triple-equals": [ 76 | true, 77 | "allow-null-check" 78 | ], 79 | "typedef-whitespace": [ 80 | true, 81 | { 82 | "call-signature": "nospace", 83 | "index-signature": "nospace", 84 | "parameter": "nospace", 85 | "property-declaration": "nospace", 86 | "variable-declaration": "nospace" 87 | } 88 | ], 89 | "typeof-compare": true, 90 | "unified-signatures": true, 91 | "variable-name": false, 92 | "whitespace": [ 93 | true, 94 | "check-branch", 95 | "check-decl", 96 | "check-operator", 97 | "check-separator", 98 | "check-type" 99 | ], 100 | 101 | "directive-selector": [true, "attribute", "app", "camelCase"], 102 | "component-selector": [true, "element", "app", "kebab-case"], 103 | "use-input-property-decorator": true, 104 | "use-output-property-decorator": true, 105 | "use-host-property-decorator": true, 106 | "no-input-rename": true, 107 | "no-output-rename": true, 108 | "use-life-cycle-interface": true, 109 | "use-pipe-transform-interface": true, 110 | "component-class-suffix": true, 111 | "directive-class-suffix": true, 112 | "no-access-missing-member": true, 113 | "templates-use-public": true, 114 | "invoke-injectable": true 115 | } 116 | } 117 | --------------------------------------------------------------------------------