Skip to content

Commit

Permalink
feat: unknown contacts (#32865)
Browse files Browse the repository at this point in the history
  • Loading branch information
tapiarafael committed Sep 9, 2024
1 parent e0050c3 commit 06dbf72
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
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') {
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') {
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') {
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

0 comments on commit 06dbf72

Please sign in to comment.