Collectchat.on callback not getting called in Embed Mode

Hi everyone,

I have just started building a bot using this framework and working on a very tight timeline. I have used the embed mode to integrate my bot. Added the iframe in a sample HTML page. The chat starts fine but I have added a JS code on the collectchat.on callback but it is not getting called.
I saw that the collectchat object itself is not getting initialized.
What am I doing wrong?
I have added the JS code in an external JS file and linked it to HTML using the script tag.
Please let me know for any solutions

Hi Varun,

Can you share the code you added with us?

Perhaps you put that in a jsfiddle and share. That should help us understand, what went wrong

Thanks and Regards,
Aslam

Its just this for now in the external JS file -

var collectchat = collectchat || {};

collectchat.ready = function() {
collectchat.on(‘open’, function() {
console.log(‘User just opened the chatbot widget’);
});
collectchat.on(‘message’, function(details) {
console.log(‘User responded to question’, details.question, details.answer);
});
}

I just tried the same and it’s working fine.

You can check the code here - https://jsitor.com/pMMtaoU96

Regards,
Aslam

Here is the code

https://jsitor.com/Qvx2b_xtX

index.js contains the js code. I am not sure what is launcher.js in your code.

I edited the iframe ID for my bot.

Update here -

I retried with widget mode and it worked but only when JS is added directly in the HTML and does not work with external JS, I don’t know why. This is just a hack because ideally I want it to work with external JS.
The iframe integration on the other hand never works.
Waiting for response.

Hi,

Can anyone please respond to this and help?

Done. I think the solution was to add this

I think this should have been the solution since I had mentioned that i was using iframe.

Hi Varun,

Just to confirm, is the issue solved?

Can you tell me what was missing earlier that helped you find the solution now?

Regards,
Aslam

1 Like

This tag - <script type=“text/javascript” src=“https://collectcdn.com/embed.js”></script>

2 Likes

Glad you found the answer from our Help Center.