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

c#: Add convenient construction of rawPayload messages #1545

Merged
merged 1 commit into from
Dec 5, 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
48 changes: 48 additions & 0 deletions csharp/Svix/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,54 @@
_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.

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>)
)
{
if (transformationsParams == null)
{
transformationsParams = new 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
Loading