Validates that the given payload was sent by OpenAI and parses the payload.
(
self,
payload: str | bytes,
headers: HeadersLike,
*,
secret: str | None = None,
)
| 117 | |
| 118 | class AsyncWebhooks(AsyncAPIResource): |
| 119 | def unwrap( |
| 120 | self, |
| 121 | payload: str | bytes, |
| 122 | headers: HeadersLike, |
| 123 | *, |
| 124 | secret: str | None = None, |
| 125 | ) -> UnwrapWebhookEvent: |
| 126 | """Validates that the given payload was sent by OpenAI and parses the payload.""" |
| 127 | if secret is None: |
| 128 | secret = self._client.webhook_secret |
| 129 | |
| 130 | self.verify_signature(payload=payload, headers=headers, secret=secret) |
| 131 | |
| 132 | body = payload.decode("utf-8") if isinstance(payload, bytes) else payload |
| 133 | return cast( |
| 134 | UnwrapWebhookEvent, |
| 135 | construct_type( |
| 136 | type_=UnwrapWebhookEvent, |
| 137 | value=json.loads(body), |
| 138 | ), |
| 139 | ) |
| 140 | |
| 141 | def verify_signature( |
| 142 | self, |
nothing calls this directly
no test coverage detected