📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Added Slack & Discord notification channels
Blue Mouse4a890668fd1b
diff --git a/app/pages/UserSettings/UserSettings.tsx b/app/pages/UserSettings/UserSettings.tsxindex e98951623..93f07f2e2 100644--- a/app/pages/UserSettings/UserSettings.tsx+++ b/app/pages/UserSettings/UserSettings.tsx@@ -374,7 +374,7 @@ const UserSettings = ({}}- const handleIntegrationSave = (data: any, callback = () => {}) => {+ const handleIntegrationSave = (data: any, callback: (isSuccess: boolean) => void = () => {}) => {setBeenSubmitted(true)if (validated) {diff --git a/app/pages/UserSettings/components/Integrations.tsx b/app/pages/UserSettings/components/Integrations.tsxindex 795faff76..387e144a6 100644--- a/app/pages/UserSettings/components/Integrations.tsx+++ b/app/pages/UserSettings/components/Integrations.tsx@@ -8,6 +8,8 @@ import { CheckCircleIcon, XCircleIcon, ClockIcon } from '@heroicons/react/24/solimport Input from 'ui/Input'import Button from 'ui/Button'import Telegram from 'ui/icons/Telegram'+import Slack from 'ui/icons/Slack'+import Discord from 'ui/icons/Discord'import { removeTgIntegration } from 'api'import { IUser } from 'redux/models/IUser'@@ -25,10 +27,25 @@ const getAvailableIntegrations = (description: t('profileSettings.integrationsList.telegram'),Icon: Telegram,},+ {+ name: 'Slack',+ key: 'slack',+ description: t('profileSettings.integrationsList.slack'),+ Icon: Slack,+ },+ {+ name: 'Discord',+ key: 'discord',+ description: t('profileSettings.integrationsList.discord'),+ Icon: Discord,+ },]-const TG_BOT_URL: string = 'https://t.me/swetrixbot'-const TG_BOT_USERNAME: string = '@swetrixbot'+const TG_BOT_URL = 'https://t.me/swetrixbot'+const TG_BOT_USERNAME = '@swetrixbot'++const SLACK_WEBHOOKS_HELP = 'https://api.slack.com/messaging/webhooks'+const DISCORD_WEBHOOKS_HELP = 'https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks'const Integrations = ({user,@@ -38,13 +55,13 @@ const Integrations = ({}: {user: IUserupdateUserData: (data: Partial<IUser>) => void- handleIntegrationSave: (data: Partial<IUser>, cb: () => void) => void+ handleIntegrationSave: (data: Partial<IUser>, cb: (isSuccess: boolean) => void) => voidgenericError: (message: string) => void}) => {const { t } = useTranslation('common')const available = getAvailableIntegrations(t)const [integrationConfigurating, setIntegrationConfigurating] = useState<string | null>(null)- const [tgChatId, setTgChatId] = useState<string | null>(null)+ const [integrationInput, setIntegrationInput] = useState<string | null>(null)const [isIntegrationLoading, setIsIntegrationLoading] = useState<boolean>(false)const [isRemovalLoading, setIsRemovalLoading] = useState<boolean>(false)@@ -53,19 +70,55 @@ const Integrations = ({}const addIntegration = (key: string) => () => {- if (isIntegrationLoading) {+ if (isIntegrationLoading || !integrationInput) {return}- if (key === 'telegram' && tgChatId) {- setIsIntegrationLoading(true)+ setIsIntegrationLoading(true)++ if (key === 'telegram') {handleIntegrationSave({- telegramChatId: tgChatId,+ telegramChatId: integrationInput,},() => {setIsIntegrationLoading(false)setIntegrationConfigurating(null)+ setIntegrationInput(null)+ },+ )+ }++ if (key === 'slack') {+ handleIntegrationSave(+ {+ slackWebhookUrl: integrationInput,+ },+ (isSuccess: boolean) => {+ if (!isSuccess) {+ genericError(t('apiNotifications.integrationSaveError'))+ }++ setIsIntegrationLoading(false)+ setIntegrationConfigurating(null)+ setIntegrationInput(null)+ },+ )+ }++ if (key === 'discord') {+ handleIntegrationSave(+ {+ discordWebhookUrl: integrationInput,+ },+ (isSuccess: boolean) => {+ if (!isSuccess) {+ genericError(t('apiNotifications.integrationSaveError'))+ }++ setIsIntegrationLoading(false)+ setIntegrationConfigurating(null)+ setIntegrationInput(null)},)}@@ -80,6 +133,22 @@ const Integrations = ({}}+ if (key === 'discord') {+ return {+ connected: user.discordWebhookUrl,+ confirmed: user.discordWebhookUrl,+ id: null,+ }+ }++ if (key === 'slack') {+ return {+ connected: user.slackWebhookUrl,+ confirmed: user.slackWebhookUrl,+ id: null,+ }+ }+return {}}@@ -88,9 +157,9 @@ const Integrations = ({return}- if (key === 'telegram') {- setIsRemovalLoading(true)+ setIsRemovalLoading(true)+ if (key === 'telegram') {try {if (user.telegramChatId) {await removeTgIntegration(user.telegramChatId)@@ -101,28 +170,72 @@ const Integrations = ({isTelegramChatIdConfirmed: false,telegramChatId: null,})- } catch (e) {- if (_isString(e)) {- genericError(e)+ } catch (reason) {+ if (_isString(reason)) {+ genericError(reason)} else {genericError(t('apiNotifications.integrationRemovalError'))}- console.error(`[ERROR] Failed to remove TG integration: ${e}`)+ console.error(`[ERROR] Failed to remove TG integration: ${reason}`)}+setIsRemovalLoading(false)}++ if (key === 'slack') {+ handleIntegrationSave(+ {+ slackWebhookUrl: null,+ },+ (isSuccess: boolean) => {+ if (!isSuccess) {+ genericError(t('apiNotifications.integrationRemovalError'))+ }++ updateUserData({+ slackWebhookUrl: null,+ })+ setIsRemovalLoading(false)+ },+ )+ }++ if (key === 'discord') {+ handleIntegrationSave(+ {+ discordWebhookUrl: null,+ },+ (isSuccess: boolean) => {+ if (!isSuccess) {+ genericError(t('apiNotifications.integrationRemovalError'))+ }++ updateUserData({+ discordWebhookUrl: null,+ })+ setIsRemovalLoading(false)+ },+ )+ }}if (integrationConfigurating) {if (integrationConfigurating === 'telegram') {return (<>- <Button className='mb-2 mt-2' onClick={() => setIntegrationConfigurating(null)} primary small>+ <Button+ className='mb-2 mt-2'+ onClick={() => {+ setIntegrationInput(null)+ setIntegrationConfigurating(null)+ }}+ primary+ small+ >{t('common.goBack')}</Button><p className='max-w-prose text-base text-gray-900 dark:text-gray-50'><Trans- // @ts-ignoret={t}i18nKey='profileSettings.integrationsList.tgHint'components={{@@ -141,17 +254,122 @@ const Integrations = ({}}/></p>- <div className='mt-4 flex items-center'>+ <div className='mt-4 flex items-end'><Inputlabel={t('profileSettings.chatID')}- value={tgChatId || ''}- placeholder={t('profileSettings.chatID')}+ value={integrationInput || ''}+ className='sm:col-span-3'+ onChange={(e) => setIntegrationInput(e.target.value)}+ disabled={isIntegrationLoading}+ />+ <Button+ className='ml-2 py-2.5'+ onClick={addIntegration(integrationConfigurating)}+ loading={isIntegrationLoading}+ primary+ large+ >+ {t('common.enable')}+ </Button>+ </div>+ </>+ )+ }++ if (integrationConfigurating === 'slack') {+ return (+ <>+ <Button+ className='mb-2 mt-2'+ onClick={() => {+ setIntegrationInput(null)+ setIntegrationConfigurating(null)+ }}+ primary+ small+ >+ {t('common.goBack')}+ </Button>+ <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>+ <Trans+ t={t}+ i18nKey='profileSettings.integrationsList.slackHint'+ components={{+ // eslint-disable-next-line jsx-a11y/anchor-has-content+ url: (+ <a+ href={SLACK_WEBHOOKS_HELP}+ className='text-blue-600 hover:underline'+ target='_blank'+ rel='noreferrer noopener'+ />+ ),+ }}+ />+ </p>+ <div className='mt-4 flex items-end'>+ <Input+ label={t('profileSettings.integrationsList.webhookUrl')}+ value={integrationInput || ''}+ className='sm:col-span-3'+ onChange={(e) => setIntegrationInput(e.target.value)}+ disabled={isIntegrationLoading}+ />+ <Button+ className='ml-2 py-2.5'+ onClick={addIntegration(integrationConfigurating)}+ loading={isIntegrationLoading}+ primary+ large+ >+ {t('common.enable')}+ </Button>+ </div>+ </>+ )+ }++ if (integrationConfigurating === 'discord') {+ return (+ <>+ <Button+ className='mb-2 mt-2'+ onClick={() => {+ setIntegrationInput(null)+ setIntegrationConfigurating(null)+ }}+ primary+ small+ >+ {t('common.goBack')}+ </Button>+ <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>+ <Trans+ t={t}+ i18nKey='profileSettings.integrationsList.discordHint'+ components={{+ // eslint-disable-next-line jsx-a11y/anchor-has-content+ url: (+ <a+ href={DISCORD_WEBHOOKS_HELP}+ className='text-blue-600 hover:underline'+ target='_blank'+ rel='noreferrer noopener'+ />+ ),+ }}+ />+ </p>+ <div className='mt-4 flex items-end'>+ <Input+ label={t('profileSettings.integrationsList.webhookUrl')}+ value={integrationInput || ''}className='sm:col-span-3'- onChange={(e) => setTgChatId(e.target.value)}+ onChange={(e) => setIntegrationInput(e.target.value)}disabled={isIntegrationLoading}/><Button- className='ml-2 mt-4'+ className='ml-2 py-2.5'onClick={addIntegration(integrationConfigurating)}loading={isIntegrationLoading}primary@@ -177,55 +395,50 @@ const Integrations = ({const status = connected ? (confirmed ? 'connected' : 'pending') : 'notConnected'return (- <li key={key}>- <div className='items-center px-1 py-4 sm:flex sm:px-6'>- <div className='flex min-w-0 flex-1 items-center'>- <div className='hidden flex-shrink-0 sm:block'>- <Icon className='h-12 max-h-12 w-12 max-w-12 rounded-full' />+ <li key={key} className='items-center px-1 py-4 sm:flex sm:px-6'>+ <div className='flex min-w-0 flex-1 items-center'>+ <div className='hidden flex-shrink-0 sm:block'>+ <Icon className='size-12 max-h-12 max-w-12' />+ </div>+ <div className='min-w-0 flex-1 px-2 sm:px-4 md:grid md:grid-cols-2 md:gap-4'>+ <div>+ <p className='text-md font-medium text-gray-800 dark:text-gray-50'>{name}</p>+ <p className='mt-2 flex items-center text-sm text-gray-500 dark:text-gray-100'>+ <span>{description}</span>+ </p></div>- <div className='min-w-0 flex-1 px-2 sm:px-4 md:grid md:grid-cols-2 md:gap-4'>- <div>- <p className='text-md font-medium text-gray-800 dark:text-gray-50'>{name}</p>- <p className='mt-2 flex items-center text-sm text-gray-500 dark:text-gray-100'>- <span>{description}</span>+ <div>+ {id && (+ <p className='text-sm text-gray-900 dark:text-gray-50'>+ {t('profileSettings.chatID')}+ {`: ${id}`}</p>- </div>- <div>- {id && (- <p className='text-sm text-gray-900 dark:text-gray-50'>- {t('profileSettings.chatID')}- {`: ${id}`}- </p>+ )}+ <p className='mt-2 flex items-center text-sm text-gray-500 dark:text-gray-100'>+ {status === 'notConnected' && (+ <XCircleIcon className='mr-1.5 h-5 w-5 flex-shrink-0 text-red-400' aria-hidden='true' />)}- <p className='mt-2 flex items-center text-sm text-gray-500 dark:text-gray-100'>- {status === 'notConnected' && (- <XCircleIcon className='mr-1.5 h-5 w-5 flex-shrink-0 text-red-400' aria-hidden='true' />- )}- {status === 'pending' && (- <ClockIcon className='mr-1.5 h-5 w-5 flex-shrink-0 text-yellow-400' aria-hidden='true' />- )}- {status === 'connected' && (- <CheckCircleIcon- className='mr-1.5 h-5 w-5 flex-shrink-0 text-green-400'- aria-hidden='true'- />- )}- {t(`common.${status}`)}- </p>- </div>+ {status === 'pending' && (+ <ClockIcon className='mr-1.5 h-5 w-5 flex-shrink-0 text-yellow-400' aria-hidden='true' />+ )}+ {status === 'connected' && (+ <CheckCircleIcon className='mr-1.5 h-5 w-5 flex-shrink-0 text-green-400' aria-hidden='true' />+ )}+ {t(`common.${status}`)}+ </p></div></div>- <div className='mt-2 flex justify-center sm:mt-0 sm:block'>- {connected ? (- <Button onClick={() => removeIntegration(key)} small danger>- {t('profileSettings.removeIntegration')}- </Button>- ) : (- <Button onClick={setupIntegration(key)} small primary>- {t('profileSettings.addIntegration')}- </Button>- )}- </div>+ </div>+ <div className='mt-2 flex justify-center sm:mt-0 sm:block'>+ {connected ? (+ <Button onClick={() => removeIntegration(key)} small danger>+ {t('profileSettings.removeIntegration')}+ </Button>+ ) : (+ <Button onClick={setupIntegration(key)} small primary>+ {t('profileSettings.addIntegration')}+ </Button>+ )}</div></li>)diff --git a/app/redux/constants/index.ts b/app/redux/constants/index.tsindex 9a1b759b2..c31f9bedd 100644--- a/app/redux/constants/index.ts+++ b/app/redux/constants/index.ts@@ -483,7 +483,7 @@ export const paddleLanguageMapping: IStringObject = {// Increase this counter every time some major change is done within localisation files// This will prevent cached version or raw locale strings being displayed in production-export const I18N_CACHE_BREAKER = 2+export const I18N_CACHE_BREAKER = 3// dashboard && projectsdiff --git a/app/redux/models/IUser.ts b/app/redux/models/IUser.tsindex 99a219914..c62ae41b5 100644--- a/app/redux/models/IUser.ts+++ b/app/redux/models/IUser.ts@@ -32,6 +32,8 @@ export interface IUser {nextBillDate: string | nullcancellationEffectiveDate: string | nullapiKey: string | null+ slackWebhookUrl: string | null+ discordWebhookUrl: string | nulltelegramChatId: string | nullisTelegramChatIdConfirmed: booleantimeFormat: stringdiff --git a/public/locales/en.json b/public/locales/en.jsonindex 31e5ef1ab..b99dae4d8 100644--- a/public/locales/en.json+++ b/public/locales/en.json@@ -23,6 +23,7 @@"subscriptionUpdated": "Your subscription has been updated","generate2FAError": "Error occurred while generating 2FA code","integrationRemovalError": "Error occurred while removing the integration",+ "integrationSaveError": "Failed to save integration, make sure you've entered a valid input","enterACorrectNumber": "Please enter a correct number","numberCantBeNegative": "The number cannot be negative","forecastNumberCantBeBigger": "The forecast number cannot be bigger than {{max}} for the selected frequency",@@ -593,7 +594,12 @@"integrationsDesc": "Integrations can be used to connect your favourite messengers to Swetrix and receive updates such as notifications, reports or alerts directly.","integrationsList": {"telegram": "Receive notifications directly into a Telegram bot.",- "tgHint": "Write a message to <url>{{username}}</url> to get your chat ID. This bot will be used later to send you notifications or alerts."+ "slack": "Receive notifications in any Slack channel via webhook.",+ "discord": "Receive notifications in any Discord channel via webhook.",+ "tgHint": "Write a message to <url>{{username}}</url> to get your chat ID. This bot will be used later to send you notifications or alerts.",+ "slackHint": "We use Slack incoming webhooks to send notifications into your Slack communication channels. Please create a Slack app and <url>an incoming webhook</url> and paste it into the input field below.",+ "discordHint": "We use Discord webhooks to send you notifications. Please <url>create a Discord webhook</url> and paste it into the input field below.",+ "webhookUrl": "Webhook URL"},"socialisations": "Socialisations","socialisationsDesc": "Socialisation feature allows you to link 3rd party accounts (like Google or Twitter) to your Swetrix account and use them to sign in to Swetrix.",