EdgeInteract
Handling Responses
When PublishAndWaitAsync() resolves, you receive a typed InteractionResponse. The response contains the outcome, the respondent's user ID, any response data, and timing information. This page shows how to handle the response in your application code.
Reading the Response
// C# — server-side response handling
var response = await _publisher.PublishAndWaitAsync(request, ct);
// response.Outcome contains the type-specific outcome string
switch (response.Outcome)
{
case "approved":
await _workflow.ContinueWithApproval(
correlationId: request.CorrelationId,
approvedBy: response.RespondedBy,
approvedAt: response.Timestamp,
ct: ct);
break;
case "rejected":
var comment = response.Data?["comment"]?.ToString();
await _workflow.ContinueWithRejection(
correlationId: request.CorrelationId,
rejectedBy: response.RespondedBy,
rejectionReason: comment,
ct: ct);
break;
case "abstained":
// Escalate to the next approver
await _escalation.EscalateAsync(request, ct);
break;
}
Typed Response Data
For typed response data (e.g., form submission data or selected picker IDs), deserialize response.Data:
// Picker response — selectedIds
if (response.Outcome == "selected")
{
var pickerData = response.Data?.Deserialize<PickerResponseData>();
var selectedIds = pickerData?.SelectedIds ?? Array.Empty<string>();
await ProcessSelectedOptions(selectedIds, ct);
}
// Form response — all submitted field values
if (response.Outcome == "submitted")
{
var formData = response.Data?.Deserialize<Dictionary<string, object>>();
await ProcessFormSubmission(formData, ct);
}
Response Fields Reference
| Field | Type | Description |
|---|---|---|
InteractionId | string | Matches the original request ID |
RespondedBy | string | User ID of the respondent — important for role-targeted interactions |
Outcome | string | Type-specific outcome: approved, rejected, confirmed, submitted, selected, acknowledged |
Data | JsonElement? | Type-specific data; null for simple outcomes |
Timestamp | DateTimeOffset | When the user responded |
SessionId | string | EdgeStream session ID of the responding session |
CorrelationId | string? | Passed through from the request unchanged |
Idempotent Response Processing
In distributed deployments, the same response may occasionally be delivered twice (EdgeStream at-least-once delivery). Protect your response handler with idempotency checks:
// Use interactionId as idempotency key
if (await _idempotencyStore.AlreadyProcessedAsync(response.InteractionId, ct))
{
_logger.LogInformation("Duplicate response for {InteractionId} — ignoring", response.InteractionId);
return;
}
await _idempotencyStore.MarkProcessedAsync(response.InteractionId, ct);
// ... process the response