Facebook Messenger Bot script | XM Community
Solved

Facebook Messenger Bot script

  • 28 February 2019
  • 4 replies
  • 16 views

Badge
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
icon

Best answer by TomG 28 February 2019, 19:00

View original

4 replies

Userlevel 7
Badge +27
Instead of putting it in the question's HTML, try putting it in the addOnReady function under JavaScript.
Badge
> @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
Userlevel 7
Badge +27
> @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.
Badge
> @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