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 {
|
||||
var cfg struct {
|
||||
BotToken string `json:"botToken"`
|
||||
ChatID string `json:"chatID"`
|
||||
Token string `json:"token"`
|
||||
ChatID string `json:"chat_id"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(config, &cfg); err != nil {
|
||||
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)
|
||||
return nil
|
||||
}
|
||||
@ -144,7 +147,7 @@ func getPendingTests() ([]NotificationTest, error) {
|
||||
FROM notification_tests t
|
||||
JOIN notification_providers p
|
||||
ON "t"."notificationProviderId" = p.id
|
||||
WHERE t.success IS NOT TRUE`
|
||||
WHERE t.sent IS NOT TRUE`
|
||||
|
||||
rows, err := db.Query(query)
|
||||
if err != nil {
|
||||
|
||||
@ -17,7 +17,7 @@ export const NotificationSettings = ({ onError, onSuccess }: { onError: (message
|
||||
const testNotificationHandler = async (notificationProviderId: number) => {
|
||||
(document.getElementById('test_notification') as HTMLDialogElement)?.showModal();
|
||||
const notificationTest = await testNotification(notificationProviderId);
|
||||
setNotificationTestId(notificationTest.id);
|
||||
setNotificationTestId(notificationTest);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@ -13,9 +13,11 @@ export default function TestNotification({ notificationTestId }: TestNotificatio
|
||||
|
||||
|
||||
const checkNotificationTest = async () => {
|
||||
console.log(notificationTestId);
|
||||
await getNotificationTest(notificationTestId);
|
||||
}
|
||||
useEffect(() => {
|
||||
checkNotificationTest();
|
||||
}, [notificationTestId]);
|
||||
|
||||
return (
|
||||
<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 })
|
||||
.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 => {
|
||||
throw err.response?.data?.error || 'An error occurred';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user