agentleFS
MicrosoftKnown publishermicrosoft/omnichannel-chat-sdk/CLAUDE.md

omnichannel-chat-sdk

CLAUDE.md67 starsChanged 6 months agoMITView on GitHub

This workspace may contain up to 6 related repositories. Not all teams have all repos working together. Always be aware of which repository you're in when making changes. This repo already has comprehensive Copilot instructions. Read them ALL before any task: CRITICAL: All existing Copilot instructions apply to Claude Code as well. Follow them strictly. From copilot-instructions.md - MANDATORY: This repo follows a strict "ASK FIRST" protocol: 1. Understand the request and read relevant code 2. Propose specific changes with…

  • Deletes or force-pushes
  • Installs packages

The file

Show its rules and text

We split this CLAUDE.md into the rules it gives an agent

32 rules. About 0 are common, 23 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈23

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    CRITICAL: All existing Copilot instructions apply to Claude Code as well.

    line 33
  2. Distinctive:

    Implement: only after approval

    line 46
  3. Distinctive:

    Canonical process: Follow docs/RELEASING.md

    line 104
  4. Very specific:

    Prohibited: Do not run npm publish manually and do not use workflow dispatch for an official release

    line 107
  5. Very specific:

    Critical: Follow docs/copilot/CODING_GUIDELINES.md for all TypeScript code.

    line 113
  6. Very specific:

    Avoid any type: - Use proper type definitions

    line 118
  7. Distinctive:

    Explicit return types: - Always declare function return types

    line 120
  8. Distinctive:

    Purpose: Test against real MessagingRuntime APIs (test environment)

    line 205
  9. Distinctive:

    Test both happy path and error scenarios

    line 209
  10. Distinctive:

    Verify telemetry calls (startScenario, completeScenario, failScenario)

    line 210
  11. Very specific:

    Test cross-platform compatibility (Node.js, Browser environments)

    line 211
  12. Distinctive:

    Use semantic versioning: major version for breaking changes

    line 228
  13. Very specific:

    Code standards: Follow docs/copilot/CODING_GUIDELINES.md

    line 239
  14. Distinctive:

    Testing: All tests must pass, add tests for new functionality

    line 241
  15. Distinctive:

    Documentation: Update JSDoc comments, README.md if APIs change

    line 242
  16. Distinctive:

    CHANGELOG: Update CHANGELOG.md under [Unreleased] section:

    line 244
  17. Very specific:

    Run vsts-npm-auth -config .npmrc to refresh Azure DevOps authentication

    line 254
  18. Distinctive:

    Check internal npm feed access (requires permissions)

    line 255
  19. Very specific:

    Check Node version: node --version (must match engines in package.json)

    line 259
  20. Distinctive:

    Check if MessagingRuntime test environment is available

    line 262
  21. Distinctive:

    Verify test configuration in jest.config files

    line 263
  22. Very specific:

    Use npm run test:debug for debugging

    line 264
  23. Very specific:

    Ensure you're authenticated to npm registry: npm whoami

    line 267
  24. Distinctive:

    Check package version doesn't already exist

    line 268
  25. Distinctive:

    Verify no uncommitted changes: git status

    line 269
  26. Distinctive:

    Create tracking work item

    line 293
  27. Distinctive:

    Add new API (backwards-compatible)

    line 297
  28. Distinctive:

    Update CHANGELOG.md with migration guide

    line 299
  29. Distinctive:

    After 2 releases, remove old API (major version bump)

    line 300
  30. Distinctive:

    Update README.md with new API examples

    line 303
  31. Distinctive:

    Add migration guide to CHANGELOG.md

    line 304
  32. Distinctive:

    Update TypeScript type definitions

    line 305

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

omnichannel-chat-sdk - Claude Code Instructions

Repository Ecosystem

This workspace may contain up to 6 related repositories. Not all teams have all repos working together. Always be aware of which repository you're in when making changes.

RepositoryTypePurposeTypical Location
CRM.OmnichannelMonorepo (Backend)20+ microservices for Omnichannel platform<workspace-root>/CRM.Omnichannel/
ConversationControlFrontend (Agent UI)Agent experience and conversation management UI<workspace-root>/CRM.OmniChannel.ConversationControl/
LiveChatWidgetFrontend (Customer)Customer-facing chat widget<workspace-root>/CRM.OmniChannel.LiveChatWidget/
omnichannel-chat-sdkPublic SDKTypeScript SDK for chat integration<workspace-root>/omnichannel-chat-sdk/
omnichannel-chat-widgetPublic ComponentsReact component library<workspace-root>/omnichannel-chat-widget/
omnichannel-amsclientShared LibraryFile upload/download client<workspace-root>/omnichannel-amsclient/

