diff --git a/csharp/Svix/Message.cs b/csharp/Svix/Message.cs index 133ce6578..f85c4bbba 100644 --- a/csharp/Svix/Message.cs +++ b/csharp/Svix/Message.cs @@ -23,6 +23,54 @@ public Message(ISvixClient svixClient, IMessageApi messageApi) _messageApi = messageApi ?? throw new ArgumentException(nameof(messageApi)); } + + /// Creates a [MessageIn] with the payload already being serialized. + /// + /// The payload is not normalized on the server (usually whitespace outside + /// of string literals, unnecessarily escaped characters in string and such + /// are fixed up by the server), and is not even required to be JSON. + /// + /// + /// Serialized message payload + /// Content type of the payload to send as a header. Defaults to `application/json`. + public static MessageIn messageInRaw( + string eventType, + string payload, + string? contentType = null, + ApplicationIn application = default(ApplicationIn), + List channels = default(List), + string eventId = default(string), + long? payloadRetentionHours = default(long?), + long? payloadRetentionPeriod = 90, + List tags = default(List), + Dictionary transformationsParams = default(Dictionary) + ) + { + if (transformationsParams == null) + { + transformationsParams = new Dictionary(); + } + + transformationsParams["rawPayload"] = payload; + if (contentType != null) + { + transformationsParams["headers"] = + new Dictionary { ["content-type"] = contentType }; + } + + return new MessageIn( + eventType: eventType, + payload: new { }, + application: application, + channels: channels, + eventId: eventId, + payloadRetentionHours: payloadRetentionHours, + payloadRetentionPeriod: payloadRetentionPeriod, + tags: tags, + transformationsParams: transformationsParams + ); + } + public MessageOut Create(string appId, MessageIn message, MessageCreateOptions options = null, string idempotencyKey = default) { try