feature(dashboard): add integrations and notifications

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-10-02 22:12:05 +02:00
parent d920f6951c
commit f65a633403
94 changed files with 3692 additions and 127 deletions

View File

@@ -0,0 +1,34 @@
// Cred to (@OpenStatusHQ) https://github.com/openstatusHQ/openstatus/blob/main/packages/notifications/discord/src/index.ts
export function sendDiscordNotification({
webhookUrl,
message,
}: {
webhookUrl: string;
message: string;
}) {
return fetch(webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
content: message,
avatar_url: 'https://openpanel.dev/logo.jpg',
username: 'OpenPanel Notifications',
}),
}).catch((err) => {
return {
ok: false,
json: () => Promise.resolve({}),
};
});
}
export function sendTestDiscordNotification(webhookUrl: string) {
return sendDiscordNotification({
webhookUrl,
message:
'**🧪 Test [OpenPanel.dev](<https://openpanel.dev/>)**\nIf you can read this, your Slack webhook is functioning correctly!\n',
});
}

View File

@@ -0,0 +1,50 @@
// Cred to (@c_alares) https://github.com/christianalares/seventy-seven/blob/main/packages/integrations/src/slack/index.ts
import { LogLevel, App as SlackApp } from '@slack/bolt';
import { InstallProvider } from '@slack/oauth';
const SLACK_CLIENT_ID = process.env.SLACK_CLIENT_ID;
const SLACK_CLIENT_SECRET = process.env.SLACK_CLIENT_SECRET;
const SLACK_OAUTH_REDIRECT_URL = process.env.SLACK_OAUTH_REDIRECT_URL;
const SLACK_STATE_SECRET = process.env.SLACK_STATE_SECRET;
export const slackInstaller = new InstallProvider({
clientId: SLACK_CLIENT_ID!,
clientSecret: SLACK_CLIENT_SECRET!,
stateSecret: SLACK_STATE_SECRET,
logLevel: process.env.NODE_ENV === 'development' ? LogLevel.DEBUG : undefined,
});
export const getSlackInstallUrl = ({
integrationId,
organizationId,
}: { integrationId: string; organizationId: string }) => {
return slackInstaller.generateInstallUrl({
scopes: [
'incoming-webhook',
'chat:write',
'chat:write.public',
'team:read',
],
redirectUri: SLACK_OAUTH_REDIRECT_URL,
metadata: JSON.stringify({ integrationId, organizationId }),
});
};
export function sendSlackNotification({
webhookUrl,
message,
}: {
webhookUrl: string;
message: string;
}) {
return fetch(webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: message,
}),
});
}