Skip to content

Commit 525ad17

Browse files
committed
python: Add convenient construction of rawPayload messages
1 parent b095fdc commit 525ad17

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

python/svix/api.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,37 @@ def expunge_content(self, app_id: str, msg_id: str) -> None:
11621162
)
11631163

11641164

1165+
def message_in_raw(
1166+
event_type: str, payload: str, content_type: t.Optional[str] = None
1167+
) -> MessageIn:
1168+
"""
1169+
Creates a `MessageIn` with the payload already being serialized.
1170+
1171+
The payload is not normalized on the server. Normally, payloads are required
1172+
to be JSON, and Svix will minify the payload before sending the webhook
1173+
(for example, by removing extraneous whitespace or unnecessarily escaped
1174+
characters in strings). With this function, the payload will be sent
1175+
"as is", without any minification or other processing.
1176+
1177+
Args:
1178+
event_type (str): The event type's name Example: `user.signup`.
1179+
payload (str): Serialized message payload
1180+
content_type (str?): The `content-type` header value Svix uses for
1181+
the webhook request. If not specified, `application/json` is used.
1182+
"""
1183+
transformations_params: t.Dict[str, t.Any] = {
1184+
"rawPayload": payload,
1185+
}
1186+
if content_type is not None:
1187+
transformations_params["headers"] = {"content-type": content_type}
1188+
1189+
return MessageIn(
1190+
event_type=event_type,
1191+
payload={},
1192+
transformations_params=transformations_params,
1193+
)
1194+
1195+
11651196
class MessageAttemptAsync(ApiBase):
11661197
async def list_by_msg(
11671198
self,

0 commit comments

Comments
 (0)