Skip to content

Commit 304790f

Browse files
authored
Merge pull request #409 from elopezanaya/extend-getchat-token
Extend getchat token : pass Ms-Oc-Bot-Application-Id
2 parents af05a10 + 344d83e commit 304790f

File tree

5 files changed

+60
-8
lines changed

5 files changed

+60
-8
lines changed

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,47 @@ const optionalParams = {
243243
await chatSDK.initialize(optionalParams);
244244
```
245245

246+
## Passing cpsBotId on initialization
247+
248+
cpsBotId in UUID format, when present will use v4 for GetchatToken. (Limited to enabled orgs) establishing the connection with Copilot Bot specified.
249+
250+
### Scenarios
251+
252+
- if bot id is present and valid, SDK will use `V4` for `GetchatToken` establishing the connection with the dessired Copilot Bot.
253+
- if bot Id is not present, flow will continue using `V2` for `GetchatToken`
254+
- if bot Id is not in valid format, expect a `400 HTTP Response Error Code`
255+
- if bot Id is not enabled for the workstream, expect `403 HTTP Response Error Code`
256+
257+
```ts
258+
259+
import OmnichannelChatSDK from '@microsoft/omnichannel-chat-sdk';
260+
261+
const omnichannelConfig = {
262+
orgUrl: "",
263+
orgId: "",
264+
widgetId: "",
265+
cpsBotId: ""
266+
};
267+
268+
const chatSDKConfig = { // Optional
269+
dataMasking: {
270+
disable: false,
271+
maskingCharacter: '#'
272+
}
273+
};
274+
275+
const chatSDK = new OmnichannelChatSDK.OmnichannelChatSDK(omnichannelConfig, chatSDKConfig);
276+
277+
const optionalParams = {
278+
getLiveChatConfigOptionalParams: {
279+
sendCacheHeaders: false // Whether to send Cache-Control HTTP header to GetChatConfig call
280+
}
281+
};
282+
283+
await chatSDK.initialize(optionalParams);
284+
285+
```
286+
246287
### Start Chat
247288

248289
It starts an Omnichannel conversation.

package-lock.json

+8-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@azure/communication-chat": "1.5.4",
4949
"@azure/communication-common": "2.3.1",
5050
"@microsoft/botframework-webchat-adapter-azure-communication-chat": "^0.0.1-beta.2",
51-
"@microsoft/ocsdk": "^0.5.13",
51+
"@microsoft/ocsdk": "^0.5.14",
5252
"@microsoft/omnichannel-amsclient": "^0.1.8",
5353
"@microsoft/omnichannel-ic3core": "^0.1.5"
5454
}

src/OmnichannelChatSDK.ts

+9
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class OmnichannelChatSDK {
153153
private AMSClientLoadCurrentState: AMSClientLoadStates = AMSClientLoadStates.NOT_LOADED;
154154
private isMaskingDisabled = false;
155155
private maskingCharacter = "#";
156+
private botCSPId: string | null = null;
156157
private isAMSClientAllowed = false;
157158

158159
constructor(omnichannelConfig: OmnichannelConfig, chatSDKConfig: ChatSDKConfig = defaultChatSDKConfig) {
@@ -208,6 +209,10 @@ class OmnichannelChatSDK {
208209
this.maskingCharacter = this.chatSDKConfig.dataMasking.maskingCharacter;
209210
}
210211

212+
if (omnichannelConfig.cpsBotId) {
213+
this.botCSPId = omnichannelConfig.cpsBotId;
214+
}
215+
211216
loggerUtils.setRequestId(this.requestId, this.ocSdkLogger, this.acsClientLogger, this.acsAdapterLogger, this.callingSdkLogger, this.amsClientLogger, this.ic3ClientLogger);
212217
}
213218

@@ -1148,6 +1153,10 @@ class OmnichannelChatSDK {
11481153
getChatTokenOptionalParams.refreshToken = optionalParams?.refreshToken;
11491154
}
11501155

1156+
if (this.botCSPId) {
1157+
getChatTokenOptionalParams.MsOcBotApplicationId = this.botCSPId;
1158+
}
1159+
11511160
const chatToken = await this.OCClient.getChatToken(this.requestId, getChatTokenOptionalParams);
11521161
this.setChatToken(chatToken)
11531162
this.scenarioMarker.completeScenario(TelemetryEvent.GetChatToken, {

src/core/OmnichannelConfig.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export default interface OmnichannelConfig {
22
orgId: string;
33
orgUrl: string;
44
widgetId: string;
5+
cpsBotId?: string;
56
}

0 commit comments

Comments
 (0)