Add Google Chat webhook to notification channels
- Added Google Chat as a new channel type option in the Notification Channel - Add Google Chat tab to notifications - Fix: Ensure Google Chat and Email save record to PB
This commit is contained in:
@@ -7,7 +7,7 @@ export interface AlertConfiguration {
|
||||
collectionId?: string;
|
||||
collectionName?: string;
|
||||
service_id: string;
|
||||
notification_type: "telegram" | "discord" | "signal" | "slack" | "email";
|
||||
notification_type: "telegram" | "discord" | "slack" | "signal" | "google_chat" | "email" | "webhook";
|
||||
telegram_chat_id?: string;
|
||||
discord_webhook_url?: string;
|
||||
signal_number?: string;
|
||||
@@ -15,6 +15,7 @@ export interface AlertConfiguration {
|
||||
bot_token?: string;
|
||||
template_id?: string;
|
||||
slack_webhook_url?: string;
|
||||
google_chat_webhook_url?: string;
|
||||
enabled: boolean;
|
||||
created?: string;
|
||||
updated?: string;
|
||||
@@ -29,13 +30,10 @@ export interface AlertConfiguration {
|
||||
|
||||
export const alertConfigService = {
|
||||
async getAlertConfigurations(): Promise<AlertConfiguration[]> {
|
||||
// console.info("Fetching alert configurations");
|
||||
try {
|
||||
const response = await pb.collection('alert_configurations').getList(1, 50);
|
||||
// console.info("Alert configurations response:", response);
|
||||
return response.items as AlertConfiguration[];
|
||||
} catch (error) {
|
||||
// console.error("Error fetching alert configurations:", error);
|
||||
toast({
|
||||
title: "Error",
|
||||
description: "Failed to load notification settings",
|
||||
@@ -46,17 +44,50 @@ export const alertConfigService = {
|
||||
},
|
||||
|
||||
async createAlertConfiguration(config: Omit<AlertConfiguration, 'id' | 'collectionId' | 'collectionName' | 'created' | 'updated'>): Promise<AlertConfiguration | null> {
|
||||
// console.info("Creating alert configuration:", config);
|
||||
|
||||
try {
|
||||
const result = await pb.collection('alert_configurations').create(config);
|
||||
// console.info("Alert configuration created:", result);
|
||||
// Build the configuration object with proper field mapping
|
||||
const cleanConfig: any = {
|
||||
service_id: config.service_id || "global",
|
||||
notification_type: config.notification_type,
|
||||
notify_name: config.notify_name,
|
||||
enabled: config.enabled,
|
||||
template_id: config.template_id || "",
|
||||
};
|
||||
|
||||
// Add type-specific fields based on notification type
|
||||
if (config.notification_type === "telegram") {
|
||||
cleanConfig.telegram_chat_id = config.telegram_chat_id || "";
|
||||
cleanConfig.bot_token = config.bot_token || "";
|
||||
} else if (config.notification_type === "discord") {
|
||||
cleanConfig.discord_webhook_url = config.discord_webhook_url || "";
|
||||
} else if (config.notification_type === "slack") {
|
||||
cleanConfig.slack_webhook_url = config.slack_webhook_url || "";
|
||||
} else if (config.notification_type === "signal") {
|
||||
cleanConfig.signal_number = config.signal_number || "";
|
||||
} else if (config.notification_type === "google_chat") {
|
||||
cleanConfig.google_chat_webhook_url = config.google_chat_webhook_url || "";
|
||||
} else if (config.notification_type === "email") {
|
||||
|
||||
cleanConfig.email_address = config.email_address || "";
|
||||
cleanConfig.email_sender_name = config.email_sender_name || "";
|
||||
cleanConfig.smtp_server = config.smtp_server || "";
|
||||
cleanConfig.smtp_port = config.smtp_port || "";
|
||||
|
||||
}
|
||||
|
||||
const result = await pb.collection('alert_configurations').create(cleanConfig);
|
||||
|
||||
toast({
|
||||
title: "Success",
|
||||
description: "Notification channel created successfully",
|
||||
});
|
||||
return result as AlertConfiguration;
|
||||
} catch (error) {
|
||||
// console.error("Error creating alert configuration:", error);
|
||||
// Try to get more details from the error
|
||||
if (error && typeof error === 'object') {
|
||||
}
|
||||
|
||||
toast({
|
||||
title: "Error",
|
||||
description: "Failed to create notification channel",
|
||||
@@ -67,17 +98,14 @@ export const alertConfigService = {
|
||||
},
|
||||
|
||||
async updateAlertConfiguration(id: string, config: Partial<AlertConfiguration>): Promise<AlertConfiguration | null> {
|
||||
// console.info(`Updating alert configuration ${id}:`, config);
|
||||
try {
|
||||
const result = await pb.collection('alert_configurations').update(id, config);
|
||||
// console.info("Alert configuration updated:", result);
|
||||
toast({
|
||||
title: "Success",
|
||||
description: "Notification channel updated successfully",
|
||||
});
|
||||
return result as AlertConfiguration;
|
||||
} catch (error) {
|
||||
// console.error("Error updating alert configuration:", error);
|
||||
toast({
|
||||
title: "Error",
|
||||
description: "Failed to update notification channel",
|
||||
@@ -88,17 +116,14 @@ export const alertConfigService = {
|
||||
},
|
||||
|
||||
async deleteAlertConfiguration(id: string): Promise<boolean> {
|
||||
// console.info(`Deleting alert configuration ${id}`);
|
||||
try {
|
||||
await pb.collection('alert_configurations').delete(id);
|
||||
// console.info("Alert configuration deleted");
|
||||
toast({
|
||||
title: "Success",
|
||||
description: "Notification channel removed",
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
// console.error("Error deleting alert configuration:", error);
|
||||
toast({
|
||||
title: "Error",
|
||||
description: "Failed to remove notification channel",
|
||||
|
||||
Reference in New Issue
Block a user