Skip to content

Commit

Permalink
If we are in a production environment, send an email to the dev team …
Browse files Browse the repository at this point in the history
…instead of creating a support ticket
  • Loading branch information
tcaiger committed Oct 18, 2024
1 parent 3dcd3d5 commit eda57bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/central-server/src/utilities/createSupportTicket.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,31 @@
* Tupaia
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
import { fetchWithTimeout, requireEnv } from '@tupaia/utils';
import { fetchWithTimeout, getIsProductionEnvironment, requireEnv } from '@tupaia/utils';
import { sendEmail } from '@tupaia/server-utils';

const emailInternally = async (subject, message) => {
const sendTo = requireEnv('DEV_EMAIL_ADDRESS');
return sendEmail(sendTo, {
subject,
templateName: 'generic',
templateContext: {
userName: 'Tupaia Admin',
message,
},
});
};

export const createSupportTicket = async (subject, message) => {
try {
// If ZENDESK_NOTIFICATIONS_DISABLE is set to true, do not create a support ticket
// If ZENDESK_NOTIFICATIONS_DISABLE is set to true, do not create a support ticket
if (process.env.ZENDESK_NOTIFICATIONS_DISABLE === 'true') return;

if (process.env.ZENDESK_NOTIFICATIONS_DISABLE === 'true') return;
// If we are in a production environment, send an email to the dev team instead of creating a support ticket
if (getIsProductionEnvironment()) {
return emailInternally();
}

try {
const zendeskApi = requireEnv('ZENDESK_API_URL');
const apiToken = requireEnv('ZENDESK_API_TOKEN');
const email = requireEnv('ZENDESK_EMAIL');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
<p>Hi {{userName}},</p>
<p>{{message}}</p>
</div>

0 comments on commit eda57bd

Please sign in to comment.