Omnichannel SDK
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
Lint checks is enabled by default in watch mode.
Examples
Initialize SDK
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: 3
};
const ocsdk = Microsoft.CRM.Omnichannel.SDK.SDKProvider.getSDK(params, configuration);
window.ocsdk = ocsdk;
Get Chat Config
const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
try {
const config = await window.ocsdk.getChatConfig(requestId);
} catch {
}
try {
const config = await window.ocsdk.getChatConfig();
} catch {
}
Get Chat Token
const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
try {
const chatToken = await window.ocsdk.getChatToken(requestId);
} catch {
}
try {
const chatToken = await window.ocsdk.getChatToken();
const {requestId} = chatToken;
} catch {
}
Session Init
const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
const optionalParams = {
authenticatedUserToken: '',
getContext: true,
initContext: {
locale: '',
originalurl: '',
os: '',
browser: '',
device: '',
longitude: '',
latitiude: '',
preChatResponse: {}
}
};
try {
await window.ocsdk.sessionInit(requestId, optionalParams);
} catch {
}
Session Close
const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
const optionalParams = {
authenticatedUserToken: '',
};
try {
await window.ocsdk.sessionClose(requestId, optionalParams);
} catch {
}
Submit PostChat Response
const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
const postChatResponse = {};
const optionalParams = {
authenticatedUserToken: '',
};
try {
await window.ocsdk.submitPostChatResponse(requestId, postChatResponse, optionalParams);
} catch {
}
Get Chat Transcripts
const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
const chatId = '';
const token = '';
const optionalParams = {
authenticatedUserToken: '',
};
try {
const response = await window.ocsdk.getChatTranscripts(requestId, chatId, token, optionalParams);
} catch {
}
Email Transcript
const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
const token = '';
const emailRequestBody = {
ChatId: '',
EmailAddress: 'contoso@microsoft.com',
DefaultAttachmentMessage: '',
CustomerLocale: 'en-us'
};
const optionalParams = {
authenticatedUserToken: '',
};
try {
await window.ocsdk.emailTranscript(requestId, token, emailRequestBody, optionalParams);
} catch {
}
Fetch Data Masking Info
const requestId = Microsoft.CRM.Omnichannel.SDK.Util.uuidv4();
try {
const response = await window.ocsdk.fetchDataMaskingInfo(requestId);
} catch {
}
try {
const response = await window.ocsdk.fetchDataMaskingInfo();
} catch {
}
SDK Configuration
These are the available config options with its default values for the SDK.
{
getChatTokenRetryCount: 35,
getChatTokenTimeBetweenRetriesOnFailure: 10000,
maxRequestRetriesOnFailure: 3,
}
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.