feat(notifications): webhook custom headers (#2230)
Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me>
This commit is contained in:
@@ -196,16 +196,36 @@ class WebhookAgent
|
||||
}
|
||||
|
||||
try {
|
||||
const headers: Record<string, string> = {};
|
||||
|
||||
if (settings.options.authHeader) {
|
||||
headers.Authorization = settings.options.authHeader;
|
||||
}
|
||||
|
||||
if (
|
||||
settings.options.customHeaders &&
|
||||
settings.options.customHeaders.length > 0
|
||||
) {
|
||||
settings.options.customHeaders.forEach((header) => {
|
||||
const key = header.key?.trim();
|
||||
const value = header.value?.trim();
|
||||
|
||||
if (key && value) {
|
||||
// Don't override Authorization header if it's already set via authHeader
|
||||
if (
|
||||
key.toLowerCase() !== 'authorization' ||
|
||||
!settings.options.authHeader
|
||||
) {
|
||||
headers[key] = value;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await axios.post(
|
||||
webhookUrl,
|
||||
this.buildPayload(type, payload),
|
||||
settings.options.authHeader
|
||||
? {
|
||||
headers: {
|
||||
Authorization: settings.options.authHeader,
|
||||
},
|
||||
}
|
||||
: undefined
|
||||
Object.keys(headers).length > 0 ? { headers } : undefined
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -277,6 +277,7 @@ export interface NotificationAgentWebhook extends NotificationAgentConfig {
|
||||
webhookUrl: string;
|
||||
jsonPayload: string;
|
||||
authHeader?: string;
|
||||
customHeaders?: { key: string; value: string }[];
|
||||
supportVariables?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user