fix #148: handle nested webhook payload
This commit is contained in:
1 parent
1d12cf0b3e
commit
20e7f47b5e
2 files changed
+14
-6
No files matched your search
+13
-5
@@ -66,6 +66,18 @@ function formatStatusChangeNotification(
|
||||
}
|
||||
}
|
||||
|
||||
function templateWebhookPlayload(payload: any, message: string) {
|
||||
for (const key in payload) {
|
||||
if (Object.prototype.hasOwnProperty.call(payload, key)) {
|
||||
if (payload[key] === '$MSG') {
|
||||
payload[key] = message
|
||||
} else if (typeof payload[key] === 'object' && payload[key] !== null) {
|
||||
templateWebhookPlayload(payload[key], message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function webhookNotify(webhook: WebhookConfig, message: string) {
|
||||
console.log(
|
||||
'Sending webhook notification: ' + JSON.stringify(message) + ' to webhook ' + webhook.url
|
||||
@@ -75,11 +87,7 @@ async function webhookNotify(webhook: WebhookConfig, message: string) {
|
||||
let method = webhook.method
|
||||
let headers = new Headers(webhook.headers as any)
|
||||
let payloadTemplated: { [key: string]: string | number } = JSON.parse(JSON.stringify(webhook.payload))
|
||||
Object.keys(payloadTemplated).forEach((k) => {
|
||||
if (payloadTemplated[k] === '$MSG') {
|
||||
payloadTemplated[k] = message
|
||||
}
|
||||
})
|
||||
templateWebhookPlayload(payloadTemplated, message)
|
||||
let body = undefined
|
||||
|
||||
switch (webhook.payloadType) {
|
||||
|
||||
Reference in new issue
Block a user