包详细信息

@microsoft/ocsdk

microsoft14.6kMIT0.5.20-main.c747daa

Microsoft Omnichannel SDK

自述文件

Omnichannel SDK

npm version Release CI

This repo contains the source code for getting up and running with the Omnichannel SDK on the web using standard web technologies and on mobile using React Native.

Getting Started

Prerequisites

Installation

npm install

Build

Load SDK in memory and watches the changes for development

npm run watch

Build SDK for development

npm run build:dev

Build SDK for production

npm run build:prod

Check lint rules

npm run lint
```console
Lint checks is enabled by default in watch mode.

# Examples

### Initialize SDK

```js
const params = {
 orgUrl: '',
 orgId: '',
 widgetId: '',
}

const ocsdk = Microsoft.CRM.Omnichannel.SDK.SDKProvider.getSDK(params);
window.ocsdk = ocsdk;

Initialize SDK with custom configuration

const params = {
 orgUrl: '',
 orgId: '',
 widgetId: '',
}

const configuration = {
  getChatTokenRetryCount: 35,
  getChatTokenTimeBetweenRetriesOnFailure: 10000,
  maxRequestRetriesOnFailure: 5
};

const ocsdk = Microsoft.CRM.Omnichannel.SDK.SDKProvider.getSDK(params, configuration);
window.ocsdk = ocsdk;

Get Chat Config

// Manually generate request id
const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
try {
 const config = await window.ocsdk.getChatConfig(requestId);
 // success
} catch {
 // failure
}

// Auto generate request id
try {
 const config = await window.ocsdk.getChatConfig();
 // success
} catch {
 // failure
}

Get Chat Token

// Manually generate request id
const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
try {
 const chatToken = await window.ocsdk.getChatToken(requestId);
 // success
} catch {
 // failure
}

// Auto generate request id
try {
  const chatToken = await window.ocsdk.getChatToken();
  const {requestId} = chatToken; // Request ID auto generated used to getChatToken
  // success
} catch {
  // failure
}

Session Init

const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
const optionalParams = {
  authenticatedUserToken: '',
  getContext: true, // Automically gets browser, device, location & os info
  initContext: { // Optional init context to pass
    locale: '', // 'en-us' by default if not set
    originalurl: '', // window.href.location by default
    os: '',
    browser: '',
    device: '',
    longitude: '',
    latitiude: '',
    preChatResponse: {}
  }
};

try {
 await window.ocsdk.sessionInit(requestId, optionalParams);
 // success
} catch {
 // failure
}

Session Close

const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
const optionalParams = {
  authenticatedUserToken: '',
};

try {
 await window.ocsdk.sessionClose(requestId, optionalParams);
 // success
} catch {
 // failure
}

Submit PostChat Response

const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
const postChatResponse = {};
const optionalParams = {
  authenticatedUserToken: '',
};

try {
 await window.ocsdk.submitPostChatResponse(requestId, postChatResponse, optionalParams);
 // success
} catch {
 // failure
}

Get Chat Transcripts

const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
const chatId = ''; // Chat thread ID
const token = ''; // Skype token
const optionalParams = {
  authenticatedUserToken: '',
};

try {
 const response = await window.ocsdk.getChatTranscripts(requestId, chatId, token, optionalParams);
 // success
} catch {
 // failure
}

Email Transcript

const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
const token = ''; // Skype token
const emailRequestBody = { // Email body
  ChatId: '', // Chat thread ID
  EmailAddress: 'contoso@microsoft.com',
  DefaultAttachmentMessage: '',
  CustomerLocale: 'en-us'
};
const optionalParams = {
  authenticatedUserToken: '',
};

try {
 await window.ocsdk.emailTranscript(requestId, token, emailRequestBody, optionalParams);
 // success
} catch {
 // failure
}

Fetch Data Masking Info

// Manually generate request id
const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
try {
  const response = await window.ocsdk.fetchDataMaskingInfo(requestId);
  // success
} catch {
  // failure
}

// Auto generate request id
try {
  const response = await window.ocsdk.fetchDataMaskingInfo();
  // success
} catch {
  // failure
}

SDK Configuration

These are the available config options with its default values for the SDK.

{
  /**
   * Number of times a getchattoken request is retried.
   */
  getChatTokenRetryCount: 35,
  /**
   * Time in milliseconds between two successive getchattoken retry requests.
   */
  getChatTokenTimeBetweenRetriesOnFailure: 10000,
  /**
   * Maximum number of request retries before failing.
   */
  maxRequestRetriesOnFailure: 5,
}

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

更新日志

Changelog

All notable changes to this project will be documented in this file.

[Unreleased]

Changed

Fixed

  • New approach to prevent pageToken header to contain wrong value for getPersistentChatHistory
  • Fixed getPersistentChatHistory method to make requestId a required parameter and ensure it is always provided by the caller.
  • Prevent mutation of default headers by creating a shallow copy before modification in getPersistentChatHistory method.

[0.5.19] 2025-09-14

Added

  • Implemented new function to obtain persistent chat history messages
  • Added logging for httpRequestResponseTime

