The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/server/services/nps/sendNpsResults.ts

35 lines
906 B

import type { INpsVote } from '@rocket.chat/core-typings';
import { serverFetch as fetch } from '@rocket.chat/server-fetch';
import { settings } from '../../../app/settings/server';
import { getWorkspaceAccessToken } from '../../../app/cloud/server';
import { SystemLogger } from '../../lib/logger/system';
type NPSResultPayload = {
total: number;
votes: Pick<INpsVote, 'identifier' | 'roles' | 'score' | 'comment'>[];
};
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,
})
).json();
} catch (e) {
SystemLogger.error(e);
return false;
}
};