First, create a layer in LayerZ dashboard and add Chatwoot script to the layer content
To allow the integration between LayerZ and Chatwoot, paste this right after:
<script>
// Helper function to convert events to promises
function waitForEvent(target, eventName){
return new Promise((resolve) => {
target.addEventListener(eventName, resolve, { once: true });
});
}
// Wait for both events
Promise.all([
waitForEvent(window, 'layerZ:ready'),
waitForEvent(window, 'chatwoot:ready')
]).then(() => {
var user = window.$layerZ.getUser();
var customAttributes = user.customAttributes;
customAttributes.lzUserId = user.id;
window.$chatwoot.setCustomAttributes(customAttributes);
});
</script>
Next, create a LayerZ journey with your desired action and a Web-hook Trigger. Generate the Web-hook URL and copy it.
In Chatwoot, create an automation with specific trigger conditions—such as a user message containing particular keywords or phrases. Then, add a "Send web-hook event" action to the Chatwoot automation and paste the LayerZ web-hook URL you copied earlier.
Finally, test the integration by running your journey through a LayerZ campaign on your website.