@tiledesk/tiledesk-server 2.1.40 → 2.2.3

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 (91) hide show
  1. package/.circleci/config.yml +54 -0
  2. package/.env.sample +1 -1
  3. package/.github/workflows/docker-community-push-latest.yml +22 -0
  4. package/.github/workflows/{docker-image-push.yml → docker-image-en-tag-push.yml} +1 -1
  5. package/.github/workflows/docker-image-tag-community-tag-push.yml +21 -0
  6. package/.github/workflows/{docker-push-latest.yml → docker-push-en-push-latest.yml} +1 -1
  7. package/CHANGELOG.md +195 -1
  8. package/Dockerfile +1 -1
  9. package/Dockerfile-en +1 -1
  10. package/README.md +5 -7
  11. package/app.js +12 -1
  12. package/channels/channelManager.js +1 -1
  13. package/channels/chat21/chat21Contact.js +34 -8
  14. package/channels/chat21/chat21Handler.js +48 -5
  15. package/channels/chat21/chat21WebHook.js +34 -9
  16. package/channels/chat21/nativeauth.js +2 -2
  17. package/channels/chat21/package-lock.json +3013 -0
  18. package/config/email.js +2 -0
  19. package/config/global.js +3 -0
  20. package/config/labels/widget.json +170 -16
  21. package/event/messageEvent.js +18 -1
  22. package/middleware/passport.js +10 -4
  23. package/migrations/1619185894304-request-remove-duplicated-request-by-request_id--autosync.js +67 -0
  24. package/models/actionsConstants.js +7 -0
  25. package/models/department.js +3 -0
  26. package/models/faq.js +8 -2
  27. package/models/faq_kb.js +6 -0
  28. package/models/message.js +10 -4
  29. package/models/messageConstants.js +9 -3
  30. package/models/request.js +33 -3
  31. package/package.json +31 -28
  32. package/pubmodules/emailNotification/requestNotification.js +483 -56
  33. package/pubmodules/messageActions/messageActionsInterceptor.js +20 -7
  34. package/pubmodules/messageTransformer/index.js +5 -1
  35. package/pubmodules/messageTransformer/messageTransformerInterceptor.js +4 -2
  36. package/pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor.js +67 -0
  37. package/pubmodules/messageTransformer/microLanguageTransformerInterceptor.js +67 -0
  38. package/pubmodules/pubModulesManager.js +66 -13
  39. package/pubmodules/rules/conciergeBot.js +81 -49
  40. package/routes/auth.js +46 -11
  41. package/routes/campaigns.js +117 -25
  42. package/routes/department.js +2 -2
  43. package/routes/faq.js +19 -0
  44. package/routes/faq_kb.js +13 -4
  45. package/routes/faqpub.js +1 -1
  46. package/routes/files.js +17 -2
  47. package/routes/images.js +1 -1
  48. package/routes/jwt.js +0 -1
  49. package/routes/logs.js +26 -0
  50. package/routes/message.js +7 -2
  51. package/routes/messagesRoot.js +73 -16
  52. package/routes/project_user.js +36 -1
  53. package/routes/request.js +88 -12
  54. package/routes/requestUtilRoot.js +30 -0
  55. package/routes/urls.js +12 -0
  56. package/routes/users.js +5 -1
  57. package/services/BotSubscriptionNotifier.js +1 -0
  58. package/services/departmentService.js +29 -5
  59. package/services/emailService.js +1170 -239
  60. package/services/faqBotHandler.js +176 -61
  61. package/services/faqBotSupport.js +182 -117
  62. package/services/faqService.js +18 -14
  63. package/services/messageService.js +57 -9
  64. package/services/modulesManager.js +86 -23
  65. package/services/requestService.js +58 -17
  66. package/template/email/assignedEmailMessage.html +205 -0
  67. package/template/email/assignedRequest.html +44 -14
  68. package/template/email/beenInvitedExistingUser.html +2 -2
  69. package/template/email/beenInvitedNewUser.html +1 -1
  70. package/template/email/newMessage.html +31 -12
  71. package/template/email/passwordChanged.html +2 -3
  72. package/template/email/pooledEmailMessage.html +208 -0
  73. package/template/email/pooledRequest.html +41 -14
  74. package/template/email/resetPassword.html +2 -3
  75. package/template/email/sendTranscript.html +1 -1
  76. package/template/email/test.html +1 -1
  77. package/template/email/ticket.html +191 -0
  78. package/template/email/ticket.txt +11 -0
  79. package/template/email/verify.html +1 -1
  80. package/test/authentication.js +76 -4
  81. package/test/authenticationJwt.js +76 -2
  82. package/test/campaignsRoute.js +226 -0
  83. package/test/faqService.js +3 -3
  84. package/test/faqkbRoute.js +3 -2
  85. package/test/messageRootRoute.js +193 -0
  86. package/test/messageRoute.js +75 -0
  87. package/test/messageService.js +39 -2
  88. package/test/requestRoute.js +27 -9
  89. package/test/requestService.js +472 -11
  90. package/test-int/bot.js +673 -8
  91. package/websocket/webSocketServer.js +7 -4
