diff --git a/python/svix/api.py b/python/svix/api.py index 006ce1509..a4e3e4d84 100644 --- a/python/svix/api.py +++ b/python/svix/api.py @@ -1162,6 +1162,37 @@ def expunge_content(self, app_id: str, msg_id: str) -> None: ) +def message_in_raw( + event_type: str, payload: str, content_type: t.Optional[str] = None +) -> MessageIn: + """ + Creates a `MessageIn` with the payload already being serialized. + + The payload is not normalized on the server. Normally, payloads are required + to be JSON, and Svix will minify the payload before sending the webhook + (for example, by removing extraneous whitespace or unnecessarily escaped + characters in strings). With this function, the payload will be sent + "as is", without any minification or other processing. + + Args: + event_type (str): The event type's name Example: `user.signup`. + payload (str): Serialized message payload. + content_type (str?): The `content-type` header value Svix uses for + the webhook request. If not specified, `application/json` is used. + """ + transformations_params: t.Dict[str, t.Any] = { + "rawPayload": payload, + } + if content_type is not None: + transformations_params["headers"] = {"content-type": content_type} + + return MessageIn( + event_type=event_type, + payload={}, + transformations_params=transformations_params, + ) + + class MessageAttemptAsync(ApiBase): async def list_by_msg( self,