@tiledesk/tiledesk-tybot-connector 0.1.41 → 0.1.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/.env +6 -2
  2. package/CHANGELOG.md +10 -0
  3. package/DEPRECATED_MockActions.js +148 -0
  4. package/ExtUtil.js +3 -3
  5. package/TdCache.js +34 -0
  6. package/TiledeskExpression.js +61 -0
  7. package/herokulog.sh +1 -0
  8. package/index.js +223 -78
  9. package/models/IntentForm.js +56 -6
  10. package/models/{IntentFormStudy.js → IntentForm_no_prefill.js} +6 -32
  11. package/models/MockBotsDataSource.js +7 -1
  12. package/models/TiledeskChatbot.js +87 -43
  13. package/models/TiledeskChatbotUtil.js +33 -0
  14. package/models/TiledeskIntentsMachine.js +49 -4
  15. package/package.json +2 -2
  16. package/test/chatbot_util_test.js +54 -0
  17. package/test/close_directive_test.js +5 -2
  18. package/test/condition_evaluator_test.js +151 -0
  19. package/test/conversation-actions-test.js +346 -0
  20. package/test/conversation-actions_bot.js +246 -0
  21. package/test/conversation-form-test.js +1043 -0
  22. package/test/conversation-form_bot.js +834 -0
  23. package/test/{conversation1-test.js → conversation1-test copy.js_ } +346 -24
  24. package/test/intent_form_pre_filled_test.js +260 -0
  25. package/test/intent_form_test.js +0 -1
  26. package/test/send_email_directive_test.js +60 -57
  27. package/test/single_test.sh +11 -7
  28. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +237 -57
  29. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +11 -5
  30. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +9 -3
  31. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +7 -2
  32. package/tiledeskChatbotPlugs/directives/DirAssign.js +114 -0
  33. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +132 -0
  34. package/tiledeskChatbotPlugs/directives/DirClose.js +5 -3
  35. package/tiledeskChatbotPlugs/directives/DirCondition.js +179 -0
  36. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -1
  37. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +74 -0
  38. package/tiledeskChatbotPlugs/directives/DirDepartment.js +40 -10
  39. package/tiledeskChatbotPlugs/directives/DirIfAvailableAgents.js +3 -0
  40. package/tiledeskChatbotPlugs/directives/DirIfNotOpenHours.js +91 -0
  41. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +90 -0
  42. package/tiledeskChatbotPlugs/directives/DirIntent.js +165 -29
  43. package/tiledeskChatbotPlugs/directives/DirMessage.js +113 -36
  44. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +45 -9
  45. package/tiledeskChatbotPlugs/directives/DirOfflineHours.js +1 -1
  46. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +36 -0
  47. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +24 -8
  48. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +54 -17
  49. package/tiledeskChatbotPlugs/directives/DirWait.js +27 -5
  50. package/tiledeskChatbotPlugs/directives/DirWhenOpen.js +3 -0
  51. package/tiledeskChatbotPlugs/directives/Directives.js +21 -4
package/.env CHANGED
@@ -4,7 +4,11 @@ REDIS_HOST=localhost
4
4
  REDIS_PORT=6379
5
5
  TYBOT_ENDPOINT=http://localhost:10001
