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

python: Add convenient construction of rawPayload messages #1540

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions python/svix/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down