Orchardcore omnichannel event grid

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore omnichannel event grid is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for receiving Azure Event Grid events in Orchard Core with the CrestApps Omnichannel - Azure Event Grid feature CrestApps.OrchardCore.Omnichannel.EventGrid. Covers the anonymous POST api/azure/webhook/eventgrid endpoint, aeg-sas-key and Microsoft Entra bearer-token authentication through Event

How to use this skill

Skill file

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

project and enable CrestApps.OrchardCore.Omnichannel.EventGrid (it depends

only on CrestApps.OrchardCore.Omnichannel).

antiforgery; every request, including the validation handshake, must pass the

SAS key or bearer-token check or it gets 401 Unauthorized.

is answered with 400 Bad Request.

never in recipes or source.

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

  1. Deploy the site with the feature enabled and a public HTTPS address.
  2. 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.

  1. Target https://<host>/api/azure/webhook/eventgrid.
  2. 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.

  1. 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.

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.

passed to the event handlers inline.

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

api/azure/webhook/eventgrid; update every subscription.

being stored, so remove custom handlers that duplicated that mapping.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.