Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Custom request body for Webhook Notifications #3088

Merged
merged 6 commits into from
Jul 9, 2023

Conversation

chakflying
Copy link
Collaborator

⚠️⚠️⚠️ Since we do not accept all types of pull requests and do not want to waste your time. Please be sure that you have read pull request rules:
https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma

Tick the checkbox if you understand [x]:

  • I have read and understand the pull request rules.

Description

Basically a continuation of #751, but only for Webhook notifications.

There is a trend of people using the Webhook notification type for other notification providers, but the body does not conform to the need of specific providers, therefore errors are encountered (#3087, #3084, #2967, #2960, #2845, #1160, #949). Allowing users to define a custom body would make Webhook actually useful.

This still doesn't solve the case for variables in query string tho. (#2813)

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the style guidelines of this project
  • I ran ESLint and other linters for modified files
  • I have performed a self-review of my own code and tested it
  • I have commented my code, particularly in hard-to-understand areas
    (including JSDoc for methods)
  • My changes generate no new warnings
  • My code needed automated testing. I have added them (this is optional task)

Screenshots (if any)

default custom
image image

@chakflying chakflying force-pushed the feat/webhook-custom-body branch from fc3f54f to 7df3aa0 Compare May 7, 2023 15:14
@louislam louislam linked an issue May 27, 2023 that may be closed by this pull request
1 task
Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have left some small inline comments

server/notification-providers/webhook.js Outdated Show resolved Hide resolved
src/components/notifications/Webhook.vue Outdated Show resolved Hide resolved
src/components/notifications/Webhook.vue Show resolved Hide resolved
@louislam louislam added this to the 1.23.0 milestone Jun 24, 2023
@chakflying chakflying force-pushed the feat/webhook-custom-body branch from bfacf92 to 8955c38 Compare June 25, 2023 21:00
@CommanderStorm CommanderStorm mentioned this pull request Jul 4, 2023
2 tasks
@louislam
Copy link
Owner

louislam commented Jul 9, 2023

Trying to test it using http://localhost:3001/test-webhook and submit it without content-type.

  • By default it seems a little bit weird to me, as it is using x-www-form-urlencoded and the json string is inside the first object key with empty string value.

image

@louislam louislam added question Further information is requested and removed cannot-reproduce labels Jul 9, 2023
@chakflying
Copy link
Collaborator Author

The "form-urlencoded" default is provided by axios. I can override this default to something like text/plain or application/json, but I'm not sure if there will be unintended consequences.

The strange body is probably because express is attempting to parse it into a javascript object. I use a rust program to print the body as string and it works fine.

@chakflying
Copy link
Collaborator Author

Express parses fine if you follow the format of form-urlencoded (ignore the unicode):

image

{
  accept: 'application/json, text/plain, */*',
  'content-type': 'application/x-www-form-urlencoded',
  authorization: 'Bearer alkdsfhgalowefvn',
  'user-agent': 'uptime-kuma/1.21',
  'content-length': '33',
  host: 'localhost:3001',
  connection: 'close'
}
{ 'Test Monitor': '[Test Monitor] [✅ Up] OK' }

@louislam
Copy link
Owner

louislam commented Jul 9, 2023

I got your point, I somehow wrongly thought the custom body must be a json due to the example in the placeholder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add application/xml to webhook option
3 participants