feat(notification): add additional Header to webhook

This commit is contained in:
janhartje 2022-10-05 17:48:07 +02:00
parent 3c5de1c889
commit b879428a03
No known key found for this signature in database
GPG Key ID: F7461D33DB5EF089
3 changed files with 46 additions and 13 deletions

View File

@ -28,8 +28,15 @@ class Webhook extends NotificationProvider {
finalData = data; finalData = data;
} }
if (notification.webhookAuthorizationHeader) { if (notification.webhookAdditionalHeaders) {
config.headers["Authorization"] = notification.webhookAuthorizationHeader; try {
config.headers = {
...config.headers,
...JSON.parse(notification.webhookAdditionalHeaders)
};
} catch (err) {
throw "Addional Headers is not a valid JSON";
}
} }
await axios.post(notification.webhookURL, finalData, config); await axios.post(notification.webhookURL, finalData, config);

View File

@ -12,7 +12,9 @@
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="webhook-content-type" class="form-label">{{ $t("Content Type") }}</label> <label for="webhook-content-type" class="form-label">{{
$t("Content Type")
}}</label>
<select <select
id="webhook-content-type" id="webhook-content-type"
v-model="$parent.notification.webhookContentType" v-model="$parent.notification.webhookContentType"
@ -24,7 +26,7 @@
</select> </select>
<div class="form-text"> <div class="form-text">
<p>{{ $t("webhookJsonDesc", ["\"application/json\""]) }}</p> <p>{{ $t("webhookJsonDesc", ['"application/json"']) }}</p>
<i18n-t tag="p" keypath="webhookFormDataDesc"> <i18n-t tag="p" keypath="webhookFormDataDesc">
<template #multipart>"multipart/form-data"</template> <template #multipart>"multipart/form-data"</template>
<template #decodeFunction> <template #decodeFunction>
@ -35,20 +37,42 @@
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="authorization-header" class="form-label">{{ $t("Authorization Header") }}</label> <i18n-t
<HiddenInput tag="label"
id="authorization-header" class="form-label"
v-model="$parent.notification.webhookAuthorizationHeader" for="additionalHeaders"
autocomplete="one-time-code" keypath="webhookAdditionalHeadersTitle"
></HiddenInput> >
</i18n-t>
<textarea
id="additionalHeaders"
v-model="$parent.notification.webhookAdditionalHeaders"
class="form-control"
:placeholder="headersPlaceholder"
></textarea>
<div class="form-text">
<i18n-t tag="p" keypath="webhookAdditionalHeadersDesc"> </i18n-t>
</div>
</div> </div>
</template> </template>
<script> <script>
import HiddenInput from "../HiddenInput.vue";
export default { export default {
components: { computed: {
HiddenInput, headersPlaceholder() {
return this.$t("Example:", [
`
{
"HeaderName": "HeaderValue"
}`,
]);
},
}, },
}; };
</script> </script>
<style lang="scss" scoped>
textarea {
min-height: 200px;
}
</style>

View File

@ -206,6 +206,8 @@ export default {
"Content Type": "Content Type", "Content Type": "Content Type",
webhookJsonDesc: "{0} is good for any modern HTTP servers such as Express.js", webhookJsonDesc: "{0} is good for any modern HTTP servers such as Express.js",
webhookFormDataDesc: "{multipart} is good for PHP. The JSON will need to be parsed with {decodeFunction}", webhookFormDataDesc: "{multipart} is good for PHP. The JSON will need to be parsed with {decodeFunction}",
webhookAdditionalHeadersTitle: "Additional Headers",
webhookAdditionalHeadersDesc: "Sets additional headers sent with the webhook.",
smtp: "Email (SMTP)", smtp: "Email (SMTP)",
secureOptionNone: "None / STARTTLS (25, 587)", secureOptionNone: "None / STARTTLS (25, 587)",
secureOptionTLS: "TLS (465)", secureOptionTLS: "TLS (465)",