Reference
Learn more about the methods available to use when working with GitBook Assistant programmatically
Last updated
Was this helpful?
Learn more about the methods available to use when working with GitBook Assistant programmatically
Last updated
Was this helpful?
Was this helpful?
Customizing GitBook Assistant allows you to integrate the assistant directly into your product or website, making it feel like a natural part of your product's experience. To do this, GitBook Assistant also exposes helper functions that further allow it to interact with your app. Using these methods to close, show, hide, or unload the assistant will help you integrate GitBook Assistant more seamlessly into your product's experience.
Display the GitBook widget if it has been hidden.
Example:
Hide the GitBook widget without unloading it.
Example:
Open the GitBook Assistant window.
Example:
Close the GitBook Assistant window.
Example:
Toggle the GitBook Assistant window open or closed.
Example:
Completely remove the GitBook widget from your site.
Example:
Navigate to a specific page within your GitBook docs by its path.
Parameters:
path (string): The path to the page you want to navigate to
Example:
Navigate directly to the GitBook Assistant interface.
Example:
Post a message to the chat as if the user typed it.
Parameters:
message (string): The message to post to the chat
Example:
Clear all messages from the current chat session.
Example:
Register an event listener for GitBook events.
Parameters:
event (string): The event name to listen for
listener (function): The callback function to execute when the event occurs
Example:
window.GitBook("close");window.GitBook("toggle");window.GitBook("unload");// Navigate to the getting started guide
window.GitBook("navigateToPage", "/getting-started");
// Navigate to a specific API documentation page
window.GitBook("navigateToPage", "/api/authentication");
// Navigate to FAQ section
window.GitBook("navigateToPage", "/faq/billing");// Open the assistant chat
window.GitBook("navigateToAssistant");
// You might use this in response to a button click
document.getElementById("help-button").addEventListener("click", () => {
window.GitBook("navigateToAssistant");
});// Send a predefined message
window.GitBook("postUserMessage", "How do I reset my password?");
// Send a message based on user action
function askAboutBilling() {
window.GitBook("postUserMessage", "I have questions about my billing");
}
// Send a message with context
const userPlan = "premium";
window.GitBook(
"postUserMessage",
`I'm on the ${userPlan} plan and need help with advanced features`
);// Clear the chat
window.GitBook("clearChat");
// Clear chat and start fresh conversation
function startNewConversation() {
window.GitBook("clearChat");
window.GitBook("postUserMessage", "Hello, I need help with a new issue");
}
// Clear chat when switching contexts
document.getElementById("new-topic").addEventListener("click", () => {
window.GitBook("clearChat");
window.GitBook("navigateToAssistant");
});// Listen for page navigation
window.GitBook("on", "navigate", (data) => {
console.log("Navigated to:", data.path);
// Update breadcrumbs or analytics
});
// Listen for tool usage
window.GitBook("on", "tool_used", (data) => {
console.log("Tool used:", data.toolName);
// Log tool usage for analytics
});window.GitBook("show");window.GitBook("hide");window.GitBook("open");