Skip to content

Commit b095fdc

Browse files
authored
go: Add convenient construction of rawPayload messages (#1538)
Part of svix/monorepo-private#9470.
2 parents b2f0708 + d81b92e commit b095fdc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

go/message.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,31 @@ func (m *Message) ExpungeContent(ctx context.Context, appId string, msgId string
9696
res, err := req.Execute()
9797
return wrapError(err, res)
9898
}
99+
100+
// Instantiates a new MessageIn object with a pre-serialized payload.
101+
//
102+
// The payload is not normalized on the server. Normally, payloads are required
103+
// to be JSON, and Svix will minify the payload before sending the webhook
104+
// (for example, by removing extraneous whitespace or unnecessarily escaped
105+
// characters in strings). With this function, the payload will be sent
106+
// "as is", without any minification or other processing.
107+
//
108+
// The `contentType` parameter can be used to change the `content-type` header
109+
// of the webhook sent by Svix overriding the default of `application/json`.
110+
//
111+
// See the class documentation for details about the other parameters.
112+
func NewMessageInRaw(eventType string, payload string, contentType openapi.NullableString) *MessageIn {
113+
msgIn := openapi.NewMessageIn(eventType, make(map[string]interface{}))
114+
115+
transformationsParams := map[string]interface{}{
116+
"rawPayload": payload,
117+
}
118+
if contentType.IsSet() {
119+
transformationsParams["headers"] = map[string]string{
120+
"content-type": *contentType.Get(),
121+
}
122+
}
123+
msgIn.SetTransformationsParams(transformationsParams)
124+
125+
return msgIn
126+
}

0 commit comments

Comments
 (0)