nutritious-oil-27998
10/13/2025, 7:29 AMgentle-policeman-89141
10/13/2025, 7:36 AMnutritious-oil-27998
10/13/2025, 7:57 AMgentle-policeman-89141
10/13/2025, 8:02 AMgentle-policeman-89141
10/13/2025, 8:08 AMif (event.type === "message-sent") {
// update clerk publicMetadata with usage count
}nutritious-oil-27998
10/13/2025, 8:12 AMnutritious-oil-27998
10/14/2025, 10:07 AMgentle-policeman-89141
10/14/2025, 2:05 PMwindow.botpress.on('message', (message) => {
console.log('New message: ', message);
// Insert your code here
});
if you did I believe that is the vanilla js one. If you're using the Webchat React library, you should use the useWebchat hook's returned on value to listen to events. You add this at the top level of your React component that renders Webchat.
import { useWebchat } from '@botpress/webchat';
import { useEffect } from 'react';
function MyWebchatComponent() {
const { on } = useWebchat();
useEffect(() => {
const unsubscribe = on('message', (event) => {
console.log('Message event received:', event);
// You can access message details from the event object
// For example: event.data.message.text
});
return () => {
unsubscribe(); // Clean up the event listener when the component unmounts
};
}, [on]); // Re-run effect if 'on' function changes
}gentle-policeman-89141
10/14/2025, 2:07 PM