Dialogflow Messenger JavaScript event not working

Hi community members,

Need some help as I am trying to work with Dialogflow Messenger JavaScript events. I am able to get the below code working pasting it after the tag:

window.addEventListener(‘df-chat-open-changed’, (event) => {
console.log(Chat is ${event.detail.isOpen ? ‘open’ : ‘closed’});
});

Similarly, I am trying another event but this isn’t working for some reason:

window.addEventListener(‘df-messenger-loaded’, () => {
console.log(“DF chat got loaded.”);
});

If I can get the second event working, the aim is to send the first “Hi” message automatically and then pass a string as a session parameter to Dialogflow, which I am going to use later in a webhook. Just wondering if I can get some guidance around this

1 Like

Try to do this without waiting for the ‘df-messenger-loaded’ event. Just call

dfMessenger.renderCustomText(‘Hi’) at the high level of your JS (immediately after getting the DOM reference to df-messenger).