We’d like to include a 3rd party bot in our Discourse site to help new users understand what our community is all about before they join it and pay a membership fee (via the subscription plugin). We’d like to trigger this bot from posts and CTAs around the site via a link / button click and start a predefined flow in the bot.
The Bot (Here’s an example) can be integrated via an iframe or via this script before the closing body-tag:
<script src="https://widget.flowxo.com/embed.js" data-fxo-widget="eyJ0aGVtZSI6IiM2N2MxOGUiLCJ3ZWIiOnsiYm90SWQiOiI1ZjYwNmFmZGJhYmU5NjAwNGIwODc4NTMiLCJ0aGVtZSI6IiM2N2MxOGUiLCJsYWJlbCI6IkV4YW1wbGVib3QifX0=" async defer></script>
So I (non-coder ) built a theme component with the code above and an additional script that triggers a certain flow when a link with a certain ID is clicked:
<script type="text/javascript">
// Wait for the page to load first
window.onload = function() {
//Get a reference to the link on the page
// with an id of "mylink"
var a = document.getElementById("mylink");
//Set code to run when the link is clicked
// by assigning a function to "onclick"
a.onclick = function() {
// Your code here...
FxoMessenger.create();
FxoMessenger.on('stateChanged', function(state) {
if (state === 'connected') {
FxoMessenger.sendMessage('This is the text that triggers the flow in the bot!');
}
});
//If you don't want the link to actually
// redirect the browser to another page,
// "google.com" in our example here, then
// return false at the end of this block.
// Note that this also prevents event bubbling,
// which is probably what we want here, but won't
// always be the case.
return false;
}
}
This works in theory, but, unfortunately, the ID is automatically removed from a link in a Discourse post. Is there a way to achieve this? Thanks for your help!