@microsoft/omnichannel-chat-sdk
Advanced tools
Comparing version 0.2.1-main.9b444a0 to 0.2.1-main.a41a521
@@ -8,2 +8,3 @@ # Changelog | ||
- Add `getCallingToken` | ||
- Send `ChannelId-lcw` message tag | ||
@@ -10,0 +11,0 @@ ## [0.2.0] - 2021-04-30 |
@@ -15,2 +15,5 @@ import ChatAdapterConfig from "./ChatAdapterConfig"; | ||
} | ||
interface ChatReconnectConfig { | ||
disable: boolean; | ||
} | ||
interface IChatSDKConfig { | ||
@@ -20,2 +23,3 @@ dataMasking?: IDataMaskingSDKConfig; | ||
persistentChat?: PersistentChatConfig; | ||
chatReconnect?: ChatReconnectConfig; | ||
getAuthToken?: () => Promise<string | null>; | ||
@@ -22,0 +26,0 @@ ic3Config?: IC3Config; |
@@ -12,2 +12,3 @@ import InitContext from "@microsoft/ocsdk/lib/Model/InitContext"; | ||
initContext?: InitContext; | ||
reconnectId?: string; | ||
} |
@@ -14,4 +14,6 @@ import IChatConfig from "./core/IChatConfig"; | ||
import IStartChatOptionalParams from "./core/IStartChatOptionalParams"; | ||
import LiveWorkItemDetails from "./core/LiveWorkItemDetails"; | ||
import OnNewMessageOptionalParams from "./core/OnNewMessageOptionalParams"; | ||
import LiveWorkItemDetails from "./core/LiveWorkItemDetails"; | ||
import ChatReconnectOptionalParams from "./core/ChatReconnectOptionalParams"; | ||
import ChatReconnectContext from "./core/ChatReconnectContext"; | ||
declare class OmnichannelChatSDK { | ||
@@ -40,6 +42,9 @@ private debug; | ||
private isPersistentChat; | ||
private isChatReconnect; | ||
private reconnectId; | ||
private refreshTokenTimer; | ||
constructor(omnichannelConfig: IOmnichannelConfig, chatSDKConfig?: IChatSDKConfig); | ||
setDebug(flag: boolean): void; | ||
initialize(): Promise<IChatConfig>; | ||
getChatReconnectContext(optionalParams?: ChatReconnectOptionalParams): Promise<ChatReconnectContext>; | ||
startChat(optionalParams?: IStartChatOptionalParams): Promise<void>; | ||
@@ -74,3 +79,4 @@ endChat(): Promise<void>; | ||
private resolveChatAdapterUrl; | ||
private updateChatToken; | ||
} | ||
export default OmnichannelChatSDK; |
@@ -25,3 +25,5 @@ declare enum TelemetryEvent { | ||
StopCall = "StopCall", | ||
OnCallDisconnected = "OnCallDisconnected" | ||
OnCallDisconnected = "OnCallDisconnected", | ||
UpdateChatToken = "UpdateChatToken", | ||
GetChatReconnectContext = "GetChatReconnectContext" | ||
} | ||
@@ -28,0 +30,0 @@ export declare const startEvent: (event: TelemetryEvent) => string; |
@@ -30,2 +30,4 @@ "use strict"; | ||
TelemetryEvent["OnCallDisconnected"] = "OnCallDisconnected"; | ||
TelemetryEvent["UpdateChatToken"] = "UpdateChatToken"; | ||
TelemetryEvent["GetChatReconnectContext"] = "GetChatReconnectContext"; | ||
})(TelemetryEvent || (TelemetryEvent = {})); | ||
@@ -32,0 +34,0 @@ exports.startEvent = function (event) { |
@@ -17,2 +17,5 @@ "use strict"; | ||
tokenUpdateTime: 21600000 | ||
}, | ||
chatReconnect: { | ||
disable: true, | ||
} | ||
@@ -19,0 +22,0 @@ }; |
{ | ||
"name": "@microsoft/omnichannel-chat-sdk", | ||
"version": "0.2.1-main.9b444a0", | ||
"version": "0.2.1-main.a41a521", | ||
"description": "Microsoft Omnichannel Chat SDK", | ||
@@ -5,0 +5,0 @@ "files": [ |
122
README.md
@@ -49,2 +49,4 @@ # Omnichannel Chat SDK | ||
| Proactive Chat | β | BYOI **\*** | | ||
| Persistent Chat | β | β | | ||
| Chat Reconnect | β | β | | ||
@@ -70,2 +72,3 @@ **\*** BYOI: Bring Your Own Implementation | ||
| OmnichannelChatSDK.getCurrentLiveChatContext() | Get current live chat context information to reconnect to the same chat | | | ||
| OmnichannelChatSDK.getChatReconnectContext() | Get current reconnectable chat context information to reconnect to a previous existing chat session | | | ||
| OmnichannelChatSDK.getConversationDetails() | Get details of the current conversation such as its state & when the agent joined the conversation | | | ||
@@ -118,2 +121,11 @@ | OmnichannelChatSDK.getChatToken() | Get chat token | | | ||
### Get Current Chat Reconnect Context | ||
```ts | ||
const optionalParams = { | ||
reconnectId: '', // reconnect Id | ||
}; | ||
const chatReconnectContext = await chatSDK.getChatReconnectContext(optionalParams); | ||
``` | ||
### Get Conversation Details | ||
@@ -357,2 +369,112 @@ ```ts | ||
### Persistent Chat | ||
```ts | ||
const chatSDKConfig = { | ||
persistentChat: { | ||
disable: false, | ||
tokenUpdateTime: 21600000 | ||
}, | ||
getAuthToken: async () => { | ||
const response = await fetch("http://contosohelp.com/token"); | ||
if (response.ok) { | ||
return await response.text(); | ||
} | ||
else { | ||
return null | ||
} | ||
} | ||
} | ||
const chatSDK = new OmnichannelChatSDK.OmnichannelChatSDK(omnichannelConfig, chatSDKConfig); | ||
await chatSDK.initialize(); | ||
// from this point, this acts like a persistent chat | ||
``` | ||
### Chat Reconnect with Authenticated User | ||
```ts | ||
const chatSDKConfig = { | ||
chatReconnect: { | ||
disable: false, | ||
}, | ||
getAuthToken: async () => { | ||
const response = await fetch("http://contosohelp.com/token"); | ||
if (response.ok) { | ||
return await response.text(); | ||
} | ||
else { | ||
return null | ||
} | ||
} | ||
} | ||
const chatSDK = new OmnichannelChatSDK.OmnichannelChatSDK(omnichannelConfig, chatSDKConfig); | ||
await chatSDK.initialize(); | ||
.... | ||
const chatReconnectContext = await chatSDK?.getChatReconnectContext(); | ||
if (chatReconnectContext.reconnectId) { | ||
// Add UX with options to reconnect to previous existing chat or start new chat | ||
} | ||
// Reconnect chat option | ||
const optionalParams = {}; | ||
optionalParams.reconnectId = chatReconnectContext.reconnectId; | ||
chatSDK.startChat(optionalParams); | ||
// Start new chat option | ||
chatSDK.startChat(); | ||
``` | ||
### Chat Reconnect with Unauthenticated User | ||
```ts | ||
const chatSDKConfig = { | ||
chatReconnect: { | ||
disable: false, | ||
}, | ||
} | ||
const chatSDK = new OmnichannelChatSDK.OmnichannelChatSDK(omnichannelConfig, chatSDKConfig); | ||
await chatSDK.initialize(); | ||
.... | ||
const optionalParams: any = {}; | ||
//retrieve the reconnect ID from the URL | ||
const retrieveReconnectId = function(): any { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
if (urlParams.get('oc.reconnectid') !== null) { | ||
return urlParams.get('oc.reconnectid'); | ||
} else { | ||
return null; | ||
} | ||
} | ||
const params = { | ||
reconnectId: retrieveReconnectId(), | ||
} | ||
const chatReconnectContext = await chatSDK?.getChatReconnectContext(params); | ||
// if the reconnect id is invalid or expired, redirect URL if there is any URL set in the configuration | ||
if (chatReconnectContext.redirectURL) { | ||
window.location.replace(chatReconnectContext.redirectURL); | ||
} | ||
// Valid reconnect id, reconnect to previous chat | ||
if (chatReconnectContext.reconnectId) { | ||
await chatSDK.startChat({ | ||
reconnectId: chatReconnectContext.reconnectId | ||
}); | ||
} else { // ReconnectId from URL is not valid, start new chat session | ||
await chatSDK.startChat(); | ||
} | ||
``` | ||
### Use [BotFramework-WebChat](https://github.com/microsoft/BotFramework-WebChat) | ||
@@ -359,0 +481,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
748416
198
9149
683
2530
10