Skip to content

Commit

Permalink
chore!: remove deprecated livechat:setCustomField method (#33444)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavkrin authored and ggazzo committed Oct 11, 2024
1 parent 279d276 commit b980fbb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-vans-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': major
---

Removes deprecated method `livechat:setCustomField`. The custom fields can be directly set via the `livechat/visitor` endpoint.
11 changes: 6 additions & 5 deletions apps/meteor/app/livechat/imports/server/rest/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { API } from '../../../../api/server';
import { FileUpload } from '../../../../file-upload/server';
import { checkUrlForSsrf } from '../../../../lib/server/functions/checkUrlForSsrf';
import { settings } from '../../../../settings/server';
import { setCustomField } from '../../../server/api/lib/customFields';
import type { ILivechatMessage } from '../../../server/lib/LivechatTyped';
import { Livechat as LivechatTyped } from '../../../server/lib/LivechatTyped';

Expand Down Expand Up @@ -263,16 +264,16 @@ API.v1.addRoute('livechat/sms-incoming/:service', {
setImmediate(async () => {
if (sms.extra) {
if (sms.extra.fromCountry) {
await Meteor.callAsync('livechat:setCustomField', sendMessage.message.token, 'country', sms.extra.fromCountry);
await setCustomField(sendMessage.message.token, 'country', sms.extra.fromCountry);
}
if (sms.extra.fromState) {
await Meteor.callAsync('livechat:setCustomField', sendMessage.message.token, 'state', sms.extra.fromState);
await setCustomField(sendMessage.message.token, 'state', sms.extra.fromState);
}
if (sms.extra.fromCity) {
await Meteor.callAsync('livechat:setCustomField', sendMessage.message.token, 'city', sms.extra.fromCity);
await setCustomField(sendMessage.message.token, 'city', sms.extra.fromCity);
}
if (sms.extra.toPhone) {
await Meteor.callAsync('livechat:setCustomField', sendMessage.message.token, 'phoneNumber', sms.extra.toPhone);
if (sms.extra.fromZip) {
await setCustomField(sendMessage.message.token, 'zip', sms.extra.fromZip);
}
}
});
Expand Down
20 changes: 19 additions & 1 deletion apps/meteor/app/livechat/server/api/lib/customFields.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ILivechatCustomField } from '@rocket.chat/core-typings';
import { LivechatCustomField } from '@rocket.chat/models';
import { LivechatCustomField, LivechatVisitors, LivechatRooms } from '@rocket.chat/models';
import type { PaginatedResult } from '@rocket.chat/rest-typings';
import { escapeRegExp } from '@rocket.chat/string-helpers';
import type { UpdateResult, Document } from 'mongodb';

export async function findLivechatCustomFields({
text,
Expand Down Expand Up @@ -41,3 +42,20 @@ export async function findCustomFieldById({
customField: await LivechatCustomField.findOneById(customFieldId),
};
}

export async function setCustomField(
token: string,
key: string,
value: string,
overwrite = true,
): Promise<boolean | UpdateResult | Document> {
const customField = await LivechatCustomField.findOneById(key);
if (customField) {
if (customField.scope === 'room') {
return LivechatRooms.updateDataByToken(token, key, value, overwrite);
}
return LivechatVisitors.updateLivechatDataByToken(token, key, value, overwrite);
}

return true;
}
1 change: 0 additions & 1 deletion apps/meteor/app/livechat/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import './methods/saveIntegration';
import './methods/saveTrigger';
import './methods/sendMessageLivechat';
import './methods/sendFileLivechatMessage';
import './methods/setCustomField';
import './methods/setDepartmentForVisitor';
import './methods/transfer';
import './methods/setUpConnection';
Expand Down
30 changes: 0 additions & 30 deletions apps/meteor/app/livechat/server/methods/setCustomField.ts

This file was deleted.

0 comments on commit b980fbb

Please sign in to comment.