Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unknown contacts #32865

Merged
merged 105 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
40312b9
feat: create contact entity
tapiarafael Jun 27, 2024
668d934
feat: add create contact endpoint
tapiarafael Jun 27, 2024
de25810
add deprecation message to old endpoint
tapiarafael Jun 27, 2024
74c9ed8
remove unused file
tapiarafael Jun 27, 2024
ae70c00
fix: typo in prop
tapiarafael Jun 27, 2024
20c3892
test: implement contact tests
tapiarafael Jun 27, 2024
7e8dfa3
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jun 27, 2024
da25a9c
Create sixty-spoons-own.md
tapiarafael Jun 27, 2024
b7e0bf7
Update sixty-spoons-own.md
tapiarafael Jun 28, 2024
675bb12
Update .changeset/sixty-spoons-own.md
tapiarafael Jul 2, 2024
c59c4c2
test: include custom fields validations
tapiarafael Jul 2, 2024
e13f736
test: ensure body is being validated
tapiarafael Jul 2, 2024
e329740
test: ensure error message is equal the expected
tapiarafael Jul 2, 2024
4b74679
test: ensure that it is possible to create contact with contact manag…
tapiarafael Jul 2, 2024
8b1a303
feat: create new permission
tapiarafael Jul 2, 2024
3d26650
fix: replace MeteorError to Error
tapiarafael Jul 3, 2024
36b5021
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 3, 2024
9fe155c
refactor: deprecate old endpoint
tapiarafael Jul 3, 2024
8e7da69
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 3, 2024
35bc941
fix: remove migration
tapiarafael Jul 4, 2024
9813b26
feat: implement update contact endpoint
tapiarafael Jul 5, 2024
1549a4e
Create heavy-snails-help.md
tapiarafael Jul 5, 2024
e7b6048
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 5, 2024
fc24f66
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 9, 2024
6c908af
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 9, 2024
a5c7ec5
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 9, 2024
b4c2686
test: additional fields
tapiarafael Jul 9, 2024
af05b31
test: create agent to test
tapiarafael Jul 9, 2024
06a656e
test: restore setting to the original value
tapiarafael Jul 9, 2024
d61e15e
fix: set `phones` as required property
tapiarafael Jul 9, 2024
167da1a
refactor: breaks `validateCustomFields` into two functions
tapiarafael Jul 9, 2024
3a08e05
test: ensure that custom fields are properly validated
tapiarafael Jul 9, 2024
716162c
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 9, 2024
d1927ed
Update .changeset/heavy-snails-help.md
tapiarafael Jul 9, 2024
63a4c63
Update apps/meteor/tests/end-to-end/api/livechat/contacts.ts
tapiarafael Jul 9, 2024
bdf60f3
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 9, 2024
56b36c4
test: create agent to test
tapiarafael Jul 9, 2024
f602e92
refactor: pass the user to check if is valid manager
tapiarafael Jul 9, 2024
c7cf819
test: ensure that contact manager is properly validated
tapiarafael Jul 9, 2024
422943d
refactor: extract update to a proper method
tapiarafael Jul 9, 2024
37bdda6
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 9, 2024
7022d3b
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 9, 2024
438c697
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 9, 2024
cb9a598
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 9, 2024
8c3a68f
Update .changeset/sixty-spoons-own.md
tapiarafael Jul 10, 2024
80172f9
Update apps/meteor/app/livechat/server/lib/Contacts.ts
tapiarafael Jul 10, 2024
0d0d016
fix: use correct method to deprecation
tapiarafael Jul 10, 2024
3bba59f
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 10, 2024
87316ca
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 10, 2024
cf6da0c
fix: type of IUser
tapiarafael Jul 10, 2024
2cb7fcd
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 12, 2024
92c220b
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 12, 2024
8ebf18a
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 15, 2024
a8a4071
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 15, 2024
ef56b06
fix: find only agents
tapiarafael Jul 16, 2024
307661a
Update apps/meteor/app/livechat/server/api/v1/contact.ts
tapiarafael Jul 16, 2024
51b9d0b
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 16, 2024
ba6a59e
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 16, 2024
6cbc007
test: remove test since it never happen
tapiarafael Jul 16, 2024
98b50bc
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 16, 2024
d08fe10
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 16, 2024
e07090a
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 16, 2024
c1633e6
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 17, 2024
c4a50c1
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 18, 2024
5b8fec0
refactor: turn fields to optional to be able to create a unknown contact
tapiarafael Jul 23, 2024
168a943
feat: create an unknown contact for a new visitor
tapiarafael Jul 23, 2024
e218fb1
fix: always create unknown contact
tapiarafael Jul 29, 2024
a9bf6e0
test: ensure that a contact is created
tapiarafael Jul 29, 2024
39fffda
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Jul 29, 2024
46145de
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Jul 29, 2024
6476483
Merge branch 'feat/update-contact-endpoint' into feat/unknown-contacts
tapiarafael Jul 29, 2024
a5483d5
Merge branch 'develop' into feat/create-contact-endpoint
tapiarafael Aug 8, 2024
b285d39
Merge branch 'feat/create-contact-endpoint' into feat/update-contact-…
tapiarafael Aug 8, 2024
53550c7
Merge branch 'feat/update-contact-endpoint' into feat/unknown-contacts
tapiarafael Aug 8, 2024
ff1c391
Merge branch 'develop' into feat/update-contact-endpoint
tapiarafael Aug 23, 2024
33dace9
Merge branch 'develop' into feat/update-contact-endpoint
tapiarafael Aug 26, 2024
af787ea
Merge branch 'feat/update-contact-endpoint' into feat/unknown-contacts
tapiarafael Aug 27, 2024
3c87d58
feat: add translation for new permissions
tapiarafael Aug 28, 2024
a4d84fe
refactor: extract contact manager validation to a function
tapiarafael Aug 28, 2024
504c4ec
refactor: use findOneAndUpdate instead
tapiarafael Aug 28, 2024
0babebc
fix: set unknown to false when contact is updated
tapiarafael Aug 28, 2024
cb5d963
refactor: get only the id to check if user exists
tapiarafael Aug 28, 2024
1fea4e2
fix: throw an error if additional custom fields are provided
tapiarafael Aug 28, 2024
0cc0e83
test: mock user repository
tapiarafael Aug 28, 2024
32cb0a6
test: add updateContact unit tests
tapiarafael Aug 28, 2024
c3bfd27
Merge branch 'develop' into feat/update-contact-endpoint
tapiarafael Aug 28, 2024
c903de9
fix: make name not nullable
tapiarafael Aug 29, 2024
f54dc84
test: admin already has the permission by default
tapiarafael Aug 29, 2024
a23a9e0
test: use after/before to set permissions
tapiarafael Aug 29, 2024
67f25b3
chore: improve description
tapiarafael Aug 29, 2024
559340c
Merge branch 'develop' into feat/update-contact-endpoint
tapiarafael Aug 29, 2024
d1858ad
Merge branch 'develop' into feat/update-contact-endpoint
tapiarafael Sep 2, 2024
43187b5
Merge branch 'develop' into feat/update-contact-endpoint
tapiarafael Sep 2, 2024
59ca71e
Merge branch 'feat/update-contact-endpoint' into feat/unknown-contacts
tapiarafael Sep 2, 2024
726414e
Update .changeset/heavy-snails-help.md
tapiarafael Sep 2, 2024
b922e3d
fix: set the correct translation
tapiarafael Sep 2, 2024
39c5a02
Merge branch 'develop' into feat/update-contact-endpoint
tapiarafael Sep 2, 2024
4cbedd9
Merge branch 'feat/update-contact-endpoint' into feat/unknown-contacts
tapiarafael Sep 2, 2024
5f5ce4c
refactor: remove unused method
tapiarafael Sep 3, 2024
a35b097
Merge branch 'develop' into feat/unknown-contacts
tapiarafael Sep 3, 2024
58df14e
refactor: create contacts only in test mode
tapiarafael Sep 3, 2024
838b7af
fix: `test_mode` validation
tapiarafael Sep 3, 2024
5c47c35
Merge branch 'develop' into feat/unknown-contacts
kodiakhq[bot] Sep 6, 2024
01d3c60
Merge branch 'develop' into feat/unknown-contacts
tapiarafael Sep 6, 2024
9b45119
Merge branch 'develop' into feat/unknown-contacts
tapiarafael Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/server/api/v1/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ API.v1.addRoute(
{ authRequired: true, permissionsRequired: ['create-livechat-contact'], validateParams: isPOSTOmnichannelContactsProps },
{
async post() {
if (!process.env.TEST_MODE) {
if (process.env.TEST_MODE?.toUpperCase() !== 'TRUE') {
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
throw new Meteor.Error('error-not-allowed', 'This endpoint is only allowed in test mode');
}
const contactId = await createContact({ ...this.bodyParams, unknown: false });
Expand All @@ -106,7 +106,7 @@ API.v1.addRoute(
{ authRequired: true, permissionsRequired: ['update-livechat-contact'], validateParams: isPOSTUpdateOmnichannelContactsProps },
{
async post() {
if (!process.env.TEST_MODE) {
if (process.env.TEST_MODE?.toUpperCase() !== 'TRUE') {
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
throw new Meteor.Error('error-not-allowed', 'This endpoint is only allowed in test mode');
}

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/server/lib/Contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type RegisterContactProps = {

type CreateContactParams = {
name: string;
emails: string[];
phones: string[];
emails?: string[];
phones?: string[];
unknown: boolean;
customFields?: Record<string, string | unknown>;
contactManager?: string;
Expand Down
11 changes: 11 additions & 0 deletions apps/meteor/app/livechat/server/lib/LivechatTyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import * as Mailer from '../../../mailer/server/api';
import { metrics } from '../../../metrics/server';
import { settings } from '../../../settings/server';
import { businessHourManager } from '../business-hour';
import { createContact } from './Contacts';
import { parseAgentCustomFields, updateDepartmentAgents, validateEmail, normalizeTransferredByData } from './Helper';
import { QueueManager } from './QueueManager';
import { RoutingManager } from './RoutingManager';
Expand Down Expand Up @@ -664,6 +665,16 @@ class LivechatClass {
}
}

if (process.env.TEST_MODE?.toUpperCase() === 'TRUE') {
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
const contactId = await createContact({
name: name ?? (visitorDataToUpdate.username as string),
emails: email ? [email] : [],
phones: phone ? [phone.number] : [],
unknown: true,
});
visitorDataToUpdate.contactId = contactId;
}

const upsertedLivechatVisitor = await LivechatVisitors.updateOneByIdOrToken(visitorDataToUpdate, {
upsert: true,
returnDocument: 'after',
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('LIVECHAT - visitors', () => {
expect(body).to.have.property('success', true);
expect(body).to.have.property('visitor');
expect(body.visitor).to.have.property('token', 'test');
expect(body.visitor).to.have.property('contactId');

// Ensure all new visitors are created as online :)
expect(body.visitor).to.have.property('status', 'online');
Expand Down
4 changes: 2 additions & 2 deletions packages/core-typings/src/ILivechatContact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export interface ILivechatContactConflictingField {

export interface ILivechatContact extends IRocketChatRecord {
name: string;
phones: string[];
emails: string[];
phones?: string[];
emails?: string[];
contactManager?: string;
unknown?: boolean;
hasConflict?: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/core-typings/src/ILivechatVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface ILivechatVisitor extends IRocketChatRecord {
};
activity?: string[];
disabled?: boolean;
contactId?: string;
}

export interface ILivechatVisitorDTO {
Expand Down
Loading