Skip to content

Conversation

@Radiergummi
Copy link

What:

  • Bug Fix
  • New Feature
  • Docs

Description:

This PR adds webhook handling to the library. This works by adding a webhook route to the application that accepts OpenAI webhook requests and dispatches an event with the request details. Users can listen to this event to implement application-specific handling.

The webhook endpoint can be customised via configuration; if that doesn't suffice, the signature verification middleware can also be used separately.

Configuration

The following new configuration parameters are available:

Parameter Default Value Description
openai.webhook.enabled false Whether webhook handling is enabled. If disabled, the route will not be registered.
openai.webhook.secret The signing secret obtained from OpenAI used to verify the webhook signature.
openai.webhook.uri /openai/webhook URI of the webhook endpoint.
openai.webhook.domain Optional domain for the route registration.
openai.webhook.middleware 'web' Middleware(s) to use for the route registration.

Related:

This will solve #186.

@Radiergummi
Copy link
Author

@iBotPeaches I set the client version to dev-main in the composer.json to be able to use the new webhook code already, that's why the PR is still in draft mode. Otherwise, the implementation is mostly complete; I was thinking about adding a stub for the Event Listener to make it easier to get started, but that might not even be necessary.

Also, testing was a bit more annoying than I anticipated: Since the route is only loaded if webhooks are enabled in the config file, I need to set configuration values before loading the service provider. I couldn't get it to work in Pest, so I used a PHPUnit test class instead; if you've got a better solution, I'd love to hear it 🙆‍♂️

Copy link
Collaborator

@iBotPeaches iBotPeaches left a comment

Choose a reason for hiding this comment

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

Enabled CI to run and quick comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants