function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sam Sam 85Sam Sam 85 

Embedded Service - Embedded Web Chat - Intercept User Sent Message

Hello everyone, 

I am currently stuck trying to figure out how to do the following:

Is there a way I could intercept the user sent message on client-side (before it goes to the bot) and then send to the bot my own custom message, all in javascript?

For example:

1.  User sends a message "Hello".
2.  My client-side javascript, intercepts the user sent message.
3.  In javascript, customize the message and then send the custom message to the bot.  In this example, I send to the bot "Hello, world!!!".

Thank you for all your help.

HTML Code:
<div id="divContainer">
	<img id="imgChatBubble" src="..." />
</div>

Javscript Code:
var initESW = function (gslbBaseURL) {
	
	embedded_svc.settings.displayHelpButton = false; 
	embedded_svc.settings.language = ''; 

	embedded_svc.settings.enabledFeatures = ['LiveAgent'];
	embedded_svc.settings.entryFeature = 'LiveAgent';
		
	embedded_svc.settings.widgetHeight = "90%";

	embedded_svc.init(
		'...',
		'...',
		gslbBaseURL,
		'...',
		'...',
		{
			baseLiveAgentContentURL: '...',
			deploymentId: '...',
			buttonId: '...',
			baseLiveAgentURL: '...',
			eswLiveAgentDevName: '...',
			isOfflineSupportEnabled: true
		}
	);
};

if (!window.embedded_svc) {
	var s = document.createElement('script');
	s.setAttribute('src', '...');
	s.onload = function () {
		initESW(null);
	};
	document.body.appendChild(s);
}
else {
	initESW('https://service.force.com');
}


function setupOnChasitorMessageEventHandler() {

	// onChasitorMessage event fired when user sends a message.  
	// This event handler will handle the fired onChasitorMessage event.
	embedded_svc.addEventHandler("onChasitorMessage", function (data) {

		if (true) {

		}
		
	});
}


setupOnChasitorMessageEventHandler();
MagulanDuraipandianMagulanDuraipandian
Sam,
You can achieve this using the Lightning Web Component.
https://www.infallibletechie.com/2021/12/how-to-interceptmodify-chat-message-in.html