Orchardcore ai chat notifications

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore ai chat notifications is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for sending transient SignalR chat UI notifications in Orchard Core using the CrestApps AI Chat feature. Covers IChatNotificationSender, keyed IChatNotificationTransport implementations, keyed IChatNotificationActionHandler callbacks, notification models, built-in transfer and session actions,

How to use this skill

Skill file

Orchard Core AI Chat Notifications - Prompt Templates

Send Transient Chat UI Notifications

You are an Orchard Core expert. Generate C# integration code for transient, non-persistent system messages delivered to connected chat clients through SignalR. These notifications are an AI Chat feature and are distinct from response handlers and persisted chat messages.

Guidelines

Feature Overview

| Feature | Feature ID | Transport |

|---|---|---|

| AI Chat | CrestApps.OrchardCore.AI.Chat | AIChatNotificationTransport for AIChatSession |

| AI Chat Interactions | CrestApps.OrchardCore.AI.Chat.Interactions | ChatInteractionNotificationTransport for ChatInteraction |

Install and Enable

Install the chat package in the web/startup project:

dotnet add package CrestApps.OrchardCore.AI.Chat
{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "CrestApps.OrchardCore.AI",
        "CrestApps.OrchardCore.AI.Chat"
      ],
      "disable": []
    }
  ]
}

For notifications on ad-hoc chat interactions, also enable CrestApps.OrchardCore.AI.Chat.Interactions.

Send and Remove a Typing Indicator

using CrestApps.Core.AI.Chat;
using CrestApps.Core.AI.Models;
using Microsoft.Extensions.Localization;

namespace MyModule;

public sealed class AgentStatusNotifier
{
    private readonly IChatNotificationSender _notifications;
    private readonly IStringLocalizer T;

    public AgentStatusNotifier(
        IChatNotificationSender notifications,
        IStringLocalizer<AgentStatusNotifier> localizer)
    {
        _notifications = notifications;
        T = localizer;
    }

    public Task ShowTypingAsync(string sessionId)
    {
        return _notifications.SendAsync(
            sessionId,
            ChatContextType.AIChatSession,
            new ChatNotification(ChatNotificationTypes.Typing)
            {
                Content = T["An agent is typing"].Value,
                Icon = "fa-solid fa-ellipsis",
            });
    }

    public Task RemoveTypingAsync(string sessionId)
    {
        return _notifications.RemoveAsync(
            sessionId,
            ChatContextType.AIChatSession,
            ChatNotificationTypes.Typing);
    }
}

Notification Model

| Member | Use |

|---|---|

| Id | Optional instance identifier for client targeting |

| Type | Required visual and replacement type set by the constructor |

| Content | Localized display text |

| Icon | Font Awesome icon class |

| CssClass | Additional container class |

| Dismissible | Shows a client dismissal control |

| Actions | Buttons that invoke server-side handlers |

| Metadata | Non-sensitive extensibility data sent to the client |

The chat UI applies ai-chat-notification-{type} in addition to base styling. Add theme CSS for custom types.

Send a Transfer Notification

await notifications.SendAsync(
    sessionId,
    ChatContextType.AIChatSession,
    new ChatNotification(ChatNotificationTypes.Transfer)
    {
        Content = T["Transferring you to a live agent."].Value,
        Icon = "fa-solid fa-headset",
        Actions =
        [
            new ChatNotificationAction
            {
                Name = ChatNotificationActionNames.CancelTransfer,
                Label = T["Cancel Transfer"].Value,
                CssClass = "btn-outline-danger",
                Icon = "fa-solid fa-xmark",
            },
        ],
    });

Update the same Transfer type when wait-time information changes. Remove it when transfer completes.

Add a Custom Action

Define a handler for a custom action name:

using CrestApps.Core.AI.Chat;
using CrestApps.Core.AI.Models;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Modules;

namespace MyModule;

public sealed class FeedbackActionHandler : IChatNotificationActionHandler
{
    public Task HandleAsync(
        ChatNotificationActionContext context,
        CancellationToken cancellationToken = default)
    {
        var notifications = context.Services.GetRequiredService<IChatNotificationSender>();

        return notifications.RemoveAsync(
            context.SessionId,
            context.ChatType,
            context.NotificationType);
    }
}

public sealed class Startup : StartupBase
{
    public override void ConfigureServices(IServiceCollection services)
    {
        services.AddKeyedScoped<IChatNotificationActionHandler, FeedbackActionHandler>("feedback-positive");
    }
}

Send an action whose Name is exactly feedback-positive:

await notifications.SendAsync(sessionId, ChatContextType.AIChatSession, new ChatNotification("feedback")
{
    Content = T["Was this helpful?"].Value,
    Dismissible = true,
    Actions =
    [
        new ChatNotificationAction
        {
            Name = "feedback-positive",
            Label = T["Yes"].Value,
            CssClass = "btn-outline-success",
        },
    ],
});

Built-In Types and Actions

| Constant | Purpose |

|---|---|

| ChatNotificationTypes.Typing | Agent typing indicator |

| ChatNotificationTypes.Transfer | Live-agent transfer state |

| ChatNotificationTypes.AgentConnected | Agent-connected state |

| ChatNotificationTypes.AgentReconnecting | Reconnect warning |

| ChatNotificationTypes.ConnectionLost | Connection failure |

| ChatNotificationTypes.ConversationEnded | Conversation-ended state |

| ChatNotificationTypes.SessionEnded | Session-ended state |

| ChatNotificationActionNames.CancelTransfer | Reset response-handler routing and remove transfer notification |

| ChatNotificationActionNames.EndSession | Close the session and show session-ended state |

Create a Custom Transport

ChatContextType is an enum with two values, AIChatSession and ChatInteraction, and the transport is resolved as a keyed service by that value. A custom transport therefore replaces the delivery for one of those two chat types, for example when a module serves profile chat from its own hub. Implement IChatNotificationTransport (SendNotificationAsync, UpdateNotificationAsync, RemoveNotificationAsync), broadcast to your hub's group, and register it for the chat type it serves:

public sealed class Startup : StartupBase
{
    public override void ConfigureServices(IServiceCollection services)
    {
        services.AddKeyedScoped<IChatNotificationTransport, MyChatNotificationTransport>(
            ChatContextType.AIChatSession);
    }
}

The built-in AIChatNotificationTransport and ChatInteractionNotificationTransport are internal. Do not replace them for ordinary profile and interaction notifications.

Security Checklist

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.