Chatbot - Reference
Bundle / Package
The Chatbot is available through our CDN as a single JavaScript file or through NPM as a React component package.
<script async type="text/javascript" src="https://client.aidbase.ai/chat.ab.js"></script>
Attributes / Props
You can include attributes in the <ab-chat>
tag to customize the Chatbot.
Most of these configurations are available from the Aidbase Dashboard, but you can override their values here.
Below is a full example of the <ab-chat>
tag with all available attributes.
<ab-chat
chatbotID="YOUR-CHATBOT-ID"
theme="dark"
orientation="left"
color="#8B5CF6"
logoURL="https://cdn.some-page.com/logo.png"
headline="Chat with our AI"
description="Ask any question and our AI will answer!"
initialMessage="How can I help you today?"
initialMessagePopupDelay="5"
placeholder="Type your message here..."
newChatButtonText="Start a new chat"
backToChatButtonText="Back to chat"
faqButtonText="See FAQ"
ticketButtonText="Create a ticket"
policyDescription="Please accept our privacy policy to continue."
policyLinkTitle="Privacy Policy"
policyLinkURL="https://example.com/privacy-policy"
policyAcceptButtonText="Yes, got it"
dataCollectionMessage="Let's get your name and email so we can follow up with you"
dataCollectionNamePlaceholder="Your name"
dataCollectionEmailPlaceholder="Your email"
dataCollectionButtonText="Add information"
isOpen="true"
hideButton="false"
useTicketModal="false"
maxHeight="48rem"
minHeight="32rem"
userID="a64427d6"
username="John Doe"
email="john@doe.com"
profileImageURL="https://cdn.some-page.com/profile-sm.png"
referenceID="a738d158892b"
></ab-chat>
Theme
This will render the Chatbot in either light or dark mode.
Can be either light
or dark
.
Attribute | Type | Default value |
---|---|---|
theme | string | light |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" theme="dark"></ab-chat>
Orientation
Determines if the Chatbot is displayed on the left or right side of the screen.
Can be either left
or right
.
Attribute | Type | Default value |
---|---|---|
orientation | string | right |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" orientation="left"></ab-chat>
Color
This will display the Chatbot in a specific color.
Colors are included in the header, the button, around the avatar, the loading animation and other places.
Attribute | Type | Default value |
---|---|---|
color | string | N/A |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" color="#8B5CF6"></ab-chat>
Logo URL
This logo will be displayed on the Chatbot button and as the avatar next to each message.
Attribute | Type | Default value |
---|---|---|
logoURL | string | N/A |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" logoURL="https://cdn.some-page.com/logo.png"></ab-chat>
Headline
This will be displayed as the headline of the Chatbot.
Attribute | Type | Default value |
---|---|---|
headline | string | N/A |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" headline="Chat with our AI"></ab-chat>
Description
This will be displayed as the description of the Chatbot.
The description is the subtext that appears below the headline.
Attribute | Type | Default value |
---|---|---|
description | string | N/A |
Example
<ab-chat
chatbotID="YOUR-CHATBOT-ID"
description="Ask any question and our AI will answer!"
></ab-chat>
Initial Message
This will be the first message that the Chatbot sends to the user when the Chatbot is opened.
Attribute | Type | Default value |
---|---|---|
initialMessage | string | N/A |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" initialMessage="How can I help you today?"></ab-chat>
Initial Message Popup Delay
This will determine how long the Chatbot will wait before showing the initial message as a popup.
If this is set to 0
, the popup will not be shown.
Attribute | Type | Default value |
---|---|---|
initialMessagePopupDelay | number | 0 |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" initialMessagePopupDelay="5"></ab-chat>
Placeholder
This will be the placeholder text of the input field.
Attribute | Type | Default value |
---|---|---|
placeholder | string | N/A |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" placeholder="Type your message here..."></ab-chat>
New Chat Button Message
This will be the text of the New chat button in the header of the Chatbot.
Attribute | Type | Default value |
---|---|---|
newChatButtonText | string | Chat with us |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" newChatButtonText="Start a new chat"></ab-chat>
Back to Chat Button Text
This will be the text of the Back to chat button in the header of the Chatbot while the FAQ section is open.
Attribute | Type | Default value |
---|---|---|
backToChatButtonText | string | Back to chat |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" backToChatButtonText="Back to chat"></ab-chat>
FAQ Button Text
This will be the text of the FAQ button in the header of the Chatbot.
Attribute | Type | Default value |
---|---|---|
faqButtonText | string | FAQ |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" faqButtonText="See FAQ"></ab-chat>
Ticket Button Text
This will be the text of the Ticket button in the header of the Chatbot.
Attribute | Type | Default value |
---|---|---|
ticketButtonText | string | Create a ticket |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" ticketButtonText="Create a ticket"></ab-chat>
Policy Description
If you have a privacy policy, you can display a message to the user before they start chatting.
Attribute | Type | Default value |
---|---|---|
policyDescription | string | N/A |
Example
<ab-chat
chatbotID="YOUR-CHATBOT-ID"
policyDescription="Please accept our privacy policy to continue."
></ab-chat>
Policy Link Title
This will be the text of the link to the privacy policy.
This must be used in conjunction with the policyLinkTitle
and policyLinkURL
attributes.
Attribute | Type | Default value |
---|---|---|
policyLinkTitle | string | N/A |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" policyLinkTitle="Privacy Policy"></ab-chat>
Policy Link URL
This will be the URL of the privacy policy.
Attribute | Type | Default value |
---|---|---|
policyLinkURL | string | N/A |
Example
<ab-chat
chatbotID="YOUR-CHATBOT-ID"
policyLinkURL="https://example.com/privacy-policy"
></ab-chat>
Policy Accept Button Text
This will be the text of the button that the user clicks to accept the privacy policy.
Attribute | Type | Default value |
---|---|---|
policyAcceptButtonText | string | Yes, got it |
Example
<ab-chat
chatbotID="YOUR-CHATBOT-ID"
policyAcceptButtonText="Yes, got it"
></ab-chat>
Data Collection Message
The message that will be displayed to the user when the Chatbot will collect name and email data.
Attribute | Type | Default value |
---|---|---|
dataCollectionMessage | string | N/A |
Example
<ab-chat
chatbotID="YOUR-CHATBOT-ID"
dataCollectionMessage="Let's get your name and email so we can follow up with you"
></ab-chat>
Data Collection Name Placeholder
The placeholder text for the name input field.
Attribute | Type | Default value |
---|---|---|
dataCollectionNamePlaceholder | string |
Example
<ab-chat
chatbotID="YOUR-CHATBOT-ID"
dataCollectionNamePlaceholder="Your name"
></ab-chat>
Data Collection Email Placeholder
The placeholder text for the email input field.
Attribute | Type | Default value |
---|---|---|
dataCollectionEmailPlaceholder | string |
Example
<ab-chat
chatbotID="YOUR-CHATBOT-ID"
dataCollectionEmailPlaceholder="Your email"
></ab-chat>
Data Collection Button Text
The text of the button that the user clicks to submit their name and email.
Attribute | Type | Default value |
---|---|---|
dataCollectionButtonText | string | Add information |
Example
<ab-chat
chatbotID="YOUR-CHATBOT-ID"
dataCollectionButtonText="Add information"
></ab-chat>
Is Open
This will determine if the Chatbot is open or closed by default.
Attribute | Type | Default value |
---|---|---|
isOpen | boolean | false |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" isOpen="true"></ab-chat>
Hide button
This will determine if the Chatbot button is hidden or visible.
Attribute | Type | Default value |
---|---|---|
hideButton | boolean | false |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" hideButton="true"></ab-chat>
Use Ticket Modal
If a ticket form is connected, this will determine if the ticket form shows in a modal or inside the chatbot widget.
If set to true
, the ticket form will show in a modal.
Attribute | Type | Default value |
---|---|---|
useTicketModal | boolean | false |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" useTicketModal="true"></ab-chat>
Max Height
This will determine the maximum height of the Chatbot.
Attribute | Type | Default value |
---|---|---|
maxHeight | string | 56rem |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" maxHeight="48rem"></ab-chat>
Min Height
This will determine the minimum height of the Chatbot.
The Chatbot is built responsively and will automatically adjust its height based on the screen
size.
Use this attribute with caution.
Attribute | Type | Default value |
---|---|---|
minHeight | string | N/A |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" minHeight="32rem"></ab-chat>
User ID
If you want to identify the user, you can pass a unique ID here.
If you do not provide a user ID, the Chatbot will generate a random ID for you.
This can be used to identify the user in the Aidbase Dashboard.
Attribute | Type | Default value |
---|---|---|
userID | string | N/A |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" userID="a64427d6"></ab-chat>
Username
If you want to identify the user by a username, you can pass it here.
Attribute | Type | Default value |
---|---|---|
username | string | N/A |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" username="John Doe"></ab-chat>
If you want to identify the user by an email, you can pass it here.
Attribute | Type | Default value |
---|---|---|
string | N/A |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" email="john@doe.com"></ab-chat>
Profile Image URL
If you want to display a profile image for the user, you can pass the URL here.
This will be displayed as the avatar next to each message of the user.
Attribute | Type | Default value |
---|---|---|
profileImageURL | string | N/A |
Example
<ab-chat
chatbotID="YOUR-CHATBOT-ID"
profileImageURL="https://cdn.some-page.com/profile-sm.png"
></ab-chat>
Reference ID
If you want to identify the user by a separate reference ID, you can pass it here.
If you provide a reference ID and do not provide a user ID, the reference ID will be used as the user ID.
Attribute | Type | Default value |
---|---|---|
referenceID | string | N/A |
Example
<ab-chat chatbotID="YOUR-CHATBOT-ID" referenceID="a738d158892b"></ab-chat>
Methods
You can query the DOM node of the Chatbot and call methods on it.
Example
<ab-chat
id='my-chatbot'
chatbotID='YOUR-CHATBOT-ID'
// ...additional attributes
></ab-chat>
// Get the DOM node of the Chatbot
const chatbot = document.getElementById('my-chatbot');
// Programmatically open the Chatbot
chatbot.open();
Open
This will open the Chatbot.
Method | Type | Return value |
---|---|---|
open() | Function | void |
Example
chatbot.open();
Close
This will close the Chatbot.
Method | Type | Return value |
---|---|---|
close() | Function | void |
Example
chatbot.close();
Toggle
This will toggle the Chatbot between open and closed.
Method | Type | Return value |
---|---|---|
toggle() | Function | void |
Example
chatbot.toggle();
Set New Conversation
This will reset the Chatbot and start a new conversation.
Method | Type | Return value |
---|---|---|
setNewConversation() | Function | void |
Example
chatbot.setNewConversation();
Show FAQ Section
This will show the FAQ Section of the Chatbot.
This is only needed if you have FAQs connected.
Method | Type | Return value |
---|---|---|
showFAQSection() | Function | void |
Example
chatbot.showFAQSection();
Show Ticket Section
This will show the ticket form section of the Chatbot.
If useTicketModal
is set to true
, this will open the ticket form modal.
This is only needed if you have a ticket form connected.
Method | Type | Return value |
---|---|---|
showTicketSection() | Function | void |
Example
chatbot.showTicketSection();
Show Chat Section
If the FAQ Section is currently visible, this will switch to the Chat Section.
Method | Type | Return value |
---|---|---|
showChatSection() | Function | void |
Example
chatbot.showChatSection();
Go Back
If an FAQ article is currently displayed, this will go back to the FAQ Section.
Method | Type | Return value |
---|---|---|
goBack() | Function | void |
Example
chatbot.goBack();
Callbacks
You can pass callbacks to the Chatbot to listen to certain events.
Example
<ab-chat
id='my-chatbot'
chatbotID='YOUR-CHATBOT-ID'
></ab-chat>
const chatbot = document.getElementById('my-chatbot');
// Assign a callback to the ready event
chatbot.onReady = () => {
console.log('Chatbot is ready!');
};
On Ready
When the DOM element is registered on the page, the Chatbot will make an initial request to the Aidbase API to fetch the configuration for the Chatbot.
When the configuration is fetched and validated, the Chatbot will be ready to use.
The onReady()
callback will be called immediately after the Chatbot is ready.
Callback | Type | Return value |
---|---|---|
onReady() | Function | void |
Example
chatbot.onReady = () => {
console.log('Chatbot is ready!');
};
On Error
If the Chatbot encounters an error during the process described above, the onError()
callback will be called.
Callback | Type | Return value |
---|---|---|
onError(error: Error) | Function | void |
Example
chatbot.onError = (error) => {
console.error('Something went wrong: ' + error);
};
On Data Collected
Once the Chatbot collects data from the user, the onDataCollected()
callback will be called.
Callback | Type | Return value |
---|---|---|
onDataCollected(data: UserData) | Function | void |
interface UserData {
name?: string;
email: string;
}
Example
chatbot.onDataCollected = ({ name, email }) => {
console.log('User data collected:', name, email);
};