Facebook Messenger Bot script | XM Community
Skip to main content
Hi, we wish to include a Facebook Messenger Bot script within a question in our survey but after inserting the script into the question's HTML view, we have mixed results - several times the FB messenger button has displayed correctly on the survey page, other times it doesn't appear at all, and often when re-opening the HTML view to check the script, it has vanished.



The script we have is:



<script> window.fbMessengerPlugins = window.fbMessengerPlugins || { init : function() { FB.init({ appId: "<OUR APP ID>", xfbml: true, version: "v3.0" }); }, callable : [] }; window.fbAsyncInit = window.fbAsyncInit || function() { window.fbMessengerPlugins.callable.forEach( function( item ) { item(); } ); window.fbMessengerPlugins.init(); }; setTimeout( function() { (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) { return; } js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); }, 0); </script> <div class="fb-send-to-messenger test-fb-send-to-messenger" messenger_app_id="<OUR APP ID>" page_id="<PAGE ID>" data-ref="" color="blue" size="large"> </div>



_(OUR APP ID and PAGE ID are numbers within the live version)_



Any ideas why this isn't working? Do we need to set it up in another way?



Thanks so much in advance for any help!



Best,

Steve
Instead of putting it in the question's HTML, try putting it in the addOnReady function under JavaScript.
> @TomG said:

> Instead of putting it in the question's HTML, try putting it in the addOnReady function under JavaScript.



Hi Tom,



Thanks for the reply! When we try this, we receive the error: "_Invalid JavaScript! You cannot save until you fix all errors: Unexpected string_".



Thanks in advance for any further help you can provide.



Cheers

Steve
> @steve_emr said:

> > @TomG said:

> > Instead of putting it in the question's HTML, try putting it in the addOnReady function under JavaScript.

>

> Hi Tom,

>

> Thanks for the reply! When we try this, we receive the error: "_Invalid JavaScript! You cannot save until you fix all errors: Unexpected string_".

>

> Thanks in advance for any further help you can provide.

>

> Cheers

> Steve



That means there is a syntax error somewhere in the JS.
> @TomG said:

> > @steve_emr said:

> > > @TomG said:

> > > Instead of putting it in the question's HTML, try putting it in the addOnReady function under JavaScript.

> >

> > Hi Tom,

> >

> > Thanks for the reply! When we try this, we receive the error: "_Invalid JavaScript! You cannot save until you fix all errors: Unexpected string_".

> >

> > Thanks in advance for any further help you can provide.

> >

> > Cheers

> > Steve

>

> That means there is a syntax error somewhere in the JS.



Ah - I was fearful that may be the case! OK, thanks again for your input, Tom.

Leave a Reply