├── .gitignore ├── LICENSE ├── client ├── ChatBotService │ ├── ChatBotService.cmp │ └── ChatBotServiceController.js └── HandlerChatBot.cls └── nodeRouterApp ├── app.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Parthi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /client/ChatBotService/ChatBotService.cmp: -------------------------------------------------------------------------------- 1 | 4 | 5 | 7 | 8 | 9 | 10 |
11 |
12 |
13 |
14 | 15 |
16 | {!chatItem.userName}

{!chatItem.chatText}


17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | 29 |
30 |
31 |
32 |
33 | 34 | 35 | 36 |
37 | -------------------------------------------------------------------------------- /client/ChatBotService/ChatBotServiceController.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Parthiban.Sudhaman on 28-May-17. 3 | */ 4 | ({ 5 | postUserChat: function(component, event, helper){ 6 | if(event.getParams().keyCode !== 13){ 7 | return; 8 | } 9 | var chatList = component.get("v.chatList"); 10 | var action = component.get("c.postChatText"); 11 | chatList.push({"chatText": component.get("v.userChat"), "userName": 'Me: '}); 12 | action.setParams({"chatText": component.get("v.userChat")}); 13 | component.set("v.userChat", ""); 14 | action.setCallback(this, function(response){ 15 | var data = JSON.parse(response.getReturnValue()); 16 | chatList.push({"chatText": data.result.fulfillment.speech, "userName": 'Personal Assistant: '}); 17 | component.set("v.chatList", chatList); 18 | var navigateUrl = ""; 19 | if(!data.result.actionIncomplete && data.result.action === 'OPEN_SCREEN'){ 20 | switch(data.result.parameters.SFObjectEntities){ 21 | case 'Opportunity': 22 | navigateUrl = "/006/o"; 23 | break; 24 | case 'Lead': 25 | navigateUrl = "/00Q/o"; 26 | break; 27 | case 'Task': 28 | navigateUrl = "00T/o"; 29 | break; 30 | default: 31 | navigateUrl = ""; 32 | break; 33 | 34 | } 35 | navigateUrl && $A.get("e.force:navigateToURL").setParams({ 36 | "url": navigateUrl, 37 | "isredirect": false 38 | }).fire(); 39 | } 40 | }); 41 | $A.enqueueAction(action); 42 | } 43 | }) 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /client/HandlerChatBot.cls: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Parthiban.Sudhaman on 28-May-17. 3 | */ 4 | 5 | public with sharing class HandlerChatBot { 6 | @AuraEnabled 7 | public static string postChatText(string chatText){ 8 | Http http = new Http(); 9 | HttpRequest request = new HttpRequest(); 10 | request.setEndpoint('https://chatbotmiddleware.azurewebsites.net/chat/'); 11 | request.setMethod('POST'); 12 | request.setHeader('Content-Type', 'application/json;charset=UTF-8'); 13 | request.setBody('{"chatText":"' + chatText + '"}'); 14 | HttpResponse response = http.send(request); 15 | // Parse the JSON response 16 | if (response.getStatusCode() != 201) { 17 | System.debug('The status code returned was not expected: ' + 18 | response.getStatusCode() + ' ' + response.getStatus()); 19 | } else { 20 | System.debug(response.getBody()); 21 | } 22 | return response.getBody(); 23 | } 24 | } -------------------------------------------------------------------------------- /nodeRouterApp/app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var bodyParser = require('body-parser'); 3 | var path = require('path'); 4 | var port = process.env.port || 3000; 5 | 6 | var app = express(); 7 | var apiai = require('apiai'); 8 | var apiapp = apiai("4155768d2ec44c59bd45b146fa5f3fac"); 9 | 10 | //Body parser 11 | app.use(bodyParser.json()); 12 | app.use(bodyParser.urlencoded({extended: false})); 13 | 14 | app.get('/', function(req, res){ 15 | res.send('Hello world!!'); 16 | }); 17 | 18 | app.post('/chat', function(req, res){ 19 | console.log(req.body.chatText); 20 | var request = apiapp.textRequest(req.body.chatText, { 21 | sessionId: '123123' 22 | }); 23 | request.on('response', function(response) { 24 | console.log(response); 25 | res.send(response); 26 | }); 27 | request.on('error', function(error) { 28 | console.log(error); 29 | res.send(error); 30 | }); 31 | request.end(); 32 | }); 33 | 34 | app.listen(port, function(){ 35 | console.log('server started on Port 3000...') 36 | }); -------------------------------------------------------------------------------- /nodeRouterApp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apiai-middleware", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "dependencies": { 10 | "express":"*", 11 | "body-parser":"*", 12 | "apiai": "*" 13 | }, 14 | "author": "", 15 | "license": "ISC" 16 | } 17 | --------------------------------------------------------------------------------