Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
96 lines
2.4 KiB
TypeScript
96 lines
2.4 KiB
TypeScript
import { Logger } from '@rocket.chat/logger';
|
|
import type { ExtendedFetchOptions } from '@rocket.chat/server-fetch';
|
|
import { serverFetch as fetch } from '@rocket.chat/server-fetch';
|
|
|
|
import { API } from '../..';
|
|
import { settings } from '../../../settings';
|
|
|
|
const logger = new Logger('WebhookTest');
|
|
|
|
API.v1.addRoute(
|
|
'livechat/webhook.test',
|
|
{ authRequired: true, permissionsRequired: ['view-livechat-webhooks'] },
|
|
{
|
|
async post() {
|
|
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<string>('Livechat_secret_token'),
|
|
'Accept': 'application/json',
|
|
},
|
|
body: sampleData,
|
|
// SECURITY: Webhooks can only be configured by users with enough privileges. It's ok to disable this check here.
|
|
ignoreSsrfValidation: true,
|
|
size: 10 * 1024 * 1024,
|
|
} as ExtendedFetchOptions;
|
|
|
|
const webhookUrl = settings.get<string>('Livechat_webhookUrl');
|
|
|
|
if (!webhookUrl) {
|
|
return API.v1.failure('Webhook_URL_not_set');
|
|
}
|
|
|
|
try {
|
|
logger.debug({ msg: 'Testing webhook', webhookUrl });
|
|
const request = await fetch(webhookUrl, options);
|
|
const response = await request.text();
|
|
|
|
logger.debug({ msg: 'Webhook response', response });
|
|
if (request.status === 200) {
|
|
return API.v1.success();
|
|
}
|
|
|
|
throw new Error('Invalid status code');
|
|
} catch (error) {
|
|
logger.error({ msg: 'Error testing webhook', err: error });
|
|
throw new Error('error-invalid-webhook-response');
|
|
}
|
|
},
|
|
},
|
|
);
|