async function sendNotificationSafely(appId: string, apiKey: string, message: any) {
try {
const response = await fetch(`https://alerts-api.dial.to/v2/${appId}/send`, {
method: 'POST',
headers: {
'x-dialect-api-key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify(message)
});
if (!response.ok) {
const error = await response.json();
switch (response.status) {
case 401:
throw new Error('Invalid API key. Please check your credentials.');
case 403:
throw new Error('Access denied. Check your app permissions.');
default:
throw new Error(`HTTP ${response.status}: ${JSON.stringify(error)}`);
}
}
return response.json();
} catch (error) {
console.error('Failed to send notification:', error);
throw error;
}
}