6
6
  CHATBOT_TOKEN=JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3ZWJob29rX2VuYWJsZWQiOmZhbHNlLCJ0eXBlIjoiZXh0ZXJuYWwiLCJsYW5ndWFnZSI6ImVuIiwicHVibGljIjpmYWxzZSwiX2lkIjoiNjM4Yzc5MDQxZGI0NDkwMDM1MTEwMjYwIiwibmFtZSI6IlRoZSBGb3JtIHYyIC0gZXh0IiwidXJsIjoiaHR0cHM6Ly90aWxlYm90LWRldi5oZXJva3VhcHAuY29tL2V4dC82MzhjNzhkNzFkYjQ0OTAwMzUxMTAxYzIiLCJpZF9wcm9qZWN0IjoiNjM4Yzc4YTYxZGI0NDkwMDM1MTBmZjkxIiwidHJhc2hlZCI6ZmFsc2UsImNyZWF0ZWRCeSI6IjVlMDlkMTZkNGQzNjExMDAxNzUwNmQ3ZiIsImNyZWF0ZWRBdCI6IjIwMjItMTItMDRUMTA6NDA6MDQuMjA3WiIsInVwZGF0ZWRBdCI6IjIwMjItMTItMDVUMDc6MjE6MDIuOTIxWiIsIl9fdiI6MCwiZGVzY3JpcHRpb24iOiJPbiBIZXJva3UiLCJpYXQiOjE2NzA2NzE4ODksImF1ZCI6Imh0dHBzOi8vdGlsZWRlc2suY29tL2JvdHMvNjM4Yzc5MDQxZGI0NDkwMDM1MTEwMjYwIiwiaXNzIjoiaHR0cHM6Ly90aWxlZGVzay5jb20iLCJzdWIiOiJib3QiLCJqdGkiOiJmNDVlZGIwYS0zNzVhLTQ0NjMtYjFhZi1jM2ZiZDg4YmE3ZGQifQ.FbW3csHl1sQgSyRz5Jg0qaTvvpXWXgWHlJ1JWoVbv3s
7
- CHATBOT_ENDPOINT=http://localhost:10001
7
+ _CHATBOT_ENDPOINT=http://localhost:10001
8
8
  _API_LOG=1
9
9
  TEST_PROJECT_ID=638c78a61db449003510ff91
10
- TEST_BOT_ID=638c78d71db44900351101c2
10
+ TEST_BOT_ID=638c78d71db44900351101c2
11
+
12
+ TEST_ACTIONS_PROJECT_ID=63b2ab8fd0029e0035252df5
13
+ TEST_ACTIONS_BOT_ID=63b2aba4d0029e0035252ebb
14
+ ACTIONS_CHATBOT_TOKEN=JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3ZWJob29rX2VuYWJsZWQiOmZhbHNlLCJ0eXBlIjoiZXh0ZXJuYWwiLCJsYW5ndWFnZSI6ImVuIiwicHVibGljIjpmYWxzZSwiY2VydGlmaWVkIjpmYWxzZSwiaW50ZW50c0VuZ2luZSI6Im5vbmUiLCJfaWQiOiI2M2IyYWJkY2QwMDI5ZTAwMzUyNTMyNGIiLCJuYW1lIjoiQWN0aW9ucyBCb3QgLSBleHQiLCJ1cmwiOiJodHRwczovL3RpbGVib3QtZGV2Lmhlcm9rdWFwcC5jb20vZXh0LzYzYjJhYmE0ZDAwMjllMDAzNTI1MmViYiIsImlkX3Byb2plY3QiOiI2M2IyYWI4ZmQwMDI5ZTAwMzUyNTJkZjUiLCJ0cmFzaGVkIjpmYWxzZSwiY3JlYXRlZEJ5IjoiNWUwOWQxNmQ0ZDM2MTEwMDE3NTA2ZDdmIiwiY3JlYXRlZEF0IjoiMjAyMy0wMS0wMlQxMDowMzowOC43NTVaIiwidXBkYXRlZEF0IjoiMjAyMy0wMS0wMlQxMDowMzo1MS4yOTZaIiwiX192IjowLCJpYXQiOjE2NzMzNzA5NzksImF1ZCI6Imh0dHBzOi8vdGlsZWRlc2suY29tL2JvdHMvNjNiMmFiZGNkMDAyOWUwMDM1MjUzMjRiIiwiaXNzIjoiaHR0cHM6Ly90aWxlZGVzay5jb20iLCJzdWIiOiJib3QiLCJqdGkiOiJjMTI2ZTk1Yi1lMGY2LTRmNDQtOTQ3NS0xN2IxNDMzYmY0MjEifQ.TWfVy7frEA98o596xCa-8hNnBAzBVhpYTz9p_zmNA4M
package/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ ### 0.1.43
9
+ - added context variable chatbot.addParameter("_tdRequestId", requestId);
10
+ - completed TiledeskIntentsMachine.js
11
+ - tdCondition
12
+ - tdAssign
13
+ - /IntentName{"variableName":"value", ...}
14
+
15
+ ### 0.1.42
16
+ - added IntentForm pre-set variables skipping
17
+
8
18
  ### 0.1.41
