-
Notifications
You must be signed in to change notification settings - Fork 396
docs(calling): Spark 787604 call flow specs #4780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Kesari3008
merged 14 commits into
webex:next
from
Kesari3008:SPARK-787604-Call-Flow-Specs
Apr 6, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
90c45d8
docs(calling): root level specs for calling packages
Kesari3008 bc9c0e0
docs(calling): calling folderbspecs covering call flows
Kesari3008 73e787e
docs(calling): latest next merge
Kesari3008 49e6e88
docs(calling): improvements
Kesari3008 bd0725c
docs(calling): small fixes
Kesari3008 bfd7a8f
Merge branch 'next' into SPARK-787604-Call-Flow-Specs
rarajes2 c8eb7eb
Merge branch 'next' of github.com:webex/webex-js-sdk into SPARK-78760…
Kesari3008 0118564
docs(calling): review comments
Kesari3008 be44aad
Merge branch 'SPARK-787604-Call-Flow-Specs' of github.com:Kesari3008/…
Kesari3008 1602b12
docs(calling): review comments
Kesari3008 abe58dc
docs(calling): few more fixes
Kesari3008 5ea1cb9
docs(calling): latest code merge
Kesari3008 2e1f954
docs(calling): removing old unnecessary files
Kesari3008 c6deeeb
docs(calling): review comments
Kesari3008 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
packages/calling/src/CallingClient/calling/CallerId/ai-docs/AGENTS.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| # CallerId Sub-Module - Agent Specification | ||
|
|
||
| ## Overview | ||
|
|
||
| The `CallerId` sub-module resolves caller identity for a `Call` using SIP-style headers delivered by Mobius signaling events. It provides immediate, best-effort display information from headers and then performs asynchronous enrichment through SCIM lookup when BroadWorks metadata includes an `externalId`. | ||
|
|
||
| This module is intentionally small and stateful: | ||
| - `fetchCallerDetails()` is the public entrypoint. | ||
| - It resets and repopulates internal `callerInfo` for each resolution request. | ||
| - It emits updates via a callback when new identity data becomes available. | ||
|
|
||
| --- | ||
|
|
||
| ## Key Capabilities | ||
|
|
||
| ### 1. Deterministic Header Priority Resolution | ||
| - Parses `p-asserted-identity` first (highest preference). | ||
| - Uses `from` header as fallback for missing fields. | ||
| - Maintains predictable precedence for name/number population. | ||
|
|
||
| ### 2. SIP URI Parsing for Name/Number | ||
| - Extracts display name from quoted/header prefix. | ||
| - Extracts number from SIP URI local part. | ||
| - Validates parsed phone tokens using `VALID_PHONE_REGEX`. | ||
|
|
||
| ### 3. Async SCIM Enrichment from BroadWorks Data | ||
| - Parses `x-broadworks-remote-party-info`. | ||
| - Detects `externalId` and issues SCIM-driven resolution through `resolveCallerIdDisplay()`. | ||
| - Upgrades interim caller details with richer profile fields (`name`, `num`, `avatarSrc`, `id`) when available. | ||
|
|
||
| ### 4. Incremental Event-Style Updates | ||
| - Emits initial caller info early when header parsing yields usable values. | ||
| - Emits again only when async resolution actually changes fields. | ||
| - Avoids noisy duplicate emissions by checking diffs before callback. | ||
|
|
||
| ### 5. Logging and Failure Tolerance | ||
| - Logs parsing/resolution steps with `{file, method}` context. | ||
| - Continues gracefully when external ID is missing or SCIM enrichment fails. | ||
| - Preserves best-known caller info instead of failing hard. | ||
|
|
||
| --- | ||
|
|
||
| ## Files | ||
|
|
||
| | File | Primary Symbol(s) | Description | | ||
| |------|--------------------|-------------| | ||
| | `index.ts` | `CallerId`, `createCallerId` | Main implementation and factory for caller ID resolution | | ||
| | `types.ts` | `ICallerId`, helper types | Public contract for caller detail resolution | | ||
| | `index.test.ts` | Jest tests | Priority, fallback, and async enrichment behavior validation | | ||
|
|
||
| --- | ||
|
|
||
| ## Public API | ||
|
|
||
| ## Factory Function | ||
|
|
||
| ```typescript | ||
| export const createCallerId = (webex: WebexSDK, emitterCb: CallEmitterCallBack): ICallerId => | ||
| new CallerId(webex, emitterCb); | ||
| ``` | ||
|
|
||
| ## ICallerId Interface | ||
|
|
||
| `ICallerId` is the contract consumed by `Call`. It defines a single entrypoint that returns immediate display info while potentially triggering async updates through the emitter callback. | ||
|
|
||
| ```typescript | ||
| export interface ICallerId { | ||
| fetchCallerDetails: (callerId: CallerIdInfo) => DisplayInformation; | ||
| } | ||
| ``` | ||
|
|
||
| ## CallerId Class | ||
|
|
||
| ### Constructor | ||
|
|
||
| ```typescript | ||
| constructor(webex: WebexSDK, emitter: CallEmitterCallBack) | ||
| ``` | ||
|
|
||
| Responsibilities: | ||
| - Ensures `SDKConnector` has a valid Webex instance. | ||
| - Initializes internal mutable `callerInfo`. | ||
| - Stores emitter callback for incremental caller ID updates. | ||
|
|
||
| ### Core Methods | ||
|
|
||
| | Method | Visibility | Purpose | | ||
| |--------|------------|---------| | ||
| | `fetchCallerDetails(callerId)` | Public | Main entrypoint: resets fields, applies header priority parsing, emits initial data, triggers async BroadWorks enrichment | | ||
| | `parseSipUri(paid)` | Private | Parses name and number from SIP-like header string | | ||
| | `parseRemotePartyInfo(data)` | Private | Extracts BroadWorks `externalId` and starts SCIM lookup | | ||
| | `resolveCallerId(filter)` | Private async | Performs SCIM enrichment and emits only when resolved fields differ | | ||
|
|
||
| --- | ||
|
|
||
| ## Resolution Rules (Source of Truth) | ||
|
|
||
| 1. Reset `callerInfo` (`id`, `avatarSrc`, `name`, `num`) before processing a new event. | ||
| 2. If `p-asserted-identity` exists, parse and set `name`/`num` directly (highest priority). | ||
| 3. If `from` exists, parse and fill only fields still unset by step 2. | ||
| 4. Emit immediate caller update if `name` or `num` is available. | ||
| 5. If `x-broadworks-remote-party-info` exists, parse `externalId` and run async SCIM enrichment. | ||
| 6. During enrichment, update only changed fields and emit callback only when at least one field changed. | ||
|
|
||
| --- | ||
|
|
||
| ## Control Flow | ||
|
|
||
| ```mermaid | ||
| flowchart TD | ||
| A[fetchCallerDetails CallerIdInfo] --> B[Reset callerInfo fields] | ||
| B --> C{Has p-asserted-identity?} | ||
| C -- Yes --> D[parseSipUri PAI and set name/num] | ||
| C -- No --> E | ||
| D --> E{Has from header?} | ||
| E -- Yes --> F[parseSipUri from and fill missing fields only] | ||
| E -- No --> G | ||
| F --> G{Has name or num?} | ||
| G -- Yes --> H[emit interim callerInfo] | ||
| G -- No --> I | ||
| H --> I{Has x-broadworks-remote-party-info?} | ||
| I -- Yes --> J[parseRemotePartyInfo] | ||
| I -- No --> M[Return current callerInfo] | ||
| J --> K{externalId found?} | ||
| K -- Yes --> L[resolveCallerId SCIM query] | ||
| K -- No --> M | ||
| L --> N{Any field changed?} | ||
| N -- Yes --> O[emit enriched callerInfo] | ||
| N -- No --> M | ||
| O --> M | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Testing Expectations | ||
|
|
||
| Tests for this module should cover: | ||
| - Header precedence: `p-asserted-identity` over `from`. | ||
| - Fallback behavior when one/both SIP fields are partially missing. | ||
| - Async overwrite by BroadWorks+SCIM enrichment when `externalId` is present. | ||
| - No overwrite when `externalId` is absent. | ||
| - SCIM failure path preserves already-resolved interim details. | ||
| - Emission behavior: | ||
| - Interim emit when `name`/`num` exists. | ||
| - Follow-up emit only when enrichment changes fields. | ||
|
|
||
| --- | ||
|
|
||
| ## Agent Rules for Code Generation | ||
|
|
||
| When implementing or modifying `CallerId`: | ||
| - Keep `fetchCallerDetails()` as the only public resolution entrypoint. | ||
| - Preserve the strict precedence order: `p-asserted-identity` -> `from` -> BroadWorks enrichment. | ||
| - Keep enrichment non-blocking for initial caller identity delivery. | ||
| - Do not introduce direct event emitter dependencies; continue using `CallEmitterCallBack`. | ||
| - Use existing logger conventions with `{file, method}` metadata. | ||
| - Reuse `DisplayInformation` and `CallerIdInfo` types (no duplicate local types). | ||
| - Keep parsing and enrichment side effects minimal and explicit. | ||
|
|
||
| ### Do Not | ||
| - Do not replace the callback-based update mechanism with direct `Call` mutations. | ||
| - Do not block return of interim caller details while waiting for SCIM lookup. | ||
| - Do not emit duplicate callbacks when resolved data is unchanged. | ||
| - Do not weaken validation around parsed number fields. | ||
|
|
||
| --- | ||
|
|
||
| ## Quick Validation Checklist | ||
|
|
||
| - [ ] `createCallerId()` still returns `ICallerId`. | ||
| - [ ] `fetchCallerDetails()` resets stale state before processing input. | ||
| - [ ] Header parsing order and fallback semantics remain unchanged. | ||
| - [ ] BroadWorks `externalId` parsing still triggers async SCIM lookup. | ||
| - [ ] Callback emissions occur for interim and changed enriched data only. | ||
| - [ ] Existing `index.test.ts` scenarios remain valid or are updated with behavior-preserving intent. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to create separate AGENTS.md for
CallerIdsince it's pretty small ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why I have not added ARCHITECTURE.md for this. But method details and how this component is designed has to be added somewhere so keeping AGENTS.md file for that reason