共用方式為


在即時聊天期間傳送自訂內容

自訂內容是索引鍵或值組的集合。 任何索引鍵只允許基本值。 索引鍵必須對應於為關聯工作流建立的內容變數。 如果未在即時工作串流下建立具有相符邏輯名稱的內容變數,則會在執行階段建立變數,假設類型為字串。 當啟動新聊天時,即時聊天小工具會叫用自訂內容提供者。 因為值區分大小寫,所以使用完全比對來將它們傳遞至環境定義變數。 其他資訊: 內容變數的考量

這很重要

  • setContextProvider 僅支援未經驗證的聊天。 對於已驗證的聊天,您必須使用 JSON Web 權杖 (JWT)。 其他資訊: 傳送驗證權杖
  • 在每個聊天階段作業期間,您只能傳遞 100 個自訂內容變數。

當客戶從入口網站開始聊天時,您可以將自訂內容傳遞至 Customer Service 全通路。 此自訂內容可用來 顯示使用者介面上的資訊 ,並建立路由規則,最終決定您必須將聊天路由到的佇列。

請按照以下步驟在開始聊天時傳送自訂內容:

  1. 應該在引發 lcw:ready 事件 事件之後叫用即時聊天 SDK 方法。 您可以在視窗物件上新增自己的事件接聽程式,以監聽此事件。
  2. 引發事件之後 lcw:ready ,請使用 setContextProvider 方法向即時聊天註冊自訂內容提供者。
  3. 使用 startChat 方法開始聊天

範例程式碼

function contextProvider(){
	//Here it is assumed that the corresponding work stream would have context variables with logical name of 'contextKey1', 'contextKey2', 'contextKey3'. If no context variable exists with a matching logical name, items are created assuming Type:string               
	return {
			'contextKey1': 'contextValue1', // string value
			'contextKey2': 12.34, // number value
			'contextKey3': true // boolean value
	};
}

window.addEventListener("lcw:ready", function handleLivechatReadyEvent(){
	// Handle LiveChat Ready event
	// SDK methods are ready for use now
	// Setting custom context provider to be used with Chat for Dynamics 365
	// The custom context provided by custom context provider can be used for routing the chat to a particular queue
	Microsoft.Omnichannel.LiveChatWidget.SDK.setContextProvider(contextProvider);
	// Starting a new chat
	Microsoft.Omnichannel.LiveChatWidget.SDK.startChat();
});

window.addEventListener("lcw:error", function handleLivechatErrorEvent(errorEvent){
	// Handle LiveChat SDK error event
	console.log(errorEvent);
});

如需如何在交談摘要中顯示內容變數的相關資訊,請參閱 顯示自訂內容

setContextProvider
getContextProvider
removeContextProvider
即時聊天SDK JavaScript API參考
設定機器人的內容變數