feature(dashboard): add integrations and notifications
This commit is contained in:
34
packages/integrations/src/discord.ts
Normal file
34
packages/integrations/src/discord.ts
Normal 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',
|
||||
});
|
||||
}
|
||||
50
packages/integrations/src/slack.ts
Normal file
50
packages/integrations/src/slack.ts
Normal 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,
|
||||
}),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user