Quick Context

  • Purpose: Public SDK for building custom chat experiences with Dynamics 365 Omnichannel
  • Type: TypeScript Library (npm package)
  • Tech Stack: TypeScript, Rollup, Jest, Playwright
  • Distribution: npm registry (@microsoft/omnichannel-chat-sdk)
  • Consumers: CRM.OmniChannel.LiveChatWidget, omnichannel-chat-widget, external customers

Memory Bank & Existing Instructions (Read First)

This repo already has comprehensive Copilot instructions. Read them ALL before any task:

  1. .github/copilot-instructions.md - ASK FIRST protocol, PR guidelines, coding standards
  2. docs/copilot/CODING_GUIDELINES.md - Essential patterns and requirements
  3. docs/copilot/PROMPT_TEMPLATES.md - Copilot prompt templates

CRITICAL: All existing Copilot instructions apply to Claude Code as well. Follow them strictly.


Authorization Protocol (ASK FIRST)

From copilot-instructions.md - MANDATORY:

This repo follows a strict "ASK FIRST" protocol:

  1. Understand the request and read relevant code
  2. Propose specific changes with file paths and code snippets
  3. Explain impact on consumers (LiveChatWidget, chat-widget, external customers)
  4. Wait for explicit approval ("yes", "proceed", "go")
  5. Implement only after approval

NEVER modify code without explicit user authorization.


Architecture Overview

What is omnichannel-chat-sdk?

This is the official TypeScript SDK for integrating Omnichannel chat into custom applications. It provides a strongly-typed API for chat operations (start chat, send message, end chat, file attachments) and abstracts the MessagingRuntime REST APIs.

Key Features:

  • Promise-based async API
  • TypeScript type definitions
  • Comprehensive error handling (ChatSDKExceptionDetails)
  • Telemetry integration (startScenario → completeScenario/failScenario)
  • Cross-platform support (Browser, Node.js, React Native)

