@tiledesk/tiledesk-server 2.1.41 → 2.2.4

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 (85) 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 +198 -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/chat21/chat21Contact.js +34 -8
  13. package/channels/chat21/chat21Handler.js +48 -5
  14. package/channels/chat21/chat21WebHook.js +34 -5
  15. package/channels/chat21/nativeauth.js +2 -2
  16. package/config/email.js +2 -1
  17. package/config/global.js +3 -0
  18. package/config/labels/widget.json +170 -16
  19. package/event/messageEvent.js +18 -1
  20. package/middleware/passport.js +10 -4
  21. package/models/actionsConstants.js +7 -0
  22. package/models/department.js +3 -0
  23. package/models/faq.js +8 -2
  24. package/models/faq_kb.js +6 -0
  25. package/models/message.js +10 -4
  26. package/models/messageConstants.js +3 -3
  27. package/models/request.js +33 -3
  28. package/package.json +31 -28
  29. package/pubmodules/emailNotification/requestNotification.js +380 -62
  30. package/pubmodules/messageActions/messageActionsInterceptor.js +20 -7
  31. package/pubmodules/messageTransformer/index.js +1 -1
  32. package/pubmodules/messageTransformer/microLanguageAttributesTransformerInterceptor.js +67 -0
  33. package/pubmodules/pubModulesManager.js +66 -14
  34. package/pubmodules/rules/conciergeBot.js +81 -49
  35. package/routes/auth.js +34 -10
  36. package/routes/campaigns.js +117 -25
  37. package/routes/faq.js +19 -0
  38. package/routes/faq_kb.js +13 -4
  39. package/routes/faqpub.js +1 -1
  40. package/routes/images.js +1 -1
  41. package/routes/jwt.js +0 -1
  42. package/routes/logs.js +26 -0
  43. package/routes/message.js +7 -2
  44. package/routes/messagesRoot.js +73 -16
  45. package/routes/project_user.js +36 -1
  46. package/routes/request.js +88 -12
  47. package/routes/requestUtilRoot.js +30 -0
  48. package/routes/urls.js +12 -0
  49. package/routes/users.js +5 -1
  50. package/services/BotSubscriptionNotifier.js +1 -0
  51. package/services/departmentService.js +29 -5
  52. package/services/emailService.js +1103 -298
  53. package/services/faqBotHandler.js +176 -61
  54. package/services/faqBotSupport.js +181 -117
  55. package/services/faqService.js +17 -14
  56. package/services/messageService.js +57 -9
  57. package/services/modulesManager.js +86 -23
  58. package/services/requestService.js +58 -17
  59. package/template/email/assignedEmailMessage.html +205 -0
  60. package/template/email/assignedRequest.html +44 -14
  61. package/template/email/beenInvitedExistingUser.html +2 -2
  62. package/template/email/beenInvitedNewUser.html +1 -1
  63. package/template/email/newMessage.html +31 -12
  64. package/template/email/passwordChanged.html +2 -3
  65. package/template/email/pooledEmailMessage.html +208 -0
  66. package/template/email/pooledRequest.html +41 -14
  67. package/template/email/resetPassword.html +2 -3
  68. package/template/email/sendTranscript.html +1 -1
  69. package/template/email/test.html +1 -1
  70. package/template/email/ticket.html +78 -52
  71. package/template/email/ticket.txt +5 -1
  72. package/template/email/verify.html +1 -1
  73. package/test/authentication.js +76 -4
  74. package/test/authenticationJwt.js +76 -2
  75. package/test/campaignsRoute.js +226 -0
  76. package/test/faqService.js +3 -3
  77. package/test/faqkbRoute.js +3 -2
  78. package/test/messageRootRoute.js +193 -0
  79. package/test/messageRoute.js +75 -0
  80. package/test/messageService.js +5 -5
  81. package/test/requestRoute.js +27 -9
  82. package/test/requestService.js +472 -11
  83. package/test-int/bot.js +673 -8
  84. package/websocket/webSocketServer.js +7 -4
  85. package/template/email/ticket-taking.txt +0 -7
