-
Notifications
You must be signed in to change notification settings - Fork 363
Expand file tree
/
Copy pathconversation_lab.json
More file actions
136 lines (136 loc) · 6.62 KB
/
conversation_lab.json
File metadata and controls
136 lines (136 loc) · 6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
[{
"id": "b3330b31.662488",
"type": "watson-conversation-v1",
"z": "72348800.770678",
"name": "My Bot",
"workspaceid": "",
"multiuser": false,
"context": false,
"empty-payload": false,
"default-endpoint": false,
"service-endpoint": "",
"x": 447,
"y": 196,
"wires": [
["32b8547d.30af5c"]
]
}, {
"id": "8766f7e0.6684e8",
"type": "http in",
"z": "72348800.770678",
"name": "BOT Home Page",
"url": "/bot",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 113,
"y": 87,
"wires": [
["69503ce4.8665d4"]
]
}, {
"id": "1caa670e.0138d9",
"type": "template",
"z": "72348800.770678",
"name": "HTML",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "<!--\n# Copyright 2018 IBM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n-->\n\n<html>\n <head>\n <meta charset=\"utf-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>\n\t My BOT\n\t</title>\n\t<link rel=\"stylesheet\"\n type=\"text/css\"\n href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" />\n </head>\n <body>\n\n <div class=\"container\">\n <div id=\"no-script\"class=\"bg-info\">\n This application needs JavaScript enabled in your browser!\n </div>\n <div id=\"id_contextdump\"></div>\n\n <h1>My BOT</h1>\n <div id=id_botchathistory>\n\t </div>\n\t \n\t <div>\n\t <form>\n <label for=\"id_chattext\">Your Input: </label>\n <input type=\"text\" name=\"chattext\" id=\"id_chattext\">\n <br/><br/>\n\t </form>\n\t <button onclick=\"javascript:onChatClick()\" id=\"id_enter\">Send</button>\n\t </div>\n </div>\n \n <script type=\"text/javascript\" src=\"https://code.jquery.com/jquery-2.1.4.min.js\"></script>\n <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"></script>\n\n <script>{{{payload.script}}}</script>\n </body>\n</html>\n",
"x": 532,
"y": 87,
"wires": [
["f6b3b293.da141"]
]
}, {
"id": "f6b3b293.da141",
"type": "http response",
"z": "72348800.770678",
"name": "",
"x": 746,
"y": 87,
"wires": []
}, {
"id": "38a3db46.fa5df4",
"type": "http in",
"z": "72348800.770678",
"name": "BOT REST API",
"url": "/botchat",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 112,
"y": 198,
"wires": [
["3b16c868.99c7c8"]
]
}, {
"id": "4aba78f1.afdba8",
"type": "http response",
"z": "72348800.770678",
"name": "",
"x": 743,
"y": 193,
"wires": []
}, {
"id": "3b16c868.99c7c8",
"type": "function",
"z": "72348800.770678",
"name": "Pre Service Processing",
"func": "// stash away incoming data\nmsg.mydata = {};\nmsg.mydata.messagein = msg.req.body.msgdata;\nmsg.payload = msg.mydata.messagein;\n\nmsg.params = { \"context\": msg.req.body.context};\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 289,
"y": 285,
"wires": [
["b3330b31.662488"]
]
}, {
"id": "32b8547d.30af5c",
"type": "function",
"z": "72348800.770678",
"name": "Post Service Processing",
"func": "msg.mydata.messageout = msg.payload;\n\nmsg.payload = {};\nmsg.payload.botresponse = msg.mydata;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 607,
"y": 289,
"wires": [
["4aba78f1.afdba8"]
]
}, {
"id": "69503ce4.8665d4",
"type": "template",
"z": "72348800.770678",
"name": "JavaScript",
"field": "payload.script",
"fieldType": "msg",
"format": "javascript",
"syntax": "mustache",
"template": "$(document).ready(function() {\n javascriptCheck();\n $('#id_contextdump').hide();\n enterbutton();\n invokeAjax (\"Hello\");\n});\n\n// if javascript is enabled on the browser then can remove the warning message\nfunction javascriptCheck() {\n $('#no-script').remove();\n}\n\n// creates div for interaction with bot \nfunction createNewDiv(who, message) {\n var txt = who + ' : ' + message;\n return $('<div></div>').text(txt);\n}\n\n// appends latest communication with bot to botchathistory\nfunction chat(person, txt) {\n $('#id_botchathistory').append(createNewDiv(person, txt));\n} \n\n// sets pressing of enter key to perform same action as send button\nfunction enterbutton(){\n $(function() {\n $(\"form input\").keypress(function (e) {\n if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {\n $('#id_enter').click();\n return false;\n } else {\n return true;\n }\n });\n });\n}\n\n// User has entered some text.\nfunction onChatClick() {\n var txt = $('#id_chattext').val();\n chat('You', txt); \n invokeAjax(txt);\n $('#id_chattext').val('');\n}\n\nfunction processOK(response) {\n console.log(response);\n console.log(response.botresponse.messageout);\n console.log(response.botresponse.messageout.output.text);\n console.log(response.botresponse.messageout.context);\n chat('Bot', response.botresponse.messageout.output.text); \n $('#id_contextdump').data('convContext', response.botresponse.messageout.context);\n}\n \nfunction processNotOK() {\n chat('Error', 'Error whilst attempting to talk to Bot');\n}\n \nfunction invokeAjax(message) {\n var contextdata = $('#id_contextdump').data('convContext');\n console.log('checking stashed context data');\n console.log(contextdata);\n \n var ajaxData = {};\n ajaxData.msgdata = message;\n if (contextdata) {\n ajaxData.context = contextdata; \n }\n\n $.ajax({\n type: 'POST',\n url: 'botchat',\n data: ajaxData,\n success: processOK,\n error: processNotOK\n });\n}",
"output": "str",
"x": 336,
"y": 87,
"wires": [
["1caa670e.0138d9"]
]
}, {
"id": "6cf1222c.fbe88c",
"type": "comment",
"z": "72348800.770678",
"name": "Conversation BOT Template",
"info": "",
"x": 152,
"y": 46,
"wires": []
}, {
"id": "53946458.57dcdc",
"type": "comment",
"z": "72348800.770678",
"name": "Conversation REST API",
"info": "",
"x": 131,
"y": 158,
"wires": []
}]