Gå til innhold

Integration – ClubsiteCMS

Overview

The chatbot is integrated into ClubsiteCMS via three Classic ASP/JS files that are automatically included in all pages for a given tenant.

Include Order

All CMS pages (e.g. default.asp)
    └── #include "common-front/ai_chatbot_loader.asp"
              └── (if IsActive=1) #include "../ai_chat_widget.asp"
              └── Writes <script src="/assets/js/chatbot.js">

ai_chatbot_loader.asp

Location: SKI/common-front/ai_chatbot_loader.asp

Runs server-side on every page view. Does the following:

  1. Queries the AI_Chatbot_Settings table in the club's database
  2. Writes CSS variables to a <style> block:
    :root {
      --chatbot-theme-color: #2e7d32;
      --chatbot-logo-url: url('/assets/img/logo.png');
    }
    
  3. Writes JS constants to a <script> block:
    const BOT_NAME = "SKI Golf Club Assistant";
    const WELCOME_MSG = "Hi! How can I help you?";
    const TENANT_ID = "SKI";   // from <%=ROOT_FOLDER%>
    
  4. Includes ai_chat_widget.asp if IsActive = 1

AI_Chatbot_Settings – Database Table

Column Type Description
ClubID int Foreign key to Clubs
IsActive bit Chatbot enabled (1) or disabled (0)
BotName nvarchar Display name for the bot
WelcomeMessage nvarchar Welcome message
ThemeColor nvarchar CSS colour (hex)
LogoUrl nvarchar URL to bot logo
ExcludedPaths nvarchar Comma-separated list of pages without chatbot

ai_chat_widget.asp

Location: SKI/ai_chat_widget.asp

Simple HTML structure for the chatbot widget. Rendered server-side and conditionally included from the loader.

chatbot.js

Location: SKI/assets/js/chatbot.js

Vanilla JavaScript client. Key logic:

const API_URL = "/api/chat";

async function sendMessage(message) {
  const response = await fetch(API_URL, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      tenant_id: TENANT_ID,   // injected from ASP loader
      message: message,
      history: conversationHistory
    })
  });
  const data = await response.json();
  return data.reply;
}

Conversation history is stored only in the browser's memory (JavaScript array). It is sent with each request for context but is never stored on the server.

Admin Settings (CSADMIN)

Location: SKI/CSADMIN/files_setup/cChatbot.asp

Gives CMS administrators an interface to: - Enable/disable the chatbot - Change bot name and welcome message - Set theme colour and logo image - Define excluded pages

Saving is handled by SKI/CSADMIN/files_setup/scr_chatbot.asp via SQL UPSERT against AI_Chatbot_Settings.

IIS Configuration

/api/chat requests are routed by IIS to the uvicorn process via URL Rewrite (reverse proxy). The rule is configured at the IIS site level, not in the per-tenant-folder web.config.

<!-- Example IIS URL Rewrite rule (set at site level) -->
<rule name="API Proxy" stopProcessing="true">
  <match url="^api/(.*)" />
  <action type="Rewrite" url="http://127.0.0.1:8000/api/{R:1}" />
</rule>