Answered

Pre-fill search input in the messenger widget help section


Hello 

Our SaaS solution has recently introduced an in-app search feature allowing our users to search in different app locations. When we don’t find results we’re encouraging users to find possibles answers within our help center (powered by Intercom) trough the SDK JS Widget

In order to achieve that we’re calling programatically Intercom('showSpace', 'help');

We would like to go further and be able to call this method or similar one with a text parameter that would fill the search input on the “help” space and trigger a search within articles : 

 

Would it be something achievable on your side ? 

I’m available if you want/need more details!

Thanks

icon

Best answer by Eden 28 June 2023, 23:57

View original

2 replies

Userlevel 3
Badge

Hey @josephq 👋 Eden from the support engineer team here.

 

Thanks for reaching out. At the moment, it wouldn’t be possible to insert text parameters that automatically populate in the Help Center search bar when programmatically calling Intercom('showSpace', 'help'); , however I can see how that would be cool functionality to have! I’ll submit this as a feature request for you with the product team. 👍

I was searching for something else and came across this, not sure if it’s worth trying but, if you are already procedurally showing help, I would’ve suggested using jQuery or JS to programattically set the help field input after the Intercom agent reached a ready state. ChatGPT says the code might look like this:

// Open the help dialog and set the search field text
Intercom('showSpace', 'help');

// Set the value of the search field to 'Getting started'
Intercom('update', {
custom_launcher_selector: '#intercom-container .intercom-help-center-input', // Change the selector accordingly
custom_launcher_content: 'Getting started',
});

But just be aware of the race condition this introduces. The first command is trying to open and display the dialog, the second is looking for the field in the dialog, but is probably executing before the dialog is ready. If the Intercom function returns a promise, you could do it like this:

// Open the help dialog and set the search field text
Intercom('showSpace', 'help').then(function(){

// Set the value of the search field to 'Getting started'
Intercom('update', {
custom_launcher_selector: '#intercom-container .intercom-help-center-input', // Change the selector accordingly
custom_launcher_content: 'Getting started',
});
});

Otherwise, you’d be left with a clunky setTimeout approach, which if tuned right would work most of the time:

// Open the help dialog and set the search field text
Intercom('showSpace', 'help');

// Introduce a 0.5 second delay using setTimeout
setTimeout(function() {
Intercom('update', {
custom_launcher_selector: '#intercom-container .intercom-help-center-input', // Change the selector accordingly
custom_launcher_content: 'Getting started',
});
}, 500); // 500 milliseconds = 0.5 seconds

Hope that helps!

Bryce R

Reply