@@ -0,0 +1,54 @@
1
+ # Use the latest 2.1 version of CircleCI pipeline process engine.
2
+ # See: https://circleci.com/docs/2.0/configuration-reference
3
+ version: 2.1
4
+
5
+ orbs:
6
+ # The Node.js orb contains a set of prepackaged CircleCI configuration you can utilize
7
+ # Orbs reduce the amount of configuration required for common tasks.
8
+ # See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/node
9
+ node: circleci/node@4.1
10
+
11
+
12
+ jobs:
13
+ # Below is the definition of your job to build and test your app, you can rename and customize it as you want.
14
+ build-and-test:
15
+ # These next lines define a Docker executor: https://circleci.com/docs/2.0/executor-types/
16
+ # You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
17
+ # A list of available CircleCI Docker Convenience Images are available here: https://circleci.com/developer/images/image/cimg/node
18
+ docker:
19
+ - image: cimg/node:15.1
20
+ # Then run your tests!
21
+ # CircleCI will report the results back to your VCS provider.
22
+ steps:
23
+ # Checkout the code as the first step.
24
+ - checkout
25
+ # Next, the node orb's install-packages step will install the dependencies from a package.json.
26
+ # The orb install-packages step will also automatically cache them for faster future runs.
27
+ - node/install-packages
28
+ # If you are using yarn instead npm, remove the line above and uncomment the two lines below.
29
+ # - node/install-packages:
30
+ # pkg-manager: yarn
31
+ - restore_cache:
32
+ keys:
33
+ # when lock file changes, use increasingly general patterns to restore cache
34
+ - node-v1-{{ .Branch }}-{{ checksum "package-lock.json" }}
35
+ - node-v1-{{ .Branch }}-
36
+ - node-v1-
37
+ - save_cache:
38
+ paths:
39
+ - ~/usr/local/lib/node_modules # location depends on npm version
40
+ key: node-v1-{{ .Branch }}-{{ checksum "package-lock.json" }}
41
+ - run:
42
+ name: Run tests
43
+ command: npm test
44
+
45
+ workflows:
46
+ # Below is the definition of your workflow.
47
+ # Inside the workflow, you provide the jobs you want to run, e.g this workflow runs the build-and-test job above.
48
+ # CircleCI will run this workflow on every commit.
49
+ # For more details on extending your workflow, see the configuration docs: https://circleci.com/docs/2.0/configuration-reference/#workflows
50
+ sample:
51
+ jobs:
52
+ - build-and-test
53
+ # For running simple node tests, you could optionally use the node/test job from the orb to replicate and replace the job above in fewer lines.
54
+ # - node/test
package/.env.sample CHANGED
@@ -71,7 +71,7 @@
71
71
 
72
72
  CHAT21_ENABLED=true
73
73
 
74
- CHAT21_ENGINE=native
74
+ CHAT21_ENGINE=mqtt
75
75
  #CHAT21_ENGINE=firebase
76
76
 
77
77
  # Native Chat Engine