[0.5.18] - 2025-07-08

Changed

  • Added logging for httpRequestResponseTime

[0.5.17] - 2025-06-24

Changed

  • Replace crypto with crypto-js for browser compatibility

[0.5.16] 2025-05-12

Fixed

  • Updated request id path parameter in getReconnectable Api to standardize the use
  • Removed Timeout from telemetry logger

[0.5.15] 2025-05-09

Added

  • Added correlationId in the header for all oc request

[0.5.14] 2025-04-09

Added

  • Extend getChatToken to include Ms-Oc-Bot-Application-Id as query parameter.

[0.5.13] - 2025-03-24

Added

  • Add AuthTokenDetails as log data

[0.5.12] - 2025-03-10

Added

[0.5.11] - 2025-01-29

Added

  • Added new initContext property types for push notification

[0.5.10] - 2025-01-16

Added

  • Adding validator to remove PI.

[0.5.9] - 2024-12-05

Fixed

  • Updating exception details telemetry with response data axios field

[0.5.8] - 2024-10-31

Changed

  • Increase of timeout limit time for GetChatConfig, from 30 secs to 120 secs.

[0.5.7] - 2024-10-25

Added

  • set open ssl to legacy
  • logging response errorCode into telemetry logs
  • Improve telemetry to uniformly log all errors for reconnectable chat and reconnect availability

Fixed

  • Add requestId as optional parameters for getReconnectableChats()

[0.5.6]

Fixed

  • Fix error propagation when a call to an endpoint timesout
  • Fix unit tests

Added

  • Error propagation when getchattoken returns an empty dashboard

[0.5.5]

Security

[0.5.3] - 2024-06-18

Added

  • added axios-retry library support

[0.5.2] - 2024-05-20

Fixed

  • Fix Authenticated Chat Reconnect APIs using sig as query paramater

[0.5.1] - 2024-05-15

Fixed

  • Remove console logs from LoggingSanitizer.stripRequestHeadersSensitiveProperties()

[0.5.0] - 2024-05-14

Added

  • Add livechatconnector/v2/lcwfcsdetails endpoint
  • Add Ms-Oc-User-Agent as default request headers
  • Log RequestHeaders

[0.4.5] - 2024-03-18

Changed

  • Remove telemetry lane, which was duplicating events for GetLWI

[0.4.4] - 2024-03-18

Added

  • Add configurable wait time between retries componenets, and set to 3 secnds for getLWI, and 1 second for all other requests

[0.4.3] - 2024-02-28

Added

  • Add useUnauthReconnectIdSigQueryParam configuration to use sig as query parameter to pass reconnectId for Unauthenticated Chat Reconnect APIs
  • Add Oc-Sessionid as part of request headers if exists
  • Add configurable wait time between retries componenets, and set to 3 secnds for getLWI, and 1 second for all other requests

[0.4.2] - 2023-12-06

Added

  • Add GetChatConfigFailed telemetry event

Changed

  • Removal of recursive call in LoggingSanitizer as preventive measure for stack overflow

[0.4.1] - 2023-11-10

Added

  • including changes to handle new library versions.

Security

[0.4.0] - 2023-07-05

Added

  • refreshToken optional query parameter to getchattoken endpoint

[0.3.4] - 2023-03-24

Added

  • livechatconnector/v3/getchattoken endpoint
  • livechatconnector/v3/auth/getchattoken endpoint
  • Stop retry when the error is related to out of office hours.
  • Send and receive AuthCodeNonce header in order to be compliant with Omnichannel's OAuth 2.0 requirement
  • Increasing request timeout and add error handling for OAuth 2.0

[0.3.3] - 2023-01-09

Fix

  • Added requestTimeoutConfig and defaultRequestTimeout to set timeouts on endpoints.
  • Throw ClientHTTPTimeoutError exception in case of timeouts.
  • Update InitContext to include isProactiveChat.

[0.3.2] - 2022-11-03

Changed

  • Update methods to log RequestPath, RequestMethod and ResponseStatusCode

Fix

  • Update getChatToken's error.response to be optional

Security

[0.3.1] - 2022-07-06

Added

  • Add RequestPayload, RequestPath, RequestMethod and ResponseStatusCode as log data
  • Strip Geolocation log data

Fix

  • Stop getchattoken retry calls on 429
  • Fix axiosRetry counter

Changed

  • Rename getQueueAvailability to getAgentAvailability

[0.3.0] - 2021-09-23

Added

  • Remove sensitive properties from Error object
  • Return date field on getChatConfig response
  • Add customerDisplayName as optional parameter in sendTypingIndicator

Security

[0.2.0] - 2021-05-05

Added

  • livechatconnector/v2/auth/getchattoken endpoint
  • inbound/typingindicator/livechat/sendtypingindicator endpoint
  • livechatconnector/v2/getchattranscripts endpoint
  • livechatconnector/v2/auth/getchattranscripts endpoint

[0.1.1] - 2021-02-16

Added

  • livechatconnector/v2/getchattoken endpoint

Security

[0.1.0] - 2020-09-21

Added

  • Initial release of Omnichannel SDK v0.1.0