mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 15:36:50 +00:00
Send Test Notification Type fix
This commit is contained in:
parent
fb13c2bfce
commit
a218a7f8f3
@ -91,14 +91,17 @@ func SendNotification(providerType NotificationType, config json.RawMessage, tes
|
|||||||
|
|
||||||
func sendTelegramNotification(config json.RawMessage, test NotificationTest) error {
|
func sendTelegramNotification(config json.RawMessage, test NotificationTest) error {
|
||||||
var cfg struct {
|
var cfg struct {
|
||||||
BotToken string `json:"botToken"`
|
Token string `json:"token"`
|
||||||
ChatID string `json:"chatID"`
|
ChatID string `json:"chat_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(config, &cfg); err != nil {
|
if err := json.Unmarshal(config, &cfg); err != nil {
|
||||||
return fmt.Errorf("invalid Telegram config: %w", err)
|
return fmt.Errorf("invalid Telegram config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("Token:", cfg.Token)
|
||||||
|
fmt.Println("ChatID:", cfg.ChatID)
|
||||||
|
|
||||||
log.Printf("Sending Telegram test to chat %s", cfg.ChatID)
|
log.Printf("Sending Telegram test to chat %s", cfg.ChatID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -144,7 +147,7 @@ func getPendingTests() ([]NotificationTest, error) {
|
|||||||
FROM notification_tests t
|
FROM notification_tests t
|
||||||
JOIN notification_providers p
|
JOIN notification_providers p
|
||||||
ON "t"."notificationProviderId" = p.id
|
ON "t"."notificationProviderId" = p.id
|
||||||
WHERE t.success IS NOT TRUE`
|
WHERE t.sent IS NOT TRUE`
|
||||||
|
|
||||||
rows, err := db.Query(query)
|
rows, err := db.Query(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ export const NotificationSettings = ({ onError, onSuccess }: { onError: (message
|
|||||||
const testNotificationHandler = async (notificationProviderId: number) => {
|
const testNotificationHandler = async (notificationProviderId: number) => {
|
||||||
(document.getElementById('test_notification') as HTMLDialogElement)?.showModal();
|
(document.getElementById('test_notification') as HTMLDialogElement)?.showModal();
|
||||||
const notificationTest = await testNotification(notificationProviderId);
|
const notificationTest = await testNotification(notificationProviderId);
|
||||||
setNotificationTestId(notificationTest.id);
|
setNotificationTestId(notificationTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -13,9 +13,11 @@ export default function TestNotification({ notificationTestId }: TestNotificatio
|
|||||||
|
|
||||||
|
|
||||||
const checkNotificationTest = async () => {
|
const checkNotificationTest = async () => {
|
||||||
console.log(notificationTestId);
|
|
||||||
await getNotificationTest(notificationTestId);
|
await getNotificationTest(notificationTestId);
|
||||||
}
|
}
|
||||||
|
useEffect(() => {
|
||||||
|
checkNotificationTest();
|
||||||
|
}, [notificationTestId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -49,10 +49,14 @@ const useNotifications = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const testNotification = (notificationProviderId: number): Promise<string> | string => {
|
const testNotification = (notificationProviderId: number): Promise<number> | number => {
|
||||||
return axios.post('/api/notifications/test', { notificationProviderId })
|
return axios.post('/api/notifications/test', { notificationProviderId })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return response.data.notificationTest;
|
if(response.data.notificationTest) {
|
||||||
|
return Number(response.data.notificationTest.id);
|
||||||
|
} else {
|
||||||
|
throw new Error('Notification test not found');
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err.response?.data?.error || 'An error occurred';
|
throw err.response?.data?.error || 'An error occurred';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user