mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-19 06:05:25 +02:00
fix(notifications): update Mattermost notification handling
- Changed webhookUrl validation to ensure it is a valid URL. - Updated input types for createMattermostNotification and updateMattermostNotification functions to use z.infer for better type inference. - Refactored sendMattermostNotification to improve error handling and payload construction.
This commit is contained in:
@@ -211,26 +211,26 @@ export const sendMattermostNotification = async (
|
||||
connection: typeof mattermost.$inferInsert,
|
||||
message: any,
|
||||
) => {
|
||||
try {
|
||||
const payload = {
|
||||
...message,
|
||||
// Only include username if it's provided and not empty
|
||||
...(message.username &&
|
||||
message.username.trim() && { username: message.username }),
|
||||
// Only include channel if it's provided and not empty
|
||||
...(message.channel &&
|
||||
message.channel.trim() && {
|
||||
channel: `#${message.channel.replace("#", "")}`,
|
||||
}),
|
||||
};
|
||||
const payload = {
|
||||
...message,
|
||||
// Only include username if it's provided and not empty
|
||||
...(message.username?.trim() && { username: message.username }),
|
||||
// Only include channel if it's provided and not empty
|
||||
...(message.channel?.trim() && {
|
||||
channel: `#${message.channel.replace("#", "")}`,
|
||||
}),
|
||||
};
|
||||
|
||||
await fetch(connection.webhookUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
const response = await fetch(connection.webhookUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to send Mattermost notification: ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user