9
19
  - added Filler
10
20
  - added Filler to email .to .subject .text attributes
@@ -0,0 +1,148 @@
1
+ class MockActions {
2
+
3
+ static MessageActions() {
4
+ return [
5
+ {
6
+ type: "message",
7
+ body: {
8
+ message: {
9
+ "attributes": {
10
+ "commands": [{
11
+ "type": "message",
12
+ "message": {
13
+ "text": "Hello by message directive!",
14
+ "type": "text"
15
+ }
16
+ }, {
17
+ "type": "wait",
18
+ "time": 500
19
+ }, {
20
+ "type": "message",
21
+ "message": {
22
+ "text": "Ciao",
23
+ "type": "text",
24
+ "attributes": {
25
+ "attachment": {
26
+ "type": "template",
27
+ "buttons": [{
28
+ "type": "text",
29
+ "value": "/start"
30
+ }]
31
+ }
32
+ }
33
+ }
34
+ }]
35
+ }
36
+ }
37
+ }
38
+ }
39
+ ]
40
+ }
41
+
42
+ static Message_plus_Agent() {
43
+ return [
44
+ {
45
+ type: "message",
46
+ body: {
47
+ message: {
48
+ "attributes": {
49
+ "commands": [{
50
+ "type": "message",
51
+ "message": {
52
+ "text": "Moving you to an agent...",
53
+ "type": "text"
54
+ }
55
+ }]
56
+ }
57
+ }
58
+ }
59
+ },
60
+ {
61
+ type: "agent"
62
+ }
63
+ ]
64
+ }
65
+
66
+ static Message_plus_AgentWhenOnline() {
67
+ return [
68
+ {
69
+ type: "message",
70
+ body: {
71
+ message: {
72
+ "attributes": {
73
+ "commands": [{
74
+ "type": "message",
75
+ "message": {
76
+ "text": "Looking for an agent online...",
77
+ "type": "text"
78
+ }
79
+ }]
80
+ }
81
+ }
82
+ }
83
+ },
84
+ {
85
+ type: "whenonlinemovetoagent"
86
+ }
87
+ ]
88
+ }
89
+
90
+ static Message_plus_Close() {
91
+ return [
92
+ {
93
+ type: "message",
94
+ body: {
95
+ message: {
96
+ "attributes": {
97
+ "commands": [{
98
+ "type": "message",
99
+ "message": {
100
+ "text": "Closing...",
101
+ "type": "text"
102
+ }
103
+ }]
104
+ }
105
+ }
106
+ }
107
+ },
108
+ {
109
+ type: "close"
110
+ }
111
+ ]
112
+ }
113
+
114
+ static ChangeDepartment() {
115
+ return [
116
+ {
117
+ type: "department",
118
+ body: {
119
+ depName: "Support"
120
+ }
121
+ },
122
+ {
123
+ type: "message",
124
+ body: {
125
+ message: {
126
+ text: "/start",
127
+ "attributes": {
128
+ "subtype": "info"
129
+ }
130
+ }
131
+ }
132
+ }
133
+ ]
134
+ }
135
+
136
+ static Intent() {
137
+ return [
138
+ {
139
+ type: "intent",
140
+ body: {
141
+ intentName: "intentAction"
142
+ }
143
+ }
144
+ ]
145
+ }
146
+
147
+ }
148
+ module.exports = { MockActions };
package/ExtUtil.js CHANGED
@@ -17,10 +17,10 @@ class ExtUtil {
17
17
 
18
18
  static async execPipelineExt(request, static_bot_answer, directivesPlug, tdcache, log) {
19
19
  const messagePipeline = new MessagePipeline(static_bot_answer, null);
20
- //const webhookurl = bot.webhook_url;
21
- //messagePipeline.addPlug(new WebhookChatbotPlug(message.request, webhookurl, token));
22
- messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache, log)); // in original message
20
+ // /// const webhookurl = bot.webhook_url;
21
+ // /// messagePipeline.addPlug(new WebhookChatbotPlug(message.request, webhookurl, token));
23
22
  messagePipeline.addPlug(directivesPlug);
