Skip to content

Commit

Permalink
c#: Add convenient construction of rawPayload messages
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Dec 2, 2024
1 parent 55d615d commit 06329b0
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions csharp/Svix/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,49 @@ public Message(ISvixClient svixClient, IMessageApi messageApi)
_messageApi = messageApi ?? throw new ArgumentException(nameof(messageApi));
}


/// <summary>Creates a [MessageIn] with the payload already being serialized.
/// <para>
/// 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.
/// </para>
/// </summary>
/// <param name="payload">Serialized message payload</param>
/// <param name="contentType">Content type of the payload to send as a header. Defaults to `application/json`.</param>
public static MessageIn messageInRaw(
string eventType,
string payload,
string? contentType = null,

Check warning on line 39 in csharp/Svix/Message.cs

View workflow job for this annotation

GitHub Actions / C# Lint

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
ApplicationIn application = default(ApplicationIn),
List<string> channels = default(List<string>),
string eventId = default(string),
long? payloadRetentionHours = default(long?),
long? payloadRetentionPeriod = 90,
List<string> tags = default(List<string>),
Dictionary<string, Object> transformationsParams = default(Dictionary<string, Object>)
)
{
transformationsParams["rawPayload"] = payload;
if (contentType != null)
{
transformationsParams["headers"] =
new Dictionary<string, string> { ["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
Expand Down

0 comments on commit 06329b0

Please sign in to comment.