diff --git a/server/source/config.ts b/server/source/config.ts index d601f4b4e..bef5cf569 100644 --- a/server/source/config.ts +++ b/server/source/config.ts @@ -1,11 +1,15 @@ import type { MattermostSendMessage } from './mattermost.js' if (!process.env.MONGO_URL) { - throw new Error('MONGO_URL env var is empty') + throw new Error('Empty MONGO_URL env var') } -if (!process.env.CLIENT_ID || !process.env.CLIENT_SECRET) { - throw new Error('Empty env var CLIENT_ID or CLIENT_SECRET') +if (!process.env.CLIENT_ID) { + throw new Error('Empty CLIENT_ID env var') +} + +if (!process.env.CLIENT_SECRET) { + throw new Error('Empty CLIENT_SECRET env var') } export const PORT = process.env.PORT || 4000 diff --git a/server/source/functions/send-crisp-message.ts b/server/source/functions/send-crisp-message.ts index 68a51b916..8fa32fe3b 100644 --- a/server/source/functions/send-crisp-message.ts +++ b/server/source/functions/send-crisp-message.ts @@ -1,5 +1,19 @@ import Crisp from 'crisp-api' +const CRISP_API_IDENTIFIER = process.env.CRISP_API_IDENTIFIER +const CRISP_API_KEY = process.env.CRISP_API_KEY +const WEBSITE_ID = process.env.CRISP_WEBSITE_ID + +if (!CRISP_API_IDENTIFIER) { + throw new Error('Empty CRISP_API_IDENTIFIER env var') +} +if (!CRISP_API_KEY) { + throw new Error('Empty CRISP_API_KEY env var') +} +if (!WEBSITE_ID) { + throw new Error('Empty WEBSITE_ID env var') +} + export type BodyType = { subject: string message: string @@ -48,13 +62,7 @@ export const sendCrispMessage = async (body: BodyType) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-call const CrispClient = new Crisp() as unknown as CrispType - CrispClient.authenticateTier( - 'plugin', - process.env.CRISP_API_IDENTIFIER, - process.env.CRISP_API_KEY - ) - - const WEBSITE_ID = process.env.CRISP_WEBSITE_ID as string + CrispClient.authenticateTier('plugin', CRISP_API_IDENTIFIER, CRISP_API_KEY) const result = await CrispClient.website.createNewConversation(WEBSITE_ID)