23
+ messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache, log)); // in original message
24
24
  messagePipeline.addPlug(new SplitsChatbotPlug(log));
25
25
  messagePipeline.addPlug(new MarkbotChatbotPlug(log));
26
26
  messagePipeline.addPlug(new FillParamsChatbotPlug(request, tdcache, log)); // in splits
package/TdCache.js CHANGED
@@ -107,6 +107,40 @@ class TdCache {
107
107
  return resolve();
108
108
  });
109
109
  }
110
+
111
+ async hdel(dict_key, key, options) {
112
+ //console.log("hsetting dict_key key value", dict_key, key, value)
113
+ return new Promise( async (resolve, reject) => {
114
+ if (options && options.EX) {
115
+ //console.log("expires:", options.EX)
116
+ try {
117
+ await this.client.hdel(
118
+ dict_key,
119
+ key,
120
+ 'EX', options.EX);
121
+ }
122
+ catch(error) {
123
+ reject(error)
124
+ }
125
+ }
126
+ else {
127
+ try {
128
+ //console.log("setting here...key", key, value)
129
+ await this.client.hdel(
130
+ dict_key,
131
+ key);
132
+ }
133
+ catch(error) {
134
+ console.error("Error", error);
135
+ reject(error);
136
+ }
137
+ }
138
+ if (options && options.callback) {
139
+ options.callback();
140
+ }
141
+ return resolve();
142
+ });
143
+ }
110
144
 
111
145
  async setJSON(key, value, options) {
112
146
  const _string = JSON.stringify(value);
@@ -0,0 +1,61 @@
1
+ class TiledeskExpression {
2
+ // rules:
3
+ // check valid operators (only those in operators are allowed)
4
+ // check valid variable names /^[_0-9a-zA-Z\.]$/
5
+
6
+ static operators = {
7
+ ">" : {
8
+ applyPattern: "Number(${1}) > Number(${2})"
9
+ },
10
+ ">=" : {
11
+ applyPattern: "Number(${1}) >= Number(${2})"
12
+ },
13
+ "<" : {
14
+ applyPattern: "Number(${1}) < Number(${2})"
15
+ },
16
+ "&&": {
17
+ applyPattern: " && ${2}"
18
+ },
19
+ "||": {
20
+ applyPattern: " && ${2}"
21
+ },
22
+ "startsWith": {
23
+ applyPattern: "${1}.startsWith(${2})"
24
+ },
25
+ "contains": {
26
+ applyPattern: "?"
27
+ },
28
+ "endsWith": {
29
+ applyPattern: "?"
30
+ },
31
+ "matches": {
32
+ applyPattern: "?"
33
+ }
34
+ }
35
+
36
+ // public
37
+ evaluateExpression(_expression, variables) {
38
+ // console.log("Original expression:", _expression);
39
+ let expression = String(_expression).replace(/\$/g, "$data.");
40
+ // console.log("Evaluating expression:", expression);
41
+ // console.log("With variables:", variables);
42
+ const result = new TiledeskExpression().evaluate(expression, variables);
43
+ // console.log("Expression result:", result);
44
+ return result;
45
+ }
46
+
47
+ // private
48
+ evaluate(expression, context) {
49
+ let fn = Function(`let $data = this;return (${expression})`);
50
+ // let fn = Function(`let $data = this;console.log('data', $data);return (${conditionExpression})`);
51
+ let res = fn.bind(context)()
52
+ return res;
53
+ }
54
+
55
+ JSON2condition(json) {
56
+ return "";
57
+ }
58
+
59
+ }
60
+
61
+ module.exports = { TiledeskExpression }
package/herokulog.sh ADDED
@@ -0,0 +1 @@
1
+ heroku logs --tail --app tilebot-dev