Chatbots - Data

The data for the initial system message is crucial as it serves as instructions for the chatbot's operation.

Sources

Dynamic data can be incorporated into the system message. We currently support the following data sources:

  • Text: A simple text field.
  • Query: A query to the WordPress database. This source is special as it allows you to loop through the results in your system message.
  • Post title: The title of a post.
  • Post content: The content of a post.
  • Bricks content: The content of a Bricks page. (if Bricks is installed)
  • Elementor content: The content of an Elementor page. (if Elementor is installed)
  • Oxygen content: The content of an Oxygen page. (if Oxygen is installed)
  • Postmeta: Metadata associated with a post.
  • Taxonomy: A post's taxonomy.
  • Term: A term within a taxonomy.
  • User: User data.
  • Usermeta: Metadata associated with a user.

To use custom data sources, use the sleekAi/chatbot/source filter.

            add_filter('sleekAi/chatbot/sources', function ($data) {
      $data[] = [
        'id'    => 'customSource',
        'label' => 'Custom Source',
        'value' => functionToGetCustomData(),
      ];

      return $data;
    });
  
                    
Copy

Variables

Data query results are stored in variables. For instance, you could save the title of a post as postTitle. In the system message, you can reference the variable using curly braces: {postTitle}. This will dynamically replace {postTitle} with the actual title of the specified post when the system message is sent.

You can define multiple data sources, and each will be available as a variable. For example, if you add a "Post title" source and name the variable myPostTitle, and a "User" data source named currentUserInfo with the meta key data.user_email, your system message can use both:

            The title of the current post is {myPostTitle}.
    The current user's email is {currentUserInfo}.
  
                    
Copy

Meta Keys

For data types like postmeta and usermeta that return an object, you must define a meta-key. This key specifies which object value to retrieve.

For instance, to fetch the current user's email, select the user data source and set the meta-key to data.user_email. You can then assign a variable name like userEmail to this source.

System Message

The system message, which is the first message received by the chatbot, should be a clear instruction to guide its behavior. All previously defined data variables can be included in this message. The more specific and context-rich your system message, the better the chatbot will be able to assist your users according to your defined role and knowledge.

Consider the following example where we want the chatbot to be aware of the current post title and the current user's display name:

  1. Add a "Post title" data source, variable name: currentPostTitle.
  2. Add a "User" data source, variable name: currentUserDisplayName, meta key: data.display_name.

Example System Instruction:

            You are an assistant helping users with the content on this page.
    The current page title is: {currentPostTitle}.
    The user you are chatting with is: {currentUserDisplayName}.
    Be polite and refer to them by their name if possible.
    When discussing the page content, try to relate it back to "{currentPostTitle}".
  
                    
Copy

Rendered System Instruction Example

(assuming post title is "My Awesome Product" and user is "John Doe")

            You are an assistant helping users with the content on this page. The current page title is: My
    Awesome Product. The user you are chatting with is: John Doe. Be polite and
    refer to them by their name if possible. When discussing the page content, try
    to relate it back to "My Awesome Product".
  
                    
Copy

The Query Source

The "Query" source type is particularly powerful. It allows you to fetch multiple posts based on your criteria (post types, terms, search value) and then loop through these posts in your system message.

When configuring a Query source, you define a template for each post found by the query. Since SleekAI returns the full post object for each item, you will access its properties using nested syntax like {post.post_title}, {post.post_content}, {post.ID}, {post.permalink}, etc. The "Show available values" link in the interface helps discover all possible dynamic tags for the post object.

If the query returns multiple posts, each rendered template output will be separated by three dashes (---). This allows you to supply a cleanly structured list of items to the language model.

Let's look at a more thorough example. Suppose you want to provide the chatbot with a list of recent projects, including their titles, a short description (excerpt), and a direct link.

  1. Create a new Data Source of type "Query".
  2. Name the variable recentProjects.
  3. Configure the query to fetch posts of type 'project', ordered by date descending, limiting to 3 results.
  4. In the "Template" field, enter:
            Project Title: {post.post_title}
    Description: {post.post_excerpt}
    Link: {post.permalink}
  
                    
Copy

(Note: Ensure each dynamic tag like {post.post_title} is one of the "available values" for your post type by inspecting the post object.)

Now, in your chatbot's main system instruction, you can use the {recentProjects} variable:

            You are a portfolio assistant. You have been provided with a list of recent projects below. When a user asks about recent work, use this information to answer.

    Recent Projects:
    {recentProjects}

    Remember to be helpful and informative.
  
                    
Copy

Rendered System Instruction Example:

If the query finds three projects:

  • Project Alpha (post_title: "Project Alpha", post_excerpt: "A groundbreaking finance app.", permalink: "/projects/alpha")
  • Project Beta (post_title: "Project Beta", post_excerpt: "An e-commerce platform for artisans.", permalink: "/projects/beta")
  • Project Gamma (post_title: "Project Gamma", post_excerpt: "A community portal for local artists.", permalink: "/projects/gamma")

The rendered {recentProjects} block in the system instruction would look like this:

            Project Title: Project Alpha
    Description: A groundbreaking finance app.
    Link: /projects/alpha
    ---
    Project Title: Project Beta
    Description: An e-commerce platform for artisans.
    Link: /projects/beta
    ---
    Project Title: Project Gamma
    Description: A community portal for local artists.
    Link: /projects/gamma
  
                    
Copy

This demonstrates how the template is applied to each post and how the "---" separator joins them, creating a structured block of information for the LLM. This allows for highly dynamic and context-aware system messages, tailoring the chatbot's initial instructions based on real-time data from your WordPress site.