import type { INpsVote } from '@rocket.chat/core-typings'; import { serverFetch as fetch } from '@rocket.chat/server-fetch'; import { getWorkspaceAccessToken } from '../../lib/cloud'; import { SystemLogger } from '../../lib/logger/system'; import { settings } from '../../settings'; type NPSResultPayload = { total: number; votes: Pick[]; }; export const sendNpsResults = async function sendNpsResults(npsId: string, data: NPSResultPayload) { const token = await getWorkspaceAccessToken(); if (!token) { return false; } const npsUrl = settings.get('Nps_Url'); try { return ( await fetch(`${npsUrl}/v1/surveys/${npsId}/results`, { method: 'POST', headers: { Authorization: `Bearer ${token}`, }, body: data, // SECURITY: URL can only be configured by users with enough privileges. It's ok to disable this check here. ignoreSsrfValidation: true, }) ).json(); } catch (err) { SystemLogger.error({ err }); return false; } };