@@ -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,200 @@
1
+ # 2.2.4
2
+ - email invitation fix
3
+
4
+ # 2.2.3
5
+ - Email inboud fix (others disabled and inboudDomain variable fix and token query string encode fix)
6
+
7
+ # 2.2.2
8
+ - log fix
9
+
10
+ # 2.2.1
11
+ - log fix
12
+
13
+ # 2.2.0
14
+ - Cache circleci fix
15
+ - Added EMAIL_REPLY_ENABLED and EMAIL_INBOUND_DOMAIN env parameters.
16
+ - Added API_URL env variable TODO use wehbook url the same as API_URL if not differnet
17
+
18
+ # 2.1.42 (Compatible with tiledesk-dashboard 2.2.X)
19
+
20
+
21
+ - Added ticket_id sequence field to the request model
22
+ - Routing round robin fix (Also in 2.1.40.1)
23
+ - GLOBAL_SECRET env variable fix (Also in 2.1.40.4)
24
+ - Chatbot now support blocked_intent
25
+ - BugFix route request to another department with the same agents (Also in 2.1.40.1)
26
+ - Renamed the chatbot webhook payload field from faq to intent
27
+ - Updated tiledesk-chat-util to 0.8.21 (Also in 2.1.40.1)
28
+ - Removed request first_text replace new line with empty string (for ticketing)
29
+
30
+ - Fix login problem when email contains upper case char
31
+ - Removed answer field from the fulltext search of the faqs (2.1.40.3)
32
+
33
+ - Stripe fix for adding new agents (2.1.40.13)
34
+ - Added request delete endpoint by id (Also in 2.1.40.15)
35
+ - Campaigns direct and for group (Also in 2.1.40.16)
36
+
37
+ - Csv request export added tags (2.1.40.14)
38
+ - Changed request_id to the new standard: support-group-<project_id>-<uid>
39
+ - Added tag to the department model
40
+ - Bugfix first message with an image fix and touchText limited to 30 character or subject (2.1.40.3)
41
+ - Fix request create if department id is not correct
42
+ - MessageRoot endpoint also for group messages (Also in 2.1.40.16)
43
+ - c21 handler group mesages support (Also in 2.1.40.16)
44
+ - Added recipientFullname field to message model. Added save method to messageServive (Also in 2.1.40.16)
45
+ - ChatBot webhook fix when the webhook returns also attributes
46
+ - Messages export csv supported
47
+ - Request util to lookup id_project from request_id (2.1.40.24)
48
+
49
+ - Find user id from user email endpoint (also in 2.1.40.21)
50
+ - Inizialize enterprise modules before public modules
51
+ - Request Notification fix loading snapshot agents (also in 2.1.40.22)
52
+ - Config secret fix from env (also in 2.1.40.22)
53
+ - Lic ck for users (also in 2.1.40.26)
54
+ - Added s_ticketing_taking_01 trigger
55
+ - Added email template from project settings
56
+ - Faq pagination support
57
+ - For Ticketing send to the cc(s) the agent replies
58
+ - \agent now is hidden
59
+ - added \close faq
60
+ - \close now is hidden
61
+ - set custom role in custom auth using signInWithCustomToken
62
+ - Chat21 contacts find for agent logged with custom auth
63
+ - Added language field to faq_kb and used to specify the language for faq full-text query (default en)
64
+ - Added request priority field
65
+ - 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)
66
+ - Added webhook_enabled parameter to the faqService create method and test refactor
67
+ - 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 )
68
+ - Added ALLOW_REOPEN_CHAT environment variable to reopen a chat if a user write after a chat is closed
69
+ - Used message.received instead message.create in the messageActionsInterceptor to fix race condition sometime occurs with \close message sent by the bot
70
+ - Please type your reply above this line Only if replyTo is specified
71
+ - Webhook origin header fix for webhook
72
+
73
+
74
+ ## Email inbound
75
+ - EmailService supports custom email config with custom SMTP server settings and custom from email
76
+ - Added Tiledesk customer header in the outbound email
77
+ - Added Message-ID and sender (message sender fullname) on the outbound email
78
+ - Added project object to sendRequestTranscript function
79
+ - Welcome label fix key
80
+ - Seamless source page fix
81
+
82
+ # 2.1.41
83
+ - remove duplicate request script with: 1619185894304-request-remove-duplicated-request-by-request_id--autosync.js
84
+ - requestNotification improvement not sending email with empty email field
85
+ - Enabled witb DISABLE_SEND_OFFLINE_EMAIL the seamless conversation with email
86
+ - 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)
87
+ - files download endpoint
88
+ - emailService added EMAIL_REPLY_TO parameter;
89
+ - Added email notification for new message and new request for email and form channel (ticket)
90
+ - Added microLanguageTransformationInterceptor enabled when message.attributes.microlanguage==true
91
+
92
+
93
+ # 2.1.40.34 -> PROD
94
+ - logfix
95
+
96
+ # 2.1.40.33
97
+
98
+ - Added setTimeout to resolve race condition for \close event returned by bot
99
+
100
+ # 2.1.40.32
101
+ - Added SYNC_JOIN_LEAVE_GROUP_EVENT environment variable to enable sync between Chat21 (join and leave) and Tiledesk. Default is false.
102
+
103
+ # 2.1.40.31
104
+ - 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
105
+
106
+ # 2.1.40.30 -> PROD
107
+ - logfix
108
+
109
+ # 2.1.40.29
110
+ - --production for npm install within Docker for Enterprise
111
+
112
+ # 2.1.40.28
113
+ - --production for npm install within Docker
114
+
115
+ # 2.1.40.27
116
+ - Added language field to faq_kb and used to specify the language for faq full-text query
117
+
118
+ # 2.1.40.26
119
+ - Lic ck bug fix for users
120
+
121
+ # 2.1.40.25
122
+ - microLanguageTransformerInterceptor startup error. It is disabled. Module not present
123
+
124
+ # 2.1.40.24
125
+ - emailService toJSON is not a function fix
126
+
127
+ # 2.1.40.23
128
+ - requestNotification fix and requestUtilRoot lookup endpoint added
129
+
130
+ # 2.1.40.22
131
+ - Inizialize enterprise modules before public modules
132
+ - Request Notification fix loading snapshot agents
133
+
134
+ # 2.1.40.21
135
+ - Find user id from user email endpoint
136
+
137
+ # 2.1.40.20
138
+ - MessageRoot endpoint validation fix
139
+
140
+ # 2.1.40.19
141
+ - Stripe fix with version 1.1.5
142
+
143
+ # 2.1.40.18
144
+ - Messages export csv supported
145
+
146
+ # 2.1.40.17
147
+ - Stripe restored to the previous version 1.1.3
148
+
149
+ # 2.1.40.16
150
+ - added message recipientfullname field to the message entity to support chat campaigns for direct and group
151
+
152
+ # 2.1.40.15
153
+ - tag fix
154
+
155
+ # 2.1.40.14
156
+ - requet CSV export fix
157
+
158
+ # 2.1.40.13
159
+ - Stripe fix for adding new agents
160
+
161
+ # 2.1.40.12
162
+ - Docker image number fix
163
+
164
+ # 2.1.40.11
165
+ - Docker image number fix
166
+
167
+ # 2.1.40.10
168
+ - Docker image number fix
169
+
170
+ # 2.1.40.9
171
+ - Added request delete endpoint by id
172
+
173
+ # 2.1.40.7
174
+ - logfix
175
+
176
+ # 2.1.40.6
177
+ - Fix request create if department id is not correct
178
+
179
+ # 2.1.40.5
180
+ - Logfix
181
+
182
+ # 2.1.40.4
183
+ - GLOBAL_SECRET env variable fix
184
+
185
+ # 2.1.40.3
186
+ - Bugfix first message with an image fix and touchText limited to 30 character or subject
187
+ - Removed answer field from the fulltext search of the faqs
188
+
189
+
190
+ # 2.1.40.2
191
+ - log fix
192
+
193
+ # 2.1.40.1
194
+ - Routing round robin fix
195
+ - Updated tiledesk-chat-util to 0.8.21
196
+ - BugFix route request to another department with the same agents
197
+
1
198
 
2
199
  # 2.1.40
3
200
  - webhook fix for return empty body
@@ -171,7 +368,7 @@ Added email notification setting for each teammate (also in 2.1.14.3)
171
368
  - Fix TD218 Audit log for user invitation already registered
172
369
 
173
370
  # 2.1.12
174
- - Chat21 engine selection with CHAT21_ENGINE=[native|firebase]
371
+ - Chat21 engine selection with CHAT21_ENGINE=[mqtt|firebase]
175
372
  - Schema migration tool with mongoose-migrate. Added env property DISABLE_AUTO_SHEMA_MIGRATION
176
373
  - #TD-250 Added emoji callout
177
374
  - 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);
@@ -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);