[Widget v2] Unable to update deploymentId on the fly

Hello Team,

Customer would like to switch the Chat Deployment ID that will be launched depending on the service selection ...

So I build the below example page :

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>PureCloud WebChat Demo</title>
</head>

<body>
  <script src="https://apps.mypurecloud.de/widgets/9.0/cxbus.min.js" onload="javascript:CXBus.configure({debug:true,pluginsPath:'https://apps.mypurecloud.de/widgets/9.0/plugins/'}); CXBus.loadPlugin('widgets-core');"></script>

Choose your deployment : 
<div> <input type="radio" name="deployKeyRadio" id="COLL_Key" value="9d521e6c-4ca0-4765-ad27-e6bbc0920255"> <label for="Collectif">Collectif (9d521e6c-4ca0-4765-ad27-e6bbc0920255)</label> </div>
<div> <input type="radio" name="deployKeyRadio" id="INDV_Key" value="0abce8f9-73d3-482f-9c3d-15b5672640ea" checked> <label for="Individuel">Individuel (0abce8f9-73d3-482f-9c3d-15b5672640ea)</label> </div>

<script type="text/javascript">
 		window._genesys = {
		  widgets: {
			webchat: {
			  transport: {
				type: 'purecloud-v2-sockets',
				dataURL: 'https://api.mypurecloud.de',
				deploymentKey : '47228a28-04b8-4d80-b7ac-c387b5fbc781',
				orgGuid : 'c19e6ec9-c6db-4bd0-84e0-47d31daf4130',
				interactionData: {
				  routing: {
					targetType: 'QUEUE',
					targetAddress: 'DEVMMH-Chat_Queue',
					priority: 2
				  }
				}
			  },
			}
		  }
		};
		const customPlugin = CXBus.registerPlugin('Custom');
</script>

<br><br>
	window._genesys.widgets.webchat.transport.deploymentKey : <input id="toto" value="coucou" size = 100></input>
	<br>
	<button type="button" id="chat-button" onclick="updateWidget();customPlugin.command('WebChat.open', getAdvancedConfig());">Start Chat</button>
	
	  <script type="text/javascript">
		function getAdvancedConfig() {
			return {
				form: {
					autoSubmit: true,
				},

				formJSON: {
					wrapper: '<table></table>',
				}
			};
		}
		
		function updateWidget() {
		  	var radios = document.getElementsByName('deployKeyRadio');
			for (var i = 0, length = radios.length; i < length; i++) {
				if (radios[i].checked)  {
					var radio = radios[i];
					break;
				}
			}
			var deployKey = radio.value;
			window._genesys.widgets.webchat.transport.deploymentKey = deployKey;
			document.getElementById("toto").value = window._genesys.widgets.webchat.transport.deploymentKey;

			customPlugin.subscribe('WebChatService.started', function (e) {
			  console.log('Chat started', e);
			});
			customPlugin.subscribe('WebChatService.ended', function (e) {
			  console.log('Chat ended', e);
			});
		}
	</script>
</body>
</html>

I got here 2 radios button in order to switch the DeploymentKey when the chat is launched.
So after the the page is loaded, if I choose a deployment and then hit the Start Chat button, the right deploymentKey is used. In the Chrome Network log, we can see the right deploymentId :

Now, if I end the chat, close the popup, switch to the other deployment and hit the Start Chat button again (without refreshing the page), the DeploymentKey is updated in the code (displayed in the input text box), but in Network request, I'm still seeing the previous deploymentId.

It's like the window._genesys.widgets is kept in cache in the CXBus and we can't update it ...

I also tried to register 2 differents plugins with different deploymentKey but the second chat always open with the first deploymentId ...

Would you have any hint about that ?

Cheers,
Valéry Chhoa

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.