Building an AI Assistant Chatbot in Mendix Using Google Gemini API

Building an AI Assistant Chatbot in Mendix Using Google Gemini API

AI assistants are getting better at answering questions. What if a conversation with an AI assistant could trigger a real business workflow? 

In this article, I’ll walk through how I built an AI Assistant chatbot in Mendix by integrating the Google Gemini API. The chatbot allows users to interact naturally through a conversational AI interface embedded inside a Mendix application. Users can ask questions and receive real-time AI-generated responses.

Giving the Chatbot the Power to Act 

The chatbot brings conversational AI together with a function-calling mechanism, allowing it to perform backend actions such as: 

  • Creating support tickets  
  • Checking ticket status  

In simple terms, the chatbot can take action and trigger business workflows. 

The solution is implemented using Mendix microflows, REST APIs, and a chat-style UI to create a seamless user experience. 

High-Level Architecture 

The system is built around three core components: 

Mendix Frontend 

  • Chat-style UI for user interaction  
  • Message history display  
  • Input box for user queries  

Mendix Microflows 

  • Handle prompt generation  
  • Manage chat history context  
  • Trigger REST API calls  

Google Gemini API 

  • Processes natural language prompts  
  • Returns structured JSON responses  
  • Supports function calling logic 

Building the AI Assistant in 2 Steps 

The build starts with Gemini. Once the API connection is in place, we can bring the assistant to life inside Mendix. 

Step 1: Google Gemini API Setup 

To get started, you need access to the Gemini API. 

  • Sign in using your Google account – click here 
  • Navigate to the Gemini API dashboard  
  • Generate an API key  
  • Store it securely for Mendix integration  

Keep your API key protected, it is required for all API calls. 

Image 1 – API Keys 

Step 2: Mendix Implementation 

2.1 Domain Model Design 

A structured domain model is created to store: 

  • Chat messages  
  • Sender type (User / Bot)  
  • Conversation history  
  • API responses 

Image 2 – Domain Model Design 

2.2 JSON Structure & Mappings 

To communicate with the Gemini API, we define structured JSON formats. 

2.2.1 Request Payload (Export Mapping) 

This is used to send user input to Gemini: 

{ 

  “contents”: [ 

    { 

      “parts”: [ 

        { 

          “text”: “YOUR_PROMPT” 

        } 

      ] 

    } 

  ] 

} 

2.2.2 AI Response (Import Mapping) 

Used for standard AI-generated responses: 

{ 

  “candidates”: [ 

    { 

      “content”: { 

        “parts”: [ 

          { 

            “text”: “Generated response…” 

          } 

        ] 

      } 

    } 

  ] 

} 

 
2.2.3 Function-Based Response 

When AI triggers a business action: 

{ 

  “type”: “function”, 

  “message”: “your answer”, 

  “function”: “CreateTicket”, 

  “title”: “…”, 

  “description”: “…”, 

  “priority”: “…” 

} 

 
The setup allows AI to trigger and execute business processes. 

2.3 API Configuration Setup 

A configuration page is created in Mendix to store: 

  • API Key  
  • Model Name (e.g., gemini-2.5-flash)  

These values are stored as master data, making the system flexible and maintainable. 

Image 3 – AI Configuration

2.4 Chat Interface Development 

The chat interface is the core of the application. 

When a user sends a message: 

  1. The input is captured from the UI  
  1. Chat history is appended  
  1. A prompt is generated  
  1. REST API call is triggered  
  1. Response is processed and displayed 

Image 4 – Chat Interface 1

2.5 REST API Integration 

REST API enables the Mendix application to communicate with a generative AI service through HTTP requests and receive generated responses. 

Endpoint: https://generativelanguage.googleapis.com/v1beta/models/ 

URL: Endpoint{Model}:generateContent?key={API Key} 

`

**Note:** This is a custom URL. Append the model name and API key to the endpoint URL to construct the complete request URL.

`

Setting Up the Gemini API Endpoint 

Image 5 – API Endpoint 

Flow: 

  • Request: Structured prompt with history  
  • Response: Parsed using Mendix import mapping 

2.6 Prompt Engineering Strategy 

The behavior of the chatbot is controlled using a structured prompt. 

Example Prompt: 
 
You are a support assistant. 

Always return valid JSON. 

Normal response format: 

{ 

  “type”: “response”, 

  “message”: “your answer” 

} 

Function response format: 

{ 

  “type”: “function”, 

  “function”: “CreateTicket”, 

  “title”: “…”, 

  “description”: “…”, 

  “priority”: “…” 

} 

Available function 

The prompt defines the actions the chatbot can trigger. In this example, CreateTicket allows the assistant to create a support ticket based on the user’s request. 

Chat History: 

(SenderType, Message) 

$ChatInput/Question 

 
The response is returned as raw JSON so Mendix can process it consistently. 

Do not wrap in markdown. 

This ensures consistent structured outputs from the AI model. 

2.7 Response Handling Logic 

The system processes responses based on the type field: 

Response 

  • Create message object  
  • Display response in chat UI  

Function 

  • Identify function name  
  • Trigger corresponding microflow  
  • Execute business logic (e.g., Create Ticket) 

Image 6 – Chat Interface 2 

Making AI Chatbots More Useful 

The implementation described in this blog demonstrates how Mendix and Google Gemini API can be combined to build a powerful AI-driven assistant. 

By adding function-calling capabilities, the chatbot evolves from a simple conversational interface into a fully functional enterprise assistant capable of executing real business workflows.



Author: Ajitha Deborah
Ajitha Deborah is a skilled Mendix developer with a year of experience in crafting innovative solutions. Her technical expertise extends to Java, API integration, HTML, CSS, and JavaScript, enabling her to build robust and user-friendly applications. Ajitha's ability to integrate IoT devices into Mendix platforms showcases her versatility and deep understanding of emerging technologies.

Leave a Reply