Integration:

  • Backend: Consumes MessagingRuntime REST APIs (/api/messaging/v1/*)
  • ACS: Integrates with Azure Communication Services for chat threading
  • Consumers: LiveChatWidget, chat-widget, external customers (public npm)

Build & Test Workflow

Prerequisites

  • Node.js (version in package.json engines)
  • npm package manager
  • Authentication: vsts-npm-auth for Azure DevOps npm registry (internal dependencies)

Setup

cd omnichannel-chat-sdk

# Authenticate with Azure DevOps npm registry
vsts-npm-auth -config .npmrc

# Install dependencies
npm install

Common Commands

Build:

  • Build SDK: npm run build:tsc - TypeScript compilation
  • Bundle: npm run build - Rollup bundling (ESM, CJS, UMD)
  • Watch mode: npm run watch - Incremental development

Test:

  • Unit tests: npm test - Jest tests
  • E2E tests: npm run test:e2e - Playwright integration tests
  • Coverage: npm run coverage - Test coverage report
  • Lint: npm run lint - ESLint validation

Release:

  • Canonical process: Follow docs/RELEASING.md
  • Official release: Merge a release PR, then push v<version> on that exact merge commit
  • Automation: The tag publishes the package to npm and creates the GitHub Release with changelog notes and the exact npm tarball
  • Prohibited: Do not run npm publish manually and do not use workflow dispatch for an official release

Coding Standards

Critical: Follow docs/copilot/CODING_GUIDELINES.md for all TypeScript code.

Key Conventions from Copilot Instructions

TypeScript Best Practices:

  • Avoid any type - Use proper type definitions
  • Strict TypeScript - Enable strict mode in tsconfig.json
  • Explicit return types - Always declare function return types
  • Async/await preferred - Over .then() chains
  • Cross-platform compatibility - Code must work in Browser, Node.js, React Native

Telemetry Pattern (MANDATORY):

// ✅ CORRECT - startScenario → completeScenario/failScenario pattern
async sendMessage(message: string): Promise<void> {
    this.telemetry.startScenario('SendMessage');
    try {
        const response = await this.httpClient.post('/api/messaging/v1/messages/send', {
            conversationId: this.conversationId,
            content: message
        });
        this.telemetry.completeScenario('SendMessage');
    } catch (error) {
        this.telemetry.failScenario('SendMessage', error);
        throw new ChatSDKError('Failed to send message', error);
    }
}

Error Handling (MANDATORY):

// Use ChatSDKExceptionDetails structure
export interface ChatSDKExceptionDetails {
    message: string;
    errorCode: string;
    innerError?: Error;
    context?: Record<string, unknown>;
}

// Example usage
throw new ChatSDKError({
    message: 'Failed to start chat',
    errorCode: 'START_CHAT_FAILED',
    innerError: error,
    context: { chatConfig }
});

Method Structure:

// Standard async method pattern
export async function methodName(
    param1: Type1,
    param2: Type2,
    optionalConfig?: OptionalType
): Promise<ReturnType> {
    // 1. Validate inputs
    if (!param1) {
        throw new ChatSDKError({ message: 'param1 is required', errorCode: 'INVALID_INPUT' });
    }

    // 2. Start telemetry scenario
    this.telemetry.startScenario('MethodName');

    try {
        // 3. Business logic
        const result = await this.performOperation(param1, param2);

        // 4. Complete telemetry
        this.telemetry.completeScenario('MethodName');

        return result;
    } catch (error) {
        // 5. Fail telemetry and rethrow
        this.telemetry.failScenario('MethodName', error);
        throw new ChatSDKError({ message: 'Operation failed', errorCode: 'OPERATION_FAILED', innerError: error });
    }
}

Testing Strategy

Unit Tests (Jest):

  • Location: __tests__/ directory
  • Run: npm test
  • Coverage: Maintain >80% coverage for business logic

E2E Tests (Playwright):

  • Location: playwright/ directory
  • Run: npm run test:e2e
  • Purpose: Test against real MessagingRuntime APIs (test environment)

Test Best Practices:

  • Mock external dependencies (HTTP client, telemetry)
  • Test both happy path and error scenarios
  • Verify telemetry calls (startScenario, completeScenario, failScenario)
  • Test cross-platform compatibility (Node.js, Browser environments)

Integration with Other Repos

This SDK integrates with:

  • CRM.Omnichannel (Backend): MessagingRuntime REST APIs for chat operations
  • Azure Communication Services: Chat thread management (abstracted by backend)

Consumed by:

  • CRM.OmniChannel.LiveChatWidget (npm dependency) - Customer chat widget
  • omnichannel-chat-widget (npm peer dependency) - Shared React components
  • External customers (public npm) - Custom chat integrations

When changing public APIs:

  • This is a public contract - breaking changes affect external customers
  • Use semantic versioning: major version for breaking changes
  • Coordinate with LiveChatWidget and chat-widget teams
  • Provide migration guide in CHANGELOG.md
  • Announce breaking changes in release notes

Pull Request Guidelines

From copilot-instructions.md:

  1. Code standards: Follow docs/copilot/CODING_GUIDELINES.md
  2. Commit messages: Conventional commit format (feat:, fix:, chore:, etc.)
  3. Testing: All tests must pass, add tests for new functionality
  4. Documentation: Update JSDoc comments, README.md if APIs change
  5. Authorization: Get explicit approval before implementing
  6. CHANGELOG: Update CHANGELOG.md under [Unreleased] section:
    • Fixed: for bugs
    • Changed: for improvements or modified functionality
    • Added: for new features or components

Common Issues & Troubleshooting

Authentication Issues:

  • Run vsts-npm-auth -config .npmrc to refresh Azure DevOps authentication
  • Check internal npm feed access (requires permissions)

Build Issues:

  • Clear node_modules: rm -rf node_modules && npm install
  • Check Node version: node --version (must match engines in package.json)

Test Failures:

  • Check if MessagingRuntime test environment is available
  • Verify test configuration in jest.config files
  • Use npm run test:debug for debugging

Publish Issues:

  • Ensure you're authenticated to npm registry: npm whoami
  • Check package version doesn't already exist
  • Verify no uncommitted changes: git status

Documentation

  • README.md - SDK usage, API reference, examples
  • CHANGELOG.md - Release history, breaking changes
  • docs/copilot/ - Copilot coding guidelines and templates
  • docs/ - Additional documentation

Breaking Change Protocol

Before making breaking changes to public APIs:

  1. Identify impact:
    • LiveChatWidget dependency (check package.json version)
    • chat-widget dependency (peer dependency)
    • External customers (check npm download stats)
  2. Coordination:
    • Notify LiveChatWidget and chat-widget teams
    • Create tracking work item
    • Plan migration timeline (minimum 2 release cycles for deprecation)
  3. Implementation:
    • Add new API (backwards-compatible)
    • Mark old API as @deprecated in JSDoc
    • Update CHANGELOG.md with migration guide
    • After 2 releases, remove old API (major version bump)
  4. Documentation:
    • Update README.md with new API examples
    • Add migration guide to CHANGELOG.md
    • Update TypeScript type definitions

Summary: This is a public SDK with strict ASK FIRST protocol. Follow existing Copilot instructions, maintain telemetry patterns, use ChatSDKExceptionDetails for errors, and coordinate breaking changes with consumers.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.