|
| 1 | +--- |
| 2 | +title: Tutorial on how to pass call contextual data information using your Azure Communication Services WebJS SDK |
| 3 | +titleSuffix: An Azure Communication Services tutorial document |
| 4 | +description: Provides a tutorial guide for passing contextual information using |
| 5 | +author: sloanster |
| 6 | +ms.topic: tutorial |
| 7 | +ms.service: azure-communication-services |
| 8 | +ms.date: 09/10/2024 |
| 9 | +ms.author: micahvivion |
| 10 | +services: azure-communication-services |
| 11 | +--- |
| 12 | + |
| 13 | +# How to pass contextual data between calls |
| 14 | + |
| 15 | +The ACS WebJS SDK allows developers to pass along custom contextual information when routing calls. Developers can pass metadata about the call, callee or any other information that is relevant to their application or business logic. This allows businesses to manage, and route calls across networks without having to worry about losing context. |
| 16 | + |
| 17 | +Passing context is supported by specifying custom headers. These are an optional list of key-value pairs that can be included as part of `AddParticipant` or `Transfer` actions. The context can be later retrieved as part of the `IncomingCall` event payload. |
| 18 | + |
| 19 | +Custom call context is also forwarded to the SIP protocol, this includes both the freeform custom headers as well as the standard User-to-User Information (UUI) SIP header. When routing an inbound call from your telephony network, the data set from your SBC in the custom headers and UUI is similarly included in the `IncomingCall` event payload. |
| 20 | + |
| 21 | +All custom context data is opaque to the calling SDK and when used in SIP protocols and its content is unrelated to any basic functions. |
| 22 | + |
| 23 | +Below are samples on how to get started using custom context headers using the WebJS SDK. |
| 24 | + |
| 25 | +## Technical parameters |
| 26 | +The calling SDK support adding up to 5 custom SIP headers and 1000 custom VOIP headers. Additionally, developers can include a dedicated User-To-User header as part of SIP headers list. |
| 27 | + |
| 28 | +The custom SIP header key must start with a mandatory ‘X-MS-Custom-’ prefix. The maximum length of a SIP header key is 64 chars, including the X-MS-Custom prefix. The SIP header key may consist of alphanumeric characters and a few selected symbols which includes `.`, `!`, `%`, `*`, `_`, `+`, `~`, `-`. The maximum length of SIP header value is 256 chars. The same limitations apply when configuring the SIP headers on your SBC. The SIP header value may consist of alphanumeric characters and a few selected symbols which includes `=`, `;`, `.`, `!`, `%`, `*`, `_`, `+`, `~`, `-`. |
| 29 | + |
| 30 | +The maximum length of a VOIP header key is 64 chars. These headers can be sent without ‘x-MS-Custom’ prefix. The maximum length of VOIP header value is 1024 chars. |
| 31 | + |
| 32 | +## Adding custom context when inviting a participant |
| 33 | + |
| 34 | +### Setting custom context. |
| 35 | + |
| 36 | +```js |
| 37 | + |
| 38 | + const callOptions = { |
| 39 | + customContext: { |
| 40 | + voipHeaders: [ |
| 41 | + {key: 'voip-key-1', value: 'voip-value-1'}, |
| 42 | + {key: 'voip-key-2', value: 'voip-value-2'} |
| 43 | + ], |
| 44 | + // Sip headers have a max limit of 5 headers. |
| 45 | + // SDK is prefixing them with 'x-ms-client-' to avoid conflicts with existing headers. |
| 46 | + sipHeaders: [ |
| 47 | + {key: 'sip-key-1', value: 'sip-value-1'}, |
| 48 | + {key: 'sip-key-2', value: 'sip-value-2'} |
| 49 | + ], |
| 50 | + userToUser: 'userToUserHeader', |
| 51 | + }, |
| 52 | + }; |
| 53 | + |
| 54 | + // you can specify only sipHeaders or voipHeaders or both. |
| 55 | + |
| 56 | + // starting a call with custom context. |
| 57 | + callAgent.startCall("USER_ID", callOptions); |
| 58 | + |
| 59 | + // adding participant to existing call or transfer with custom context. |
| 60 | + call.addParticipant("USER_ID", callOptions); |
| 61 | + |
| 62 | + // Parsing custom context on the receiver side. |
| 63 | + |
| 64 | + let info = ''; |
| 65 | + |
| 66 | + callAgent.on("incomingCall", (args) => { |
| 67 | + const incomingCall = args.incomingCall; |
| 68 | + if (incomingCall.customContext) { |
| 69 | + if (incomingCall.customContext.userToUser) { |
| 70 | + info += `userToUser: '${incomingCall.customContext.userToUser}'\n`; |
| 71 | + } |
| 72 | + if (incomingCall.customContext.sipHeaders) { |
| 73 | + incomingCall.customContext.sipHeaders.forEach(header => info += `sip: ${header.key}: '${header.value}'\n`); |
| 74 | + } |
| 75 | + if (incomingCall.customContext.voipHeaders) { |
| 76 | + incomingCall.customContext.voipHeaders.forEach(header => info += `voip: ${header.key}: '${header.value}'\n`); |
| 77 | + } |
| 78 | + } |
| 79 | + }); |
| 80 | + |
| 81 | +``` |
| 82 | + |
| 83 | +## Reading custom context from an incoming call event |
| 84 | + |
| 85 | + |
| 86 | +## Additional resources |
| 87 | + |
| 88 | +- For a sample payload of the incoming call, refer to this [guide](../../../event-grid/communication-services-voice-video-events.md#microsoftcommunicationincomingcall). |
| 89 | + |
| 90 | +- Learn more about [SIP protocol details for direct routing](../../concepts/telephony/direct-routing-sip-specification.md). |
0 commit comments