omnichannel-amsclient
CLAUDE.md8 starsChanged 4 months agoMITView on GitHub
Two-mode client selected by framedMode config flag: FramedClient loads a hidden iframe ({baseUrl}/{version}/iframe.html) containing IframeCommunicator. All AMS API calls execute inside the iframe. Host ↔ iframe communication via postMessage with request/response pattern and UUID-based request correlation. FramedlessClient calls API.ts functions directly via fetch. API layer (API.ts): Five functions — skypeTokenAuth, createObject, uploadDocument, getViewStatus, getView. Auth via skype_token header. AMS endpoint from chatToken.amsEndpoint || chatToken.regionGTMS?.ams.
- Installs packages
The file
Files
omnichannel-amsclient — Claude Code Instructions
Quick Context
- Package:
@microsoft/omnichannel-amsclientv0.1.12 - Purpose: File upload/download client for Omnichannel conversations via Azure Messaging Services (AMS)
- Tech: TypeScript, esbuild (CDN), TSC (npm), Jest, ESLint
- Zero runtime dependencies
- Consumers: omnichannel-chat-sdk (primary), chat-widget (via SDK), ConversationControl (agent UI)
Architecture
Two-mode client selected by framedMode config flag:
createAMSClient(config)
├── framedMode: true → FramedClient (browser — iframe isolation + postMessage)
└── framedMode: false → FramedlessClient (Node.js / React Native — direct fetch)FramedClient loads a hidden iframe ({baseUrl}/{version}/iframe.html) containing IframeCommunicator. All AMS API calls execute inside the iframe. Host ↔ iframe communication via postMessage with request/response pattern and UUID-based request correlation.
FramedlessClient calls API.ts functions directly via fetch.
API layer (API.ts): Five functions — skypeTokenAuth, createObject, uploadDocument, getViewStatus, getView. Auth via skype_token header. AMS endpoint from chatToken.amsEndpoint || chatToken.regionGTMS?.ams.
Source File Map
src/
├── index.ts # Entry — exports createAMSClient, sets CDN global
├── createAMSClient.ts # Factory — returns FramedClient or FramedlessClient
├── API.ts # AMS REST calls (skypeTokenAuth, CRUD operations)
├── FramedClient.ts # Browser client (iframe + postMessage, 400 lines)
├── FramedlessClient.ts # Node/RN client (direct fetch, 270 lines)
├── IframeCommunicator.ts # Runs inside iframe, bridges postMessage ↔ API (317 lines)
├── AMSError.ts # Error class (extends Error + requestUrl + originalError)
├── AMSLogger.ts # Logger wrapper (delegates to PluggableLogger)
├── GlobalConfiguration.ts # Static config (silentError, debug)
├── config.ts # Build-time config (baseUrl, sdkVersion — overwritten by esbuild)
├── telemetry/
│ ├── ScenarioMarker.ts # Start/complete/fail tracking with elapsed time
│ ├── EventMarker.ts # Event name suffixing (Started/Completed/Failed)
│ └── StopWatch.ts # Simple elapsed time measurement
├── utils/
│ ├── platform.ts # isBrowser/isNode/isReactNative detection
│ ├── uuid.ts # UUID v4 generator (Math.random based)
│ ├── extractFileExtension.ts # path.extname() equivalent (no path module dependency)
│ ├── fetchClientId.ts # Read clientId from iframe URL params
│ ├── fetchDebugConfig.ts # Read debug flag from iframe URL params
│ └── fetchTelemetryConfig.ts # Read telemetry flag from iframe URL params
└── [type files] # Interfaces/enums (see below)Type Files
| File | Type | Key Fields |
OmnichannelChatToken.ts | interface | chatId, token, regionGTMS, amsEndpoint |
FileMetadata.ts | interface | id, type, name?, size?, url? |
AMSCreateObjectResponse.ts | interface | id |
AMSUploadDocumentResponse.ts | interface | id, name, size, type, url, fileSharingProtocolType |
AMSViewStatusResponse.ts | interface | view_location, content_state, view_state, view_length |
AMSFileInfo.ts | interface | name, type, size, data (ArrayBuffer) |
AMSLogData.ts | interface | AMSClientRuntimeId, ChatId, Event, AMSClientVersion |
PluggableLogger.ts | interface | logClientSdkTelemetryEvent(logLevel, event) |
InitConfig.ts | interface | chatToken |
FramedClientConfig.ts | interface | multiClient?, baseUrl? |
PostMessageRequestData.ts | interface | requestId?, file?, chatToken?, documentId?, fileMetadata? |
LogLevel.ts | enum | INFO, DEBUG, WARN, ERROR, LOG |
PostMessageEventName.ts | enum | IframeLoaded, SkypeTokenAuth, CreateObject, UploadDocument, GetViewStatus, GetView, SendTelemetry |
PostMessageEventType.ts | enum | None, Request, Response |
PostMessageEventStatus.ts | enum | None, Success, Failure |
FramedClientEventName.ts | enum | Setup, Initialize, LoadIframe |
Build & Test
npm install
npm run build:tsc # TSC → lib/ (CJS output, type declarations)
npm test # Jest (ts-jest, node environment)
npm run lint # ESLint with @typescript-eslintCDN build (requires env vars):
npm run build:tsc
BASE_URL=https://[blob-url] SDK_VERSION=[version] node ./esbuild.config.js
# Outputs: dist/SDK.js, dist/SDK.min.js, dist/iframe.js, dist/iframe.min.js, dist/iframe.htmlCI: GitHub Actions — PR (build:tsc + test + lint on Node 22), Release (CDN upload to Azure Blob Storage + npm publish). Azure Pipelines for Component Governance scan.
Key Patterns
Auth
Skype token auth: Authorization: skype_token {token} header on all AMS requests. Authenticated via POST /v1/skypetokenauth.
AMS Endpoint Resolution
chatToken.amsEndpoint || chatToken.regionGTMS?.amsFallback: https://us-api.asm.skype.com (hardcoded in patchChatToken()).
Image vs Document API Paths
MIME type determines the AMS API path:
- Image (jpeg/png/gif/heic/webp):
pish/imagefor create,imgpshfor upload,imgpsh_fullsize_animfor view - Document (everything else):
sharing/filefor create,originalfor upload/view
Telemetry
ScenarioMarker emits three events per operation:
{Operation}Started— on entry{Operation}Completed— on success (with ElapsedTimeInMilliseconds){Operation}Failed— on error (with ExceptionDetails)
Telemetry flows through AMSLogger → PluggableLogger.logClientSdkTelemetryEvent(). In framed mode, telemetry is forwarded from iframe to parent via SendTelemetry postMessage events.
Error Handling
AMSError extends Error with requestUrl and originalError. API methods throw AMSError with descriptive messages. GlobalConfiguration.silentError controls whether errors are logged to console.
FramedClient Iframe Lifecycle
NotLoaded → Loading → Loaded
→ FailedIframe is loaded once, reused across operations. dispose() removes the iframe and resets state to NotLoaded.
Known Quirks
config.ts—baseUrlandsdkVersionare placeholder values overwritten at CDN build time byesbuild.config.js(which writes tolib/config.js).patchChatToken()in API.ts mutates the chatToken object in-place on every API call.typeof window === undefinedinindex.ts— missing quotes (should be=== 'undefined'). The IIFE always executes.silentErrordefault —config.silentError || truein createAMSClient always evaluates totrue.- IframeCommunicator
postMessage('*')— uses wildcard origin for messages to parent window. - Dead code — Commented-out
uploadFile()anddownloadFile()in FramedlessClient.
Documentation
README.md— Usage guide, API reference, development setupCLAUDE.md— This file (developer reference for Claude Code)docs/CHANGELOG.md— Release historydocs/CODE_OF_CONDUCT.md— Microsoft Open Source Code of Conductdocs/SECURITY.md— Security vulnerability reportingdocs/SUPPORT.md— Support information
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
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.

