Loading the Featurebase JavaScript library provides a Featurebase JavaScript object that responds to a few methods. These allow you to update users without a page refresh and interact with the messenger window.
Written By Bruno from Featurebase
Last updated 9 days ago
This requires you to have our messenger installed, please follow the installation guide first.
Featurebase('show')
This will show the Messenger with the default view.
Featurebase('show');
Featurebase('show', pageName)
This will show the Messenger and navigate to a specific page.
Featurebase('show', 'messages'); // Options: 'home', 'messages', 'changelog', 'help'
Featurebase('hide')
This will hide the Messenger if it's currently open.
Featurebase('hide');
Featurebase('showNewMessage')
This will open the Messenger with a new message composer.
Featurebase('showNewMessage');
Featurebase('showNewMessage', initialText)
This will open the Messenger with a new message composer pre-populated with initial text.
Featurebase('showNewMessage', 'I need help with my account');
Featurebase('showArticle', articleId)
This will open the Messenger and display a specific help article.
Featurebase('showArticle', 'article-id-123');
Featurebase('showChangelog')
This will open the Messenger and navigate to the main changelog view.
Featurebase('showChangelog');
Featurebase('showChangelog', entryId)
This will open the Messenger and navigate to a specific changelog entry.
Featurebase('showChangelog', 'changelog-entry-id-456');
Featurebase('showConversation', conversationId)
This will open the Messenger and display a specific conversation.
Featurebase('showConversation', 'conversation-id-123');
Event Handling
Featurebase('onHide', callback)
Register a callback function that will be executed when the Messenger is hidden.
Featurebase('onHide', function() {
console.log('Messenger was hidden');
// Do something when messenger is hidden
});
Featurebase('onShow', callback)
Register a callback function that will be executed when the Messenger is shown.
Featurebase('onShow', function() {
console.log('Messenger was shown');
// Do something when messenger is shown
});
Featurebase('onUnreadCountChange', callback)
Register a callback function that will be executed whenever the unread message count changes. The callback receives the new count as an argument.
Featurebase('onUnreadCountChange', function(unreadCount) {
console.log('Unread count changed to:', unreadCount);
// Update UI to show unread count
document.getElementById('message-badge').textContent =
unreadCount > 0 ? unreadCount : '';
});
Theme and Language Control
Featurebase('setTheme', theme)
Set the Messenger theme to either light or dark mode.
Featurebase('setTheme', 'light'); // 'light' or 'dark'
Featurebase('setLanguage', language)
Set the display language of the Messenger.
Featurebase('setLanguage', 'fr'); // e.g., 'en', 'es', 'fr'