Orchard Core Omnichannel Azure Event Grid
Configure Event Grid Ingestion
You are an Orchard Core expert. Configure a secure Azure Event Grid webhook for
the CrestApps Omnichannel pipeline, most commonly to receive Azure
Communication Services (ACS) inbound texts.
Guidelines
- Install
CrestApps.OrchardCore.Omnichannel.EventGridin the web/startup
project and enable CrestApps.OrchardCore.Omnichannel.EventGrid (it depends
only on CrestApps.OrchardCore.Omnichannel).
- The endpoint
POST ~/api/azure/webhook/eventgridis anonymous and disables
antiforgery; every request, including the validation handshake, must pass the
SAS key or bearer-token check or it gets 401 Unauthorized.
- Only the Event Grid event schema is accepted. A CloudEvents subscription
is answered with 400 Bad Request.
- Keep the SAS key and Entra settings in secrets or environment configuration,
never in recipes or source.
- For ACS, also enable
CrestApps.OrchardCore.Omnichannel.AzureCommunicationServices
for the outbound providers (see orchardcore-omnichannel).
Enable via Recipe
{
"steps": [
{
"name": "Feature",
"enable": [
"CrestApps.OrchardCore.Omnichannel.EventGrid"
],
"disable": []
}
]
}
Configure Authentication
EventGridOptions is bound from the tenant shell configuration section
CrestApps:Omnichannel:EventGrid. In the application's root appsettings.json
the section sits under the OrchardCore key:
{
"OrchardCore": {
"CrestApps": {
"Omnichannel": {
"EventGrid": {
"EventGridSasKey": "set-from-secrets",
"AADIssuer": "https://sts.windows.net/<tenant-id>/",
"AADAudience": "api://<application-id>",
"AADMetadataAddress": "https://login.microsoftonline.com/<tenant-id>/.well-known/openid-configuration"
}
}
}
}
}
A tenant's own App_Data/Sites/{tenant}/appsettings.json uses the same keys
without the OrchardCore wrapper.
| EventGridOptions property | Use |
|---|---|
| EventGridSasKey | Fixed-time comparison with the aeg-sas-key request header. |
| AADIssuer, AADAudience, AADMetadataAddress | Validate a Microsoft Entra bearer token. All three are required; with only some set, a warning is logged and bearer tokens are rejected (SAS keeps working). |
The SAS key is checked first; a valid bearer token authorizes the request when
the SAS check fails.
Create the Subscription
- Deploy the site with the feature enabled and a public HTTPS address.
- In Azure, add an event subscription to the topic or system topic (for ACS,
the Communication Services resource's SMS events) with Webhook delivery
and Event Grid Schema.
- Target
https://<host>/api/azure/webhook/eventgrid. - For SAS delivery, add a custom delivery property (header) named
aeg-sas-key whose value equals EventGridSasKey; Event Grid does not send
it on its own. For Entra delivery, configure token delivery for the same
issuer and audience.
- Configure authentication before creating the subscription, because the
Microsoft.EventGrid.SubscriptionValidationEvent handshake is authenticated
too. The endpoint echoes { "validationResponse": "<code>" }; a validation
event without a code gets 400.
What Happens to Each Event
| Event type | Behavior |
|---|---|
| Microsoft.Communication.SMSReceived | Mapped onto the SMS channel and raised as OmnichannelConstants.Events.SmsReceived, the same event Twilio and Telnyx raise, so SMS Automation and the SMS Messaging Channel both act on it. |
| Microsoft.Communication.SMSDeliveryReportReceived | Stored as an inbound message and passed to handlers; the sent message's delivery status is not updated. |
| Any other type | Stored as an inbound message (channel Unknown unless the data names one) and passed to every IOmnichannelEventHandler with its raw type. |
ACS inbound text fields map as from to customer address, to to service
address (which selects the SMS omnichannel address, so the number must exist as
one), message to content, messageId to provider message id (event id when
missing), and receivedTimestamp to the created time.
- With an SMS feature on (SMS Omnichannel Automation or the SMS Messaging
Channel), an inbound text is committed to the durable provider webhook inbox,
keyed on messageId, before Event Grid is answered, and processed as soon as
the response is sent, because an automated reply can outlast Event Grid's
30-second wait. The Provider Webhook Inbox Dispatch background task
finishes a text a restart interrupted, a redelivered messageId is recognized
on every node, and a text that cannot be stored is answered
503 Service Unavailable so Event Grid redelivers the batch.
- With no SMS feature on, nothing composes a reply, so the text is stored and
passed to the event handlers inline.
- A text without
fromortois stored like an unmapped event with a warning. - Payloads over 1 MB get
413 Payload Too Large; malformed JSON gets400.
Handle Custom Events
Unmapped events reach every registered IOmnichannelEventHandler. Filter by the
raw event type and validate the provider payload before acting.
using CrestApps.OrchardCore.Omnichannel.Core;
using CrestApps.OrchardCore.Omnichannel.Core.Models;
namespace MyCompany.OrchardCore.Communications;
public sealed class ContosoEventGridHandler : IOmnichannelEventHandler
{
public Task HandleAsync(OmnichannelEvent omnichannelEvent, CancellationToken cancellationToken = default)
{
if (!string.Equals(omnichannelEvent.EventType, "Contoso.Orders.Shipped", StringComparison.Ordinal))
{
return Task.CompletedTask;
}
// omnichannelEvent.Data holds the raw Event Grid data.
return Task.CompletedTask;
}
}
Register it with services.AddScoped<IOmnichannelEventHandler, ContosoEventGridHandler>();
and keep it idempotent because Event Grid delivers at least once.
Troubleshooting
The endpoint logs one line per event (type and id), then what it did with it:
mapped to SmsReceived (with provider message id and length), delivery report
stored, redelivery of an already stored text ignored (information), a text that
could not be stored in the inbox (error; Event Grid is asked to redeliver),
mapping failure (warning), or no mapping (debug). Logs never
include message text or phone numbers. Watch for 401, 400 and 413 on the
route.
Monitoring
The module has its own meter and activity source, CrestApps.OrchardCore.EventGrid (EventGridTelemetry), because it does not reference the messaging workspace. crestapps.eventgrid.event counts the events deliveries carried by type (subscription_validation, sms_received, sms_delivery_report, other) and result (validated, invalid, accepted, duplicate, busy, failed, stored, malformed). The request itself is measured by ASP.NET Core, and the endpoint puts crestapps.eventgrid.result on the request span. Each event opens a log scope with EventGridEventId and EventType (never the subject, which is a phone number); log event ids are 18400-18449 (18400 validation without a code, 18404 malformed event). ACS delivery reports arriving here are counted only as crestapps.eventgrid.event with type sms_delivery_report and result stored, not on crestapps.messaging.delivery.
Upgrading from 2.x
- The route moved from
Omnichannel/webhook/AzureEventGridto
api/azure/webhook/eventgrid; update every subscription.
- ACS
SMSReceivedevents are now routed to the SMS channel instead of only
being stored, so remove custom handlers that duplicated that mapping.