@@ -0,0 +1,22 @@
1
+ name: Docker Image Community latest CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ push_to_registry:
11
+ name: Push Docker image to Docker Hub
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ name: Check out the repo
17
+ - uses: docker/build-push-action@v1
18
+ with:
19
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
20
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
21
+ repository: tiledesk/tiledesk-server
22
+ tags: latest
@@ -1,4 +1,4 @@
1
- name: Publish Docker image
1
+ name: Publish Docker Enterprise Tag image
2
2
 
3
3
  on:
4
4
  push:
@@ -0,0 +1,21 @@
1
+ name: Publish Docker Community image tags
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '**' # Push events to every tag including hierarchical tags like
7
+ jobs:
8
+
9
+ push_to_registry:
10
+ name: Push Docker image to Docker Hub
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Check out the repo
14
+ uses: actions/checkout@v2
15
+ - name: Push to Docker Hub
16
+ uses: docker/build-push-action@v1
17
+ with:
18
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
19
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
20
+ repository: tiledesk/tiledesk-server
21
+ tag_with_ref: true
@@ -1,4 +1,4 @@
1
- name: Docker Image CI
1
+ name: Docker Enterprise Latest Image CI
2
2
 
3
3
  on:
4
4
  push:
package/CHANGELOG.md CHANGED
@@ -1,3 +1,197 @@
1
+ # 2.2.3
2
+ - Email inboud fix (others disabled and inboudDomain variable fix and token query string encode fix)
3
+
4
+ # 2.2.2
5
+ - log fix
6
+
7
+ # 2.2.1
8
+ - log fix
9
+
10
+ # 2.2.0
11
+ - Cache circleci fix
12
+ - Added EMAIL_REPLY_ENABLED and EMAIL_INBOUND_DOMAIN env parameters.
13
+ - Added API_URL env variable TODO use wehbook url the same as API_URL if not differnet
14
+
15
+ # 2.1.42 (Compatible with tiledesk-dashboard 2.2.X)
16
+
17
+
18
+ - Added ticket_id sequence field to the request model
19
+ - Routing round robin fix (Also in 2.1.40.1)
20
+ - GLOBAL_SECRET env variable fix (Also in 2.1.40.4)
21
+ - Chatbot now support blocked_intent
22
+ - BugFix route request to another department with the same agents (Also in 2.1.40.1)
23
+ - Renamed the chatbot webhook payload field from faq to intent
24
+ - Updated tiledesk-chat-util to 0.8.21 (Also in 2.1.40.1)
25
+ - Removed request first_text replace new line with empty string (for ticketing)
26
+
27
+ - Fix login problem when email contains upper case char
28
+ - Removed answer field from the fulltext search of the faqs (2.1.40.3)
29
+
30
+ - Stripe fix for adding new agents (2.1.40.13)
31
+ - Added request delete endpoint by id (Also in 2.1.40.15)
32
+ - Campaigns direct and for group (Also in 2.1.40.16)
33
+
34
+ - Csv request export added tags (2.1.40.14)
35
+ - Changed request_id to the new standard: support-group-<project_id>-<uid>
36
+ - Added tag to the department model
37
+ - Bugfix first message with an image fix and touchText limited to 30 character or subject (2.1.40.3)
38
+ - Fix request create if department id is not correct
39
+ - MessageRoot endpoint also for group messages (Also in 2.1.40.16)
40
+ - c21 handler group mesages support (Also in 2.1.40.16)
41
+ - Added recipientFullname field to message model. Added save method to messageServive (Also in 2.1.40.16)
42
+ - ChatBot webhook fix when the webhook returns also attributes
43
+ - Messages export csv supported
44
+ - Request util to lookup id_project from request_id (2.1.40.24)
45
+
46
+ - Find user id from user email endpoint (also in 2.1.40.21)
47
+ - Inizialize enterprise modules before public modules
48
+ - Request Notification fix loading snapshot agents (also in 2.1.40.22)
49
+ - Config secret fix from env (also in 2.1.40.22)
50
+ - Lic ck for users (also in 2.1.40.26)
51
+ - Added s_ticketing_taking_01 trigger
52
+ - Added email template from project settings
53
+ - Faq pagination support
54
+ - For Ticketing send to the cc(s) the agent replies
55
+ - \agent now is hidden
56
+ - added \close faq
57
+ - \close now is hidden
58
+ - set custom role in custom auth using signInWithCustomToken
59
+ - Chat21 contacts find for agent logged with custom auth
60
+ - Added language field to faq_kb and used to specify the language for faq full-text query (default en)
61
+ - Added request priority field
62
+ - Concierge bot fix to reroute only for temp conversation without a bot. Race condition issue when you try manually route a request for example inside a chatbot webhook (Also in 2.1.40.31)
63
+ - Added webhook_enabled parameter to the faqService create method and test refactor
64
+ - Added SYNC_JOIN_LEAVE_GROUP_EVENT environment variable to enable sync between Chat21 (join and leave) and Tiledesk. Default is false. (Also in 2.1.40.32 )
65
+ - Added ALLOW_REOPEN_CHAT environment variable to reopen a chat if a user write after a chat is closed
66
+ - Used message.received instead message.create in the messageActionsInterceptor to fix race condition sometime occurs with \close message sent by the bot
67
+ - Please type your reply above this line Only if replyTo is specified
68
+ - Webhook origin header fix for webhook
69
+
70
+
71
+ ## Email inbound
72
+ - EmailService supports custom email config with custom SMTP server settings and custom from email
73
+ - Added Tiledesk customer header in the outbound email
74
+ - Added Message-ID and sender (message sender fullname) on the outbound email
75
+ - Added project object to sendRequestTranscript function
76
+ - Welcome label fix key
77
+ - Seamless source page fix
78
+
79
+ # 2.1.41
80
+ - remove duplicate request script with: 1619185894304-request-remove-duplicated-request-by-request_id--autosync.js
81
+ - requestNotification improvement not sending email with empty email field
82
+ - Enabled witb DISABLE_SEND_OFFLINE_EMAIL the seamless conversation with email
83
+ - signinWithCustomToken endpoint of the auth router now support id_project body parameter for jwt with generic https://www.tiledesk.com audience field (used by tiledesk-smtp-server)
84
+ - files download endpoint
85
+ - emailService added EMAIL_REPLY_TO parameter;
86
+ - Added email notification for new message and new request for email and form channel (ticket)
87
+ - Added microLanguageTransformationInterceptor enabled when message.attributes.microlanguage==true
88
+
89
+
90
+ # 2.1.40.34 -> PROD
91
+ - logfix
92
+
93
+ # 2.1.40.33
94
+
95
+ - Added setTimeout to resolve race condition for \close event returned by bot
96
+
97
+ # 2.1.40.32
98
+ - Added SYNC_JOIN_LEAVE_GROUP_EVENT environment variable to enable sync between Chat21 (join and leave) and Tiledesk. Default is false.
99
+
100
+ # 2.1.40.31
101
+ - Concierge bot fix to reroute only for temp conversation without a bot. Race condition issue when you try manually route a request for example inside a chatbot webhook
102
+
103
+ # 2.1.40.30 -> PROD
104
+ - logfix
105
+
106
+ # 2.1.40.29
107
+ - --production for npm install within Docker for Enterprise
108
+
109
+ # 2.1.40.28
110
+ - --production for npm install within Docker
111
+
112
+ # 2.1.40.27
113
+ - Added language field to faq_kb and used to specify the language for faq full-text query
114
+
115
+ # 2.1.40.26
116
+ - Lic ck bug fix for users
117
+
118
+ # 2.1.40.25
119
+ - microLanguageTransformerInterceptor startup error. It is disabled. Module not present
120
+
121
+ # 2.1.40.24
122
+ - emailService toJSON is not a function fix
123
+
124
+ # 2.1.40.23
125
+ - requestNotification fix and requestUtilRoot lookup endpoint added
126
+
127
+ # 2.1.40.22
128
+ - Inizialize enterprise modules before public modules
129
+ - Request Notification fix loading snapshot agents
130
+
131
+ # 2.1.40.21
132
+ - Find user id from user email endpoint
133
+
134
+ # 2.1.40.20
135
+ - MessageRoot endpoint validation fix
136
+
137
+ # 2.1.40.19
138
+ - Stripe fix with version 1.1.5
139
+
140
+ # 2.1.40.18
141
+ - Messages export csv supported
142
+
143
+ # 2.1.40.17
144
+ - Stripe restored to the previous version 1.1.3
145
+
146
+ # 2.1.40.16
147
+ - added message recipientfullname field to the message entity to support chat campaigns for direct and group
148
+
149
+ # 2.1.40.15
150
+ - tag fix
151
+
152
+ # 2.1.40.14
153
+ - requet CSV export fix
154
+
155
+ # 2.1.40.13
156
+ - Stripe fix for adding new agents
157
+
158
+ # 2.1.40.12
159
+ - Docker image number fix
160
+
161
+ # 2.1.40.11
162
+ - Docker image number fix
163
+
164
+ # 2.1.40.10
165
+ - Docker image number fix
166
+
167
+ # 2.1.40.9
168
+ - Added request delete endpoint by id
169
+
170
+ # 2.1.40.7
171
+ - logfix
172
+
173
+ # 2.1.40.6
174
+ - Fix request create if department id is not correct
175
+
176
+ # 2.1.40.5
177
+ - Logfix
178
+
179
+ # 2.1.40.4
180
+ - GLOBAL_SECRET env variable fix
181
+
182
+ # 2.1.40.3
183
+ - Bugfix first message with an image fix and touchText limited to 30 character or subject
184
+ - Removed answer field from the fulltext search of the faqs
185
+
186
+
187
+ # 2.1.40.2
188
+ - log fix
189
+
190
+ # 2.1.40.1
191
+ - Routing round robin fix
192
+ - Updated tiledesk-chat-util to 0.8.21
193
+ - BugFix route request to another department with the same agents
194
+
1
195
 
2
196
  # 2.1.40
3
197
  - webhook fix for return empty body
@@ -171,7 +365,7 @@ Added email notification setting for each teammate (also in 2.1.14.3)
171
365
  - Fix TD218 Audit log for user invitation already registered
172
366
 
173
367
  # 2.1.12
174
- - Chat21 engine selection with CHAT21_ENGINE=[native|firebase]
368
+ - Chat21 engine selection with CHAT21_ENGINE=[mqtt|firebase]
175
369
  - Schema migration tool with mongoose-migrate. Added env property DISABLE_AUTO_SHEMA_MIGRATION
176
370
  - #TD-250 Added emoji callout
177
371
  - Cors fix. Removed alternative cors response header.
package/Dockerfile CHANGED
@@ -18,7 +18,7 @@ RUN if [ "$NPM_TOKEN" ]; \
18
18
  # where available (npm@5+)
19
19
  COPY package*.json ./
20
20
 
21
- RUN npm install
21
+ RUN npm install --production
22
22
 
23
23
  RUN rm -f .npmrc
24
24
 
package/Dockerfile-en CHANGED
@@ -13,7 +13,7 @@ COPY .npmrc_ .npmrc
13
13
  # where available (npm@5+)
14
14
  COPY package*.json ./
15
15
 
16
- RUN npm install
16
+ RUN npm install --production
17
17
 
18
18
  RUN rm -f .npmrc
19
19
 
package/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  [![npm version](https://badge.fury.io/js/%40tiledesk%2Ftiledesk-server.svg)](https://badge.fury.io/js/%40tiledesk%2Ftiledesk-server)
2
2
 
3
- [![Build Status](https://travis-ci.org/Tiledesk/tiledesk-server.svg)](https://travis-ci.org/Tiledesk/tiledesk-server)
3
+ [![CircleCI](https://circleci.com/gh/Tiledesk/tiledesk-server.svg?style=svg)](https://circleci.com/gh/Tiledesk/tiledesk-server)
4
4
 
5
5
 
6
+ > ***🚀 Do you want to install Tiledesk on your server with just one click?***
7
+ >
8
+ > ***Use [Docker Compose Tiledesk installation](https://github.com/Tiledesk/tiledesk-deployment/blob/master/docker-compose/README.md) guide***
9
+
6
10
  # Introduction
7
11
 
8
12
  Tiledesk-server is the server engine of Tiledesk. Tiledesk is an Open Source Live Chat platform with integrated ChatBot written in NodeJs and Express. Build your own customer support with a multi-channel platform for Web, Android and iOS. More info here https://www.tiledesk.com.
@@ -81,9 +85,3 @@ To see how to upgrade tiledesk-server see [here](./docs/upgrading.md)
81
85
  # Testing
82
86
  Run unit test with `npm test` and integration test with `npm run test:int`
83
87
 
84
-
85
-
86
-
87
-
88
-
89
-
package/app.js CHANGED
@@ -99,6 +99,9 @@ var cacheUtil = require("./utils/cacheUtil");
99
99
  var images = require('./routes/images');
100
100
  var files = require('./routes/files');
101
101
  var campaigns = require('./routes/campaigns');
102
+ var logs = require('./routes/logs');
103
+ var requestUtilRoot = require('./routes/requestUtilRoot');
104
+ var urls = require('./routes/urls');
102
105
 
103
106
  var bootDataLoader = require('./services/bootDataLoader');
104
107
  var settingDataLoader = require('./services/settingDataLoader');
@@ -133,6 +136,11 @@ try {
133
136
  }
134
137
 
135
138
 
139
+ //enterprise modules can modify pubmodule
140
+ modulesManager.start();
141
+
142
+ pubModulesManager.start();
143
+
136
144
 
137
145
  settingDataLoader.save();
138
146
  schemaMigrationService.checkSchemaMigration();
@@ -281,7 +289,11 @@ app.use('/testauth', [passport.authenticate(['basic', 'jwt'], { session: false }
281
289
  app.use('/widgets', widgetsLoader);
282
290
  app.use('/images', images);
283
291
  app.use('/files', files);
292
+ app.use('/urls', urls);
284
293
  app.use('/users', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], users);
294
+ app.use('/logs', logs);
295
+ app.use('/requests_util', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], requestUtilRoot);
296
+
285
297
 
286
298
  // TODO security issues
287
299
  if (process.env.DISABLE_TRANSCRIPT_VIEW_PAGE ) {
@@ -310,7 +322,6 @@ app.use('/:projectid/', [projectIdSetter, projectSetter]);
310
322
  app.use('/:projectid/authtestWithRoleCheck', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], authtestWithRoleCheck);
311
323
 
312
324
  app.use('/:projectid/leads', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent', ['bot','subscription'])], lead);
313
- // guest perche nn c'è guest???? no???
314
325
  app.use('/:projectid/requests/:request_id/messages', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes(null, ['bot','subscription'])] , message);
315
326
 
316
327
  app.use('/:projectid/messages', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent', ['bot','subscription'])] , messagesRootRoute);
@@ -43,7 +43,7 @@ class ChannelManager {
43
43
  var firebaseAuth = require('../channels/chat21/firebaseauth');
44
44
  app.use('/chat21/firebase/auth', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], firebaseAuth);
45
45
  } else { //if (engine && engine=="native") {
46
- winston.info("ChannelManager - Chat21 channel engine is native");
46
+ winston.info("ChannelManager - Chat21 channel engine is native mqtt");
47
47
  var nativeAuth = require('../channels/chat21/nativeauth');
48
48
  app.use('/chat21/native/auth', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], nativeAuth);
49
49
  }
@@ -17,12 +17,22 @@ const { Query } = require('mongoose');
17
17
 
18
18
  router.get('/:contact_id', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], async (req, res) => {
19
19
  winston.debug('REQ USER ID ', req.user._id);
20
-
21
- var contact_id = req.params.contact_id;
22
- winston.debug('contact_id: '+ contact_id);
23
20
 
21
+ var isObjectId = mongoose.Types.ObjectId.isValid(req.user._id);
22
+ winston.debug("isObjectId:"+ isObjectId);
23
+
24
+ var query = { role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT]}, status: "active" };
25
+ winston.debug(' query: ',query);
26
+
24
27
 
25
- var projects = await Project_user.find({ id_user: req.user._id , role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT]}, status: "active" }).
28
+ if (isObjectId) {
29
+ query.id_user = req.user._id;
30
+ // query.id_user = mongoose.Types.ObjectId(contact_id);
31
+ } else {
32
+ query.uuid_user = req.user._id;
33
+ }
34
+
35
+ var projects = await Project_user.find(query).
26
36
  exec();
27
37
 
28
38
  var projectsArray = [];
@@ -32,16 +42,19 @@ router.get('/:contact_id', [passport.authenticate(['basic', 'jwt'], { session: f
32
42
  });
33
43
 
34
44
 
35
- var isObjectId = mongoose.Types.ObjectId.isValid(contact_id);
45
+ var contact_id = req.params.contact_id;
46
+ winston.debug('contact_id: '+ contact_id);
47
+
48
+ isObjectId = mongoose.Types.ObjectId.isValid(contact_id);
36
49
  winston.debug("isObjectId:"+ isObjectId);
37
50
 
38
- var query = { id_project: { $in : projectsArray }, role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT]}, status: "active" };
51
+ query = { id_project: { $in : projectsArray }, role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT]}, status: "active" };
39
52
  winston.debug(' query: ',query);
40
53
 
41
54
  if (isObjectId) {
42
55
  query.id_user = contact_id;
43
56
  // query.id_user = mongoose.Types.ObjectId(contact_id);
44
- }else {
57
+ } else {
45
58
  query.uuid_user = contact_id;
46
59
  }
47
60
 
@@ -130,8 +143,21 @@ router.get('/', [passport.authenticate(['basic', 'jwt'], { session: false }), va
130
143
  var sortQuery={};
131
144
  sortQuery[sortField] = direction;
132
145
 
146
+ var query = { role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT]}, status: "active" };
147
+
148
+ var isObjectId = mongoose.Types.ObjectId.isValid(req.user._id);
149
+ winston.debug("isObjectId:"+ isObjectId);
150
+
151
+ if (isObjectId) {
152
+ query.id_user = req.user._id;
153
+ // query.id_user = mongoose.Types.ObjectId(contact_id);
154
+ } else {
155
+ query.uuid_user = req.user._id;
156
+ }
157
+
158
+
133
159
 
134
- var projects = await Project_user.find({ id_user: req.user._id , role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT]}, status: "active" }).
160
+ var projects = await Project_user.find(query).
135
161
  exec();
136
162
 
137
163
  var projectsArray = [];
@@ -189,7 +189,7 @@ class Chat21Handler {
189
189
  setImmediate(() => {
190
190
  winston.debug("Chat21Handler on lead.update ", lead);
191
191
 
192
- // AGGIORNA SOLO SE PASSA DA GUEST A ALTRO??
192
+ // TODO AGGIORNA SOLO SE PASSA DA GUEST A ALTRO??
193
193
  Request.find({lead: lead._id, id_project: lead.id_project}, function(err, requests) {
194
194
 
195
195
  if (err) {
@@ -364,10 +364,10 @@ class Chat21Handler {
364
364
  // winston.warn("Chat21Sender this is a direct message. Unimplemented method", message);
365
365
 
366
366
  chat21.auth.setAdminToken(adminToken);
367
-
367
+
368
368
  // send: function(sender_fullname, recipient_id, recipient_fullname, text, sender_id, attributes, type, metadata){
369
369
  return chat21.messages.send(message.senderFullname, message.recipient,
370
- "recipient_fullname", message.text, message.sender, message.attributes, message.type, message.metadata)
370
+ message.recipientFullname, message.text, message.sender, message.attributes, message.type, message.metadata)
371
371
  .then(function(data){
372
372
  winston.verbose("Chat21Sender send sent: "+ JSON.stringify(data));
373
373
 
@@ -383,13 +383,54 @@ class Chat21Handler {
383
383
  });
384
384
 
385
385
  }).catch(function(err) {
386
- winston.error("Chat21 sendToGroup err", err);
386
+ winston.error("Chat21 send direct err", err);
387
387
  chat21Event.emit('message.sent.error', err);
388
388
  });
389
389
 
390
390
 
391
391
 
392
- } else {
392
+ }
393
+
394
+ else if (message &&
395
+ message.status === MessageConstants.CHAT_MESSAGE_STATUS.SENDING &&
396
+ message.channel_type == MessageConstants.CHANNEL_TYPE.GROUP &&
397
+ message.channel.name == ChannelConstants.CHAT21) {
398
+
399
+ // winston.warn("Chat21Sender this is a group message. Unimplemented method", message);
400
+
401
+ chat21.auth.setAdminToken(adminToken);
402
+
403
+ var timestamp = Date.now();
404
+ // var timestamp = undefined;
405
+ if (message.attributes && message.attributes.clienttimestamp) {
406
+ timestamp = message.attributes.clienttimestamp;
407
+ }
408
+
409
+
410
+ return chat21.messages.sendToGroup(message.senderFullname, message.recipient,
411
+ message.recipientFullname, message.text, message.sender, message.attributes, message.type, message.metadata, timestamp)
412
+ .then(function(data){
413
+ winston.verbose("Chat21Sender send sent: "+ JSON.stringify(data));
414
+
415
+
416
+ // chat21.conversations.stopTyping(message.recipient,message.sender);
417
+
418
+ chat21Event.emit('message.sent', data);
419
+
420
+ messageService.changeStatus(message._id, MessageConstants.CHAT_MESSAGE_STATUS.DELIVERED) .then(function(upMessage){
421
+ winston.debug("Chat21 message sent ", upMessage.toObject());
422
+ }).catch(function(err) {
423
+ winston.error("Error Chat21 message sent with id: "+message._id, err);
424
+ });
425
+
426
+ }).catch(function(err) {
427
+ winston.error("Chat21 sendToGroup err", err);
428
+ chat21Event.emit('message.sent.error', err);
429
+ });
430
+
431
+
432
+
433
+ } else {
393
434
  winston.error("Chat21Sender this is not a group o direct message", message);
394
435
  return;
395
436
  }
@@ -815,6 +856,8 @@ class Chat21Handler {
815
856
 
816
857
  return chat21.groups.create(group.name, groupMembers, undefined, group_id).then(function(data) {
817
858
  winston.verbose("Chat21 group created: " + JSON.stringify(data));
859
+ // TODO ritorna success anche se
860
+ // verbose: Chat21 group created: {"success":false,"err":{"message":"Channel closed","stack":"IllegalOperationError: Channel closed\n at ConfirmChannel.<anonymous> (/usr/src/app/node_modules/amqplib/lib/channel.js:160:11)\n at ConfirmChannel.Channel.publish (/usr/src/app/node_modules/amqplib/lib/callback_model.js:171:17)\n at ConfirmChannel.publish (/usr/src/app/node_modules/amqplib/lib/callback_model.js:301:36)\n at Chat21Api.publish (/usr/src/app/chat21Api/index.js:1028:29)\n at Chat21Api.sendMessageRaw (/usr/src/app/chat21Api/index.js:762:14)\n at Chat21Api.sendGroupWelcomeMessage (/usr/src/app/chat21Api/index.js:205:14)\n at /usr/src/app/chat21Api/index.js:99:22\n at /usr/src/app/chat21Api/index.js:234:17\n at /usr/src/app/chatdb/index.js:77:9\n at executeCallback (/usr/src/app/node_modules/mongodb/lib/operations/execute_operation.js:70:5)\n at updateCallback (/usr/src/app/node_modules/mongodb/lib/operations/update_one.js:41:3)\n at /usr/src/app/node_modules/mongodb/lib/operations/update_one.js:24:64\n at handleCallback (/usr/src/app/node_modules/mongodb/lib/utils.js:128:55)\n at /usr/src/app/node_modules/mongodb/lib/operations/common_functions.js:378:5\n at handler (/usr/src/app/node_modules/mongodb/lib/core/sdam/topology.js:913:24)","stackAtStateChange":"Stack capture: Socket error\n at Connection.C.onSocketError (/usr/src/app/node_modules/amqplib/lib/connection.js:354:13)\n at Connection.emit (events.js:314:20)\n at Socket.go (/usr/src/app/node_modules/amqplib/lib/connection.js:481:12)\n at Socket.emit (events.js:314:20)\n at emitReadable_ (_stream_readable.js:557:12)\n at processTicksAndRejections (internal/process/task_queues.js:83:21)"}}
818
861
  chat21Event.emit('group.create', data);
819
862
  }).catch(function(err) {
820
863
  winston.error("Error creating chat21 group ", err);