adnanh / webhook

webhook is a lightweight incoming webhook server to run shell commands
MIT License
10.47k stars 836 forks source link

Feature: Echo back #701

Open b4ldr opened 1 month ago

b4ldr commented 1 month ago

Hello,

First of all thanks for the great tool :)

I already use webhooks for a few things and so when looking to integrate some smartsheet workflows with a webhook it was the frist tool i reached for. However, there is with the smartsheets there is a verification process which happens when you first register the webhook and then once every 100 callbacks.

This verification process is described as follows:

When an API client attempts to enable a webhook, Smartsheet sends a verification request to the webhook's callbackUrl to verify that the subscriber expects and is able to successfully receive callbacks. The request specifies a unique random value in the Smartsheet-Hook-Challenge header and contains a JSON object in the request body with only challenge and webhookId attributes in the request body. The challenge attribute is a repeat of the header value for API clients that don't interpret header values.

To verify the webhook, the subscriber's response to the verification request must return a 200 HTTP status code and must echo back the same unique random value in the Smartsheet-Hook-Response header of the response or with a JSON smartsheetHookResponse attribute. Once Smartsheet receives this verification response, the webhook is enabled (enabled: true and status: "ENABLED").

From what i can see this is not something that would be currently supported in WebHook, please correct me if im wrong, and wondered, nah hoped you may like to add it as a feature. Unfortunatly i have done very little Go coding and don't think id be compitent enough to work up a PR.

ianroberts commented 1 month ago

Setting response headers to values taken from the request isn't supported, but you should be able to respond

with a JSON smartsheetHookResponse attribute

The key is that "include-command-output-in-response": true allows you to generate the response body in your execute-command by printing to standard output. Your command needs to understand this challenge message and print out the appropriate smartsheetHookResponse JSON, and you'd also need to set "response-headers": [{"name": "Content-Type", "value": "application/json; charset=utf-8"}] to make sure the webhook response is properly declared as JSON.