My SAAS company’s been making good use of Intercom’s ability to pop up the chat widget with a message request prefilled with a request. For instance, we have a button to request that the user’s account is closed (in lieu of the actual functionality existing) – when clicked, an Intercom chatbox opens with the language “please close my account.” This allows my developers to focus on implementing more profitable features alwhile helping the user put in a request without having to type out their request.
Can the Javascript API please be enhanced to include similar functionality?
It’s great to hear that your SAAS company is effectively utilizing Intercom’s chat widget for streamlining user requests. Enhancing a JavaScript API to include functionality for a prefilled message in a chat widget can indeed be a valuable feature for both users and developers.
I can suggest a general approach that you might consider. You could use the existing JavaScript API provided by your chat widget service (like Intercom or tawk.to) to programmatically open the chat widget with a prefilled message. Here’s a conceptual example of how you might achieve this:
// Check if the chat widget API is available
if (window.ChatWidgetAPI) {
// Function to open the chat widget with a prefilled message
function openChatWithPrefilledMessage(message) {
window.ChatWidgetAPI.open({
message: message
});
}
// Add event listener to your button
document.getElementById(‘close-account-btn’).addEventListener(‘click’, function() {
openChatWithPrefilledMessage(‘Please close my account.’);
});
}
In this example, ChatWidgetAPI is a placeholder for the actual API object provided by your chat service, and open is a hypothetical method that opens the chat widget with options, including a prefilled message. You would need to replace these with the actual API details provided by your chat service.
If you want more details please tell me I am happy to help you.
Can you help me achieve the same thing?
On the Prechat submit of JS API
window.Tawk_API = window.Tawk_API || {};
window.Tawk_API.onPrechatSubmit = function(data){
//place your code here
};
I want to send a prefilled message. I dont’ see any documentation in the JS API if that is possible.
OR is this something that can work…
Tawk_API.onLoad = function(){
// Wait for the Tawk.to widget to load
Tawk_API.popup(); // Open the chat popup
Tawk_API.addEvent('chat:start', function(){
Tawk_API.setAttributes({
'predefinedMessage': 'Hello, I need assistance with...'
}, function(error){
console.error(error);
});
});
};