Chapter 8

The Chat Application

The chatbot application is the central hub that orchestrates the entire interaction between a user and the AI. It’s important to distinguish this application from the AI itself; the AI serves as a tool within the application rather than the application being a form of AI. This application manages various integrations with eCommerce platforms, helpdesk software, and other tools, making them accessible to end users to enhance their experience.

To function effectively, the chatbot application requires certain information to serve customers properly. For instance, when a customer sends a message, the application must first understand what the message means. This is where AI comes into play, assisting the application by identifying the intent behind the customer's message. Beyond this, the application needs to interact seamlessly with the eCommerce platform to retrieve order details, communicate with helpdesk systems to manage tickets, and potentially utilize any other tools that may help in resolving a customer’s issue. The application acts as an operating system of sorts, coordinating these tools and resources to support the user efficiently.

You can build this chatbot application in any programming language that you are comfortable with, as long as it adheres to the integration requirements of the various systems it connects to. To give you a practical example, let’s consider a JavaScript implementation that handles a web request, identifies the client using an API key, fetches the client's configuration (such as their helpdesk and eCommerce platform), and processes the user’s message using AI. The application then runs the company policy to prepare an appropriate response and sends this response back to the user.

Here’s a basic example of how such an application might look in JavaScript:

const express = require('express');
const fetch = require('node-fetch');
const app = express();

app.use(express.json());

// Endpoint to handle incoming messages
app.post('/chat', async (req, res) => {
    const apiKey = req.headers['x-api-key'];
    const userMessage = req.body.message;

    // Step 1: Identify the client using the API key
    const clientConfig = await fetchClientConfig(apiKey);
    if (!clientConfig) {
        return res.status(404).send('Client configuration not found.');
    }

    // Step 2: Process the user's message with AI to determine intent
    const intent = await identifyIntent(userMessage, clientConfig.aiModel);
    
    // Step 3: Run the company policy based on the identified intent
    const response = await runCompanyPolicy(intent, clientConfig);
    
    // Step 4: Send the response back to the user
    res.json({ response });
});

// Fetch client configuration based on API key
async function fetchClientConfig(apiKey) {
    // Here you'd typically make a database query or API call
    // For demonstration, we return a mock configuration
    return {
        ecommercePlatform: 'Shopify',
        helpdesk: 'Zendesk',
        aiModel: 'IntentClassifier',
        supportedIntents: ['TrackOrder', 'ReturnOrder']
    };
}

// Identify the intent of the user's message
async function identifyIntent(message, aiModel) {
    // Placeholder for AI model processing
    // You would call your AI service here
    return 'TrackOrder';  // Example intent
}

// Run the company policy based on intent
async function runCompanyPolicy(intent, clientConfig) {
    // Placeholder for policy execution
    // This is where you'd integrate with your eCommerce and helpdesk platforms
    return `Processing intent: ${intent}`;  // Example response
}

app.listen(3000, () => {
    console.log('Chatbot application running on port 3000');
});

In this example, the chatbot application acts as the backbone of the customer service operation, leveraging AI to interpret messages and various integrations to gather and relay the necessary information to users. This modular approach ensures that the chatbot can adapt to different business requirements and provide a seamless experience for both customers and agents.

Analogy

Let's use the analogy of a self-checkout machine in a grocery store to understand the chatbot application. Much like these machines, the chatbot application is designed to handle a wide variety of tasks efficiently. A self-checkout machine can process almost any item a customer might purchase—scanning barcodes, weighing produce like bananas, or even allowing a manager to manually enter a price for an item without a barcode. It is built to facilitate specific, predictable interactions that revolve around completing a transaction.

Similarly, the chatbot application is designed to process various customer service requests, from checking order statuses to handling returns or addressing product inquiries. It integrates with multiple systems, like eCommerce platforms and helpdesks, to gather all the necessary information to resolve customer issues efficiently. The application knows how to communicate with these systems, just like the self-checkout machine knows how to interact with the store’s inventory system.

However, you wouldn’t ask a self-checkout machine, “How tall is the Eiffel Tower?” Not because it couldn't potentially provide the answer—developers could add a feature for trivia if they wanted—but because it is irrelevant to the machine’s primary function. The same principle applies to the chatbot application. It is not built to chat for the sake of conversation or answer unrelated questions. Its purpose is to address specific customer needs within a given context, using its integrated tools to provide meaningful support.

← Part Two: Under the Hood
CH09: Integrating AI →