From 0ece4450fdcfa7144eb64351bdec09a4a81d047f Mon Sep 17 00:00:00 2001 From: Abhinav Kumar Date: Thu, 10 Oct 2024 01:32:51 +0530 Subject: [PATCH] chore!: remove deprecated method livechat:webhookTest (#33449) --- .changeset/forty-actors-care.md | 5 + apps/meteor/app/livechat/server/index.ts | 1 - .../livechat/server/methods/webhookTest.ts | 93 ------------------- 3 files changed, 5 insertions(+), 94 deletions(-) create mode 100644 .changeset/forty-actors-care.md delete mode 100644 apps/meteor/app/livechat/server/methods/webhookTest.ts diff --git a/.changeset/forty-actors-care.md b/.changeset/forty-actors-care.md new file mode 100644 index 000000000000..2420d1603114 --- /dev/null +++ b/.changeset/forty-actors-care.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': major +--- + +Removes deprecated method `livechat:webhookTest`. Moving forward use the endpoint `livechat/webhook.test`. diff --git a/apps/meteor/app/livechat/server/index.ts b/apps/meteor/app/livechat/server/index.ts index 70d756cbc6ef..1f943523a3f5 100644 --- a/apps/meteor/app/livechat/server/index.ts +++ b/apps/meteor/app/livechat/server/index.ts @@ -45,7 +45,6 @@ import './methods/sendFileLivechatMessage'; import './methods/setCustomField'; import './methods/setDepartmentForVisitor'; import './methods/transfer'; -import './methods/webhookTest'; import './methods/setUpConnection'; import './methods/takeInquiry'; import './methods/requestTranscript'; diff --git a/apps/meteor/app/livechat/server/methods/webhookTest.ts b/apps/meteor/app/livechat/server/methods/webhookTest.ts deleted file mode 100644 index 68800e1a0616..000000000000 --- a/apps/meteor/app/livechat/server/methods/webhookTest.ts +++ /dev/null @@ -1,93 +0,0 @@ -import type { ServerMethods } from '@rocket.chat/ddp-client'; -import { serverFetch as fetch } from '@rocket.chat/server-fetch'; -import { Meteor } from 'meteor/meteor'; - -import { SystemLogger } from '../../../../server/lib/logger/system'; -import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; -import { settings } from '../../../settings/server'; - -const postCatchError = async function (url: string, options?: Record | undefined) { - try { - return fetch(url, { ...options, method: 'POST' }); - } catch (e) { - return undefined; // TODO: should we return the error? - } -}; - -declare module '@rocket.chat/ddp-client' { - // eslint-disable-next-line @typescript-eslint/naming-convention - interface ServerMethods { - 'livechat:webhookTest'(): Promise; - } -} - -Meteor.methods({ - async 'livechat:webhookTest'() { - methodDeprecationLogger.method('livechat:webhookTest', '7.0.0'); - - const sampleData = { - type: 'LivechatSession', - _id: 'fasd6f5a4sd6f8a4sdf', - label: 'title', - topic: 'asiodojf', - createdAt: new Date(), - lastMessageAt: new Date(), - tags: ['tag1', 'tag2', 'tag3'], - customFields: { - productId: '123456', - }, - visitor: { - _id: '', - name: 'visitor name', - username: 'visitor-username', - department: 'department', - email: 'email@address.com', - phone: '192873192873', - ip: '123.456.7.89', - browser: 'Chrome', - os: 'Linux', - customFields: { - customerId: '123456', - }, - }, - agent: { - _id: 'asdf89as6df8', - username: 'agent.username', - name: 'Agent Name', - email: 'agent@email.com', - }, - messages: [ - { - username: 'visitor-username', - msg: 'message content', - ts: new Date(), - }, - { - username: 'agent.username', - agentId: 'asdf89as6df8', - msg: 'message content from agent', - ts: new Date(), - }, - ], - }; - - const options = { - method: 'POST', - headers: { - 'X-RocketChat-Livechat-Token': settings.get('Livechat_secret_token'), - 'Accept': 'application/json', - }, - body: sampleData, - }; - - const response = await postCatchError(settings.get('Livechat_webhookUrl'), options); - - SystemLogger.debug({ response: await response?.text() }); - - if (response?.ok) { - return true; - } - - throw new Meteor.Error('error-invalid-webhook-response'); - }, -});