Collectchat.on callback not getting called in Embed Mode


#1

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


#2

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


#3

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);
});
}


#4

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

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

Regards,
Aslam


#5

Here is the code

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.


#6

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.


#7

Hi,

Can anyone please respond to this and help?


#8

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.


#9

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


#10

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


#11

Glad you found the answer from our Help Center.