Forms and Services Functionality - Comprehensive Documentation
Table of Contents
- Overview
- Architecture
- Setup and Configuration
- Technical Requirements
- Workflow
- Early Detection System
- API Integration
- Frontend Integration
- Configuration Examples
- Troubleshooting
Overview
The Forms and Services functionality enables the chatbot to:
- List available forms when users request to see what forms are available
- Email forms to users when they request a specific form
- List available services when users want to see what services can be requested
- Process service requests by sending notifications to administrators
This system transforms the chatbot from a simple Q&A tool into a complete customer service solution that can handle actionable requests.
Key Features
- Early Detection: Pattern-based detection intercepts form/service requests before LLM processing
- Multi-language Support: Supports English, Farsi, Arabic, French, Spanish, German, and Turkish
- Domain-specific Configuration: Each domain can have its own forms and services
- Automatic Email Delivery: Forms can be automatically emailed to users
- Service Request Notifications: Service requests trigger email notifications to administrators
- Frontend Integration: Structured responses enable rich UI components (clickable buttons, lists)
Architecture
System Components
┌─────────────────────────────────────────────────────────────┐
│ User Query │
│ "show available forms" │
└────────────────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Early Detection Preprocessor │
│ (ComprehensivePatternDetection) │
│ - Pattern matching │
│ - Tool identification │
└────────────────────┬────────────────────────────────────────┘
│
┌───────────┴───────────┐
│ │
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ Special Tool │ │ Normal LLM Flow │
│ Detected │ │ (if no match) │
└────────┬─────────┘ └──────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Handler Functions │
│ - list_forms_handler() │
│ - email_form_handler() │
│ - list_services_handler() │
│ - request_service_handler() │
└────────────────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Manager Classes │
│ - FormManager (loads forms.json) │
│ - ServiceManager (loads services.json) │
└────────────────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Response with Structured Data │
│ - message_type: "forms_list" | "services_list" │
│ - clickableForms: [...] │
│ - clickableServices: [...] │
└────────────────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Frontend (Flutter App) │
│ - FormsListWidget │
│ - ServicesListWidget │
└─────────────────────────────────────────────────────────────┘
File Structure
domain-chatbot/
├── LLM_full/
│ └── query/
│ ├── form_manager.py # Form management logic
│ ├── service_manager.py # Service management logic
│ ├── functions.py # Handler functions
│ ├── tool_detection/
│ │ └── comprehensive_pattern_detection.py # Early detection
│ └── service_vector.py # Query processing (with early detection)
├── LLM_full/
│ └── domains/
│ └── {domain_name}/
│ ├── forms/
│ │ └── forms.json # Domain forms configuration
│ └── services/
│ └── services.json # Domain services configuration
Key Classes and Functions
FormManager (form_manager.py)
load_domain_forms(domain): Loads and caches forms fromforms.jsonget_available_forms(domain): Returns list of active form typesget_form_info(domain, form_type, language): Gets localized form informationdetect_form_type_from_query(query, language, domain): Detects form type from user query
ServiceManager (service_manager.py)
load_domain_services(domain): Loads and caches services fromservices.jsonget_available_services(domain, language): Returns list of active servicesget_service_info(domain, service_id, language): Gets localized service informationdetect_service_request(query, domain, language): Detects service request intent
Handler Functions (functions.py)
list_forms_handler(name, language, domain): Handles "list forms" requestsemail_form_handler(name, email, query, language, domain, form_type): Handles "email form" requestslist_services_handler(name, language, domain): Handles "list services" requestsrequest_service_handler(name, email, service_id, language, domain): Handles service requests
Early Detection (comprehensive_pattern_detection.py)
ComprehensivePatternDetection: Pattern matching systemdetect_intent(query, language, domain): Detects special tool intent- Returns
DetectionResultwith tool type, confidence, and reasoning
Setup and Configuration
Prerequisites
-
Domain Folder Structure: Each domain must have a folder structure:
{SEARCH_DOMAIN_FOLDER}/{domain_name}/├── forms/│ └── forms.json└── services/└── services.json -
Environment Variable: Ensure
EARLY_DETECTION=truein your.envfile:EARLY_DETECTION=true -
Domain Path: The
SEARCH_DOMAIN_FOLDERsetting must point to your domains directory.
Forms Configuration (forms.json)
Location: {SEARCH_DOMAIN_FOLDER}/{domain_name}/forms/forms.json
Structure
{
"forms": {
"{form_type}": {
"name": {
"en": "English Name",
"fa": "نام فارسی",
"ar": "الاسم العربي",
"fr": "Nom français",
"es": "Nombre español",
"de": "Deutscher Name",
"tr": "Türkçe ad"
},
"url": "https://example.com/forms/{form_type}",
"keywords": {
"en": ["keyword1", "keyword2", "keyword3"],
"fa": ["کلمه کلیدی 1", "کلمه کلیدی 2"],
"ar": ["كلمة مفتاحية 1", "كلمة مفتاحية 2"],
"fr": ["mot-clé 1", "mot-clé 2"],
"es": ["palabra clave 1", "palabra clave 2"],
"de": ["Schlüsselwort 1", "Schlüsselwort 2"],
"tr": ["anahtar kelime 1", "anahtar kelime 2"]
},
"email_template": {
"subject": {
"en": "{form_name} - {domain_title}",
"fa": "{form_name} - {domain_title}"
},
"body": {
"en": "Dear {user_name},\n\nThank you for your request...",
"fa": "عزیز {user_name}،\n\nاز درخواست شما متشکرم..."
}
},
"active": true
}
},
"metadata": {
"version": "1.0",
"last_updated": "2024-01-25",
"domain": "{domain_name}",
"supported_languages": ["en", "fa", "ar", "fr", "es", "de", "tr"]
}
}
Field Descriptions
Form Object:
name(object, required): Localized form names for each languageurl(string, required): URL to the form (must start withhttp://orhttps://)keywords(object, required): Keywords for form detection, organized by languageemail_template(object, optional): Email template for sending formssubject: Email subject template (supports{form_name},{domain_title})body: Email body template (supports{user_name},{form_name},{form_url},{domain_title})
active(boolean, required): Whether the form is currently available
Metadata:
version(string): Configuration versionlast_updated(string): Last update datedomain(string): Domain namesupported_languages(array): List of supported language codes
Services Configuration (services.json)
Location: {SEARCH_DOMAIN_FOLDER}/{domain_name}/services/services.json
Structure
{
"services": {
"{service_id}": {
"id": "{service_id}",
"name": {
"en": "English Service Name",
"fa": "نام سرویس فارسی"
},
"description": {
"en": "Service description in English",
"fa": "توضیحات سرویس به فارسی"
},
"icon": "🧻",
"category": "room_amenities",
"active": true
}
},
"metadata": {
"version": "1.0",
"detection_keywords": {
"en": "room service",
"fa": "سرویس اتاق"
},
"confirmation_message": {
"en": "Your request for {service_name} has been sent to our team. Someone will assist you shortly.",
"fa": "درخواست شما برای {service_name} به تیم ما ارسال شد. به زودی کسی به شما کمک خواهد کرد."
},
"supported_languages": ["en", "fa"]
}
}
Field Descriptions
Service Object:
id(string, required): Unique service identifiername(object, required): Localized service namesdescription(object, optional): Localized service descriptionsicon(string, optional): Emoji or icon identifier for the servicecategory(string, optional): Service category (e.g., "room_amenities", "food_beverage")active(boolean, required): Whether the service is currently available
Metadata:
version(string): Configuration versiondetection_keywords(object, required): Keywords for detecting service requests (one string per language, NOT arrays)confirmation_message(object, required): Message shown after service request (supports{service_name}placeholder)supported_languages(array): List of supported language codes
Technical Requirements
Backend Requirements
-
Python 3.11+
-
Dependencies:
- FastAPI
- Pydantic (for request/response models)
- Email sending capability (SMTP configuration)
-
Settings:
EARLY_DETECTION=true # Enable early detectionSEARCH_DOMAIN_FOLDER=/path/to/domains # Domain folder path -
Email Configuration (for form emailing):
SMTP_HOST=smtp.example.comSMTP_PORT=587SMTP_USER=your-email@example.comSMTP_PASSWORD=your-passwordSMTP_FROM=noreply@example.com
Frontend Requirements
- Flutter/Dart (for
aventora-bot) - WebSocket Support (for real-time communication)
- JSON Parsing (for structured messages)
Database Requirements
- PostgreSQL (for storing chat logs and form submissions)
- Tables:
chat_logs: Stores conversation historyform_submissions: Stores form request logs (if implemented)service_requests: Stores service request logs (if implemented)
Workflow
1. List Forms Workflow
User Query: "show available forms"
│
▼
Early Detection (ComprehensivePatternDetection)
│
├─ Pattern Match: LIST_FORMS detected
│
▼
list_forms_handler()
│
├─ FormManager.load_domain_forms(domain)
│ └─ Loads forms.json from disk
│
├─ FormManager.get_available_forms(domain)
│ └─ Filters active forms
│
├─ For each form:
│ └─ FormManager.get_form_info(domain, form_type, language)
│ └─ Returns localized name and URL
│
▼
Response:
{
"answer": "Here are the available forms:\n1. Employment Form\n2. Contact Form",
"message_type": "forms_list",
"clickableForms": [
{"type": "employment", "name": "Employment Form", "url": "https://..."},
{"type": "contact", "name": "Contact Form", "url": "https://..."}
],
"complete": true,
"continue": false
}
│
▼
WebSocket Handler
│
├─ Adds message_type and clickableForms to message_data
│
▼
Frontend (Flutter)
│
├─ Parses ASSISTANT_STRUCTURED message
│
├─ Detects messageType == "forms_list"
│
▼
FormsListWidget
│
└─ Displays clickable form buttons
2. Email Form Workflow
User Query: "send me the employment form"
│
▼
Early Detection
│
├─ Pattern Match: EMAIL_FORM detected
│
▼
email_form_handler()
│
├─ FormManager.detect_form_type_from_query()
│ └─ Matches keywords: "employment" → "employment"
│
├─ FormManager.get_form_info(domain, "employment", language)
│ └─ Returns form name and URL
│
▼
Response:
{
"answer": "I can send you the Employment Application Form. Please confirm your email address.",
"message_type": "form_request",
"formData": {
"form_type": "employment",
"form_name": "Employment Application Form",
"form_url": "https://...",
"form_id": "employment"
},
"complete": false,
"continue": true,
"action_needed": "confirm_email_send"
}
│
▼
Frontend
│
├─ Displays form request UI
│
├─ User confirms email
│
▼
POST /query/send-form-email
│
├─ send_form_email_handler()
│ └─ Sends email using email_template
│
▼
Confirmation message sent to user
3. List Services Workflow
User Query: "what services are available?"
│
▼
Early Detection
│
├─ Pattern Match: REQUEST_SERVICE detected (or LIST_FORMS pattern)
│
▼
list_services_handler()
│
├─ ServiceManager.load_domain_services(domain)
│ └─ Loads services.json from disk
│
├─ ServiceManager.get_available_services(domain, language)
│ └─ Filters active services, localizes names
│
▼
Response:
{
"answer": "Here are the available services:",
"message_type": "services_list",
"clickableServices": [
{"id": "towels", "name": "Extra Towels", "description": "...", "icon": "🧻"},
{"id": "water", "name": "Drinking Water", "description": "...", "icon": "💧"}
],
"complete": true,
"continue": false
}
│
▼
Frontend
│
└─ ServicesListWidget displays service buttons
4. Request Service Workflow
User clicks service button: "towels"
│
▼
Frontend sends: "I want to request towels service"
│
▼
Early Detection
│
├─ Pattern Match: REQUEST_SERVICE detected
│
▼
request_service_handler()
│
├─ ServiceManager.get_service_info(domain, "towels", language)
│ └─ Returns service details
│
├─ Email notification sent to admin
│ └─ Includes user name, email, service name
│
▼
Response:
{
"answer": "Your request for Extra Towels has been sent to our team. Someone will assist you shortly.",
"complete": true,
"continue": false
}
Early Detection System
Overview
The Early Detection system uses pattern matching to identify special tool requests before the query reaches the LLM. This provides:
- Fast Response: No LLM API call needed
- Accurate Detection: Pattern-based matching is more reliable than LLM interpretation
- Cost Savings: Reduces LLM API usage
- Consistent Behavior: Same patterns always trigger same actions
How It Works
- Pattern Database: Pre-defined regex patterns for each tool and language
- Detection Process:
detector = ComprehensivePatternDetection()result = detector.detect_intent(query, language, domain)# Returns DetectionResult with tool, confidence, reasoning
- Pattern Matching: Tests query against all patterns for the user's language
- Confidence Scoring: Calculates confidence based on pattern matches
- Tool Routing: Routes to appropriate handler if tool detected
Supported Tools
- EMAIL_TRANSCRIPT: User wants a copy of the conversation
- EMAIL_FORM: User wants a form emailed to them
- LIST_FORMS: User wants to see available forms
- REQUEST_SERVICE: User wants to request a service
Pattern Examples
English Patterns
LIST_FORMS:
"(what|which).*(forms|documents|papers).*(available|do you have|can i get)""(show|list|tell me).*(forms|documents|papers)""show available forms"✅
EMAIL_FORM:
"(form|document|paper).*(email|send|get|give|provide)""(email|send|get|give|provide).*(form|document|paper)""send me the employment form"✅
REQUEST_SERVICE:
"(i want|i need|request|order).*(service|room service)""room service"✅
Farsi Patterns
LIST_FORMS:
"(چه|کدوم).*(فرم|سند|کاغذ).*(موجوده|دارید|میتونم بگیرم)""لیست فرمها را نشان بده"✅
EMAIL_FORM:
"(فرم|سند|کاغذ).*(ایمیل|فرست|بده|ارسال)""فرم استخدام را برایم بفرست"✅
Adding New Patterns
To add new patterns, edit comprehensive_pattern_detection.py:
"en": {
SpecialTool.LIST_FORMS: [
r"your new pattern here",
r"another pattern",
]
}
Pattern Tips:
- Use regex groups
()for optional parts - Use
.*for flexible word order - Test patterns with various phrasings
- Consider common typos and variations
Configuration
Enable/disable early detection in .env:
EARLY_DETECTION=true # Enable
EARLY_DETECTION=false # Disable (falls back to normal LLM flow)
API Integration
Endpoints
1. Query Endpoint (with Early Detection)
POST /query/
{
"question": "show available forms",
"domain": "kalano",
"language": "en",
"name": "John Doe",
"email": "john@example.com",
"user_id": 123,
"domain_metadata": {}
}
Response (Forms List):
{
"answer": "Here are the available forms:\n1. Employment Application Form\n2. Contact Form",
"message_type": "forms_list",
"clickableForms": [
{
"type": "employment",
"name": "Employment Application Form",
"url": "https://kalano.com/forms/employment"
},
{
"type": "contact",
"name": "Contact Form",
"url": "https://kalano.com/forms/contact"
}
],
"complete": true,
"continue": false,
"session": [...]
}
Response (Form Request):
{
"answer": "I can send you the Employment Application Form. Please confirm your email address.",
"message_type": "form_request",
"formData": {
"form_type": "employment",
"form_name": "Employment Application Form",
"form_url": "https://kalano.com/forms/employment",
"form_id": "employment"
},
"complete": false,
"continue": true,
"session": [...]
}
2. Send Form Email Endpoint
POST /query/send-form-email
{
"form_id": "employment",
"user_email": "john@example.com",
"user_name": "John Doe",
"language": "en",
"domain": "kalano"
}
Response:
{
"message": "The Employment Application Form has been sent to your email.",
"success": true
}
3. Request Service Endpoint
POST /query/request-service
{
"service_id": "towels",
"user_name": "John Doe",
"user_email": "john@example.com",
"language": "en",
"domain": "kalano"
}
Response:
{
"message": "Your request for Extra Towels has been sent to our team. Someone will assist you shortly.",
"success": true
}
WebSocket Integration
The WebSocket handler (Agent/server/websocket.py) processes responses and adds structured data:
if resp.get("message_type") == "forms_list":
message_data["message_type"] = resp.get("message_type")
message_data["clickableForms"] = resp.get("clickableForms")
if resp.get("message_type") == "services_list":
message_data["message_type"] = resp.get("message_type")
message_data["clickableServices"] = resp.get("clickableServices")
Frontend Integration
Flutter Integration (aventora-bot)
1. Message Parsing
The ChatScreenD widget parses structured messages:
if (value.startsWith('ASSISTANT_STRUCTURED:')) {
final structuredData = value.substring(21);
final messageData = jsonDecode(structuredData);
final messageType = messageData['messageType'];
final clickableForms = messageData['clickableForms'];
final clickableServices = messageData['clickableServices'];
_addMessageToChat(
messageId,
assistantText,
'assistant',
null,
nowMs,
messageType: messageType,
clickableForms: clickableForms,
clickableServices: clickableServices,
);
}
2. Forms List Widget
FormsListWidget displays clickable form buttons:
if (widget.message.messageType?.toLowerCase() == 'forms_list' &&
widget.message.clickableForms != null) {
return FormsListWidget(
forms: widget.message.clickableForms!,
onFormSelected: widget.onUserResponse,
isRTL: widget.isRTL,
);
}
3. Services List Widget
ServicesListWidget displays clickable service buttons:
if (widget.message.messageType?.toLowerCase() == 'services_list' &&
widget.message.clickableServices != null) {
return ServicesListWidget(
services: widget.message.clickableServices!,
onServiceRequested: widget.onUserResponse,
isRTL: widget.isRTL,
);
}
4. Trigger Phrases
The "View Forms" button sends a trigger phrase:
void _onFormsButtonPressed() {
String triggerPhrase;
switch (currentLanguage) {
case 'fa':
triggerPhrase = 'لیست فرمها را نشان بده';
break;
case 'ar':
triggerPhrase = 'أظهر قائمة النماذج';
break;
default:
triggerPhrase = 'show available forms';
}
_sendMessage(triggerPhrase);
}
Message Format
Structured Message Format:
ASSISTANT_STRUCTURED:{"text":"...","messageType":"forms_list","clickableForms":[...]}
Fields:
text: Human-readable message textmessageType:"forms_list"|"services_list"|"form_request"|"admin_call_form"|nullclickableForms: Array of form objects (ifmessageType == "forms_list")clickableServices: Array of service objects (ifmessageType == "services_list")formData: Form request data (ifmessageType == "form_request")adminCallFormData: Inline form for "talk to admin" (ifmessageType == "admin_call_form")
Admin Call Form (messageType == "admin_call_form")
When the user says "talk to admin" / "can I speak with an administrator", the backend returns messageType: "admin_call_form" and adminCallFormData with an inline form (no regex parsing). The frontend should render the form and, on submit, send a continue request with:
admin_call_name: from fieldid: "name"admin_call_phone: from fieldid: "phone"admin_call_subject: from fieldid: "subject"admin_call_preferred_channel: one of"sms"|"wmsg"|"phone"from fieldid: "preferred_channel"
adminCallFormData shape:
intro: string (optional message)fields:[{ id, type, label, required, value?, options? }]—idis"name"|"phone"|"subject"|"preferred_channel";preferred_channelhasoptions: [{ value: "sms"|"wmsg"|"phone", label }]submit_label: string for the submit button
Configuration Examples
Example 1: Healthcare Domain Forms
{
"forms": {
"patient_intake": {
"name": {
"en": "Patient Intake Form",
"fa": "فرم پذیرش بیمار"
},
"url": "https://hospital.example.com/forms/patient-intake",
"keywords": {
"en": ["intake", "patient form", "registration", "admission"],
"fa": ["پذیرش", "فرم بیمار", "ثبت نام", "بستری"]
},
"email_template": {
"subject": {
"en": "Patient Intake Form - {domain_title}",
"fa": "فرم پذیرش بیمار - {domain_title}"
},
"body": {
"en": "Dear {user_name},\n\nPlease complete the Patient Intake Form at:\n{form_url}\n\nThank you.",
"fa": "عزیز {user_name}،\n\nلطفاً فرم پذیرش بیمار را در لینک زیر تکمیل کنید:\n{form_url}\n\nمتشکرم."
}
},
"active": true
},
"appointment": {
"name": {
"en": "Appointment Booking Form",
"fa": "فرم رزرو نوبت"
},
"url": "https://hospital.example.com/forms/appointment",
"keywords": {
"en": ["appointment", "booking", "schedule", "visit"],
"fa": ["نوبت", "رزرو", "وقت", "ویزیت"]
},
"active": true
}
},
"metadata": {
"version": "1.0",
"domain": "hospital",
"supported_languages": ["en", "fa"]
}
}
Example 2: Hotel Domain Services
{
"services": {
"room_service": {
"id": "room_service",
"name": {
"en": "Room Service",
"fa": "سرویس اتاق"
},
"description": {
"en": "Order food and beverages to your room",
"fa": "سفارش غذا و نوشیدنی به اتاق شما"
},
"icon": "🍽️",
"category": "food_beverage",
"active": true
},
"laundry": {
"id": "laundry",
"name": {
"en": "Laundry Service",
"fa": "خدمات لباسشویی"
},
"description": {
"en": "Request laundry and dry cleaning services",
"fa": "درخواست خدمات لباسشویی و خشکشویی"
},
"icon": "👔",
"category": "housekeeping",
"active": true
}
},
"metadata": {
"version": "1.0",
"detection_keywords": {
"en": "room service",
"fa": "سرویس اتاق"
},
"confirmation_message": {
"en": "Your request has been sent to our team. We'll assist you shortly.",
"fa": "درخواست شما به تیم ما ارسال شد. به زودی به شما کمک خواهیم کرد."
},
"supported_languages": ["en", "fa"]
}
}
Troubleshooting
Issue: Early Detection Not Triggering
Symptoms:
- User query "show available forms" goes to LLM instead of handler
- No "EARLY DETECTION" logs in console
Solutions:
-
Check Environment Variable:
# In .env fileEARLY_DETECTION=true -
Verify Pattern Matching:
- Check logs for detection attempts
- Test patterns manually with regex tester
- Ensure query matches pattern (case-insensitive)
-
Check Service File:
- Verify
router.pyimports fromservice_vector.py(orservice.py) - Ensure early detection code is present in both
process_queryandcontinue_query
- Verify
-
Language Mismatch:
- Verify
request.languagematches pattern language - Check that patterns exist for the user's language
- Verify
Issue: Forms Not Loading
Symptoms:
- Error: "Forms file not found"
- Empty forms list returned
Solutions:
-
Check File Path:
{SEARCH_DOMAIN_FOLDER}/{domain_name}/forms/forms.json -
Verify JSON Structure:
- Validate JSON syntax
- Ensure
formsandmetadatakeys exist - Check required fields:
name,url,keywords,active
-
Check Permissions:
- Ensure file is readable
- Check file encoding (must be UTF-8)
-
Clear Cache:
from LLM_full.query.form_manager import form_managerform_manager.clear_cache(domain="your_domain")
Issue: Services Not Loading
Symptoms:
- Error: "Services file not found"
- Empty services list returned
Solutions:
-
Check File Path:
{SEARCH_DOMAIN_FOLDER}/{domain_name}/services/services.json -
Verify JSON Structure:
- Validate JSON syntax
- Ensure
servicesandmetadatakeys exist - Check
detection_keywordsis a dictionary (not array)
-
Validate Detection Keywords:
// ✅ Correct"detection_keywords": {"en": "room service","fa": "سرویس اتاق"}// ❌ Wrong (arrays not supported)"detection_keywords": {"en": ["room", "service"],"fa": ["سرویس", "اتاق"]}
Issue: Frontend Not Displaying Forms/Services
Symptoms:
- Backend returns
clickableFormsbut frontend shows plain text
Solutions:
-
Check Message Type:
- Verify
message_typeis set in response - Check WebSocket handler adds
messageTypetomessage_data
- Verify
-
Verify Frontend Parsing:
- Check
ASSISTANT_STRUCTURED:prefix is present - Verify JSON parsing in
ChatScreenD - Check
messageTypecomparison (case-insensitive)
- Check
-
Check Widget Conditions:
// Ensure both conditions are metmessageType?.toLowerCase() == 'forms_list' &&clickableForms != null -
Debug Logging:
print('DEBUG: messageType=$messageType');print('DEBUG: clickableForms=$clickableForms');
Issue: Email Not Sending
Symptoms:
- Form request succeeds but email not received
Solutions:
-
Check SMTP Configuration:
SMTP_HOST=smtp.example.comSMTP_PORT=587SMTP_USER=your-email@example.comSMTP_PASSWORD=your-passwordSMTP_FROM=noreply@example.com -
Verify Email Template:
- Check
email_templateexists informs.json - Verify placeholders:
{user_name},{form_name},{form_url},{domain_title}
- Check
-
Check Logs:
- Look for email sending errors
- Verify email address format
Issue: Pattern Not Matching
Symptoms:
- Query should match pattern but doesn't
Solutions:
-
Test Pattern Manually:
import repattern = r"(show|list|tell me).*(forms|documents|papers)"query = "show available forms"match = re.search(pattern, query, re.IGNORECASE)print(match) # Should not be None -
Check Case Sensitivity:
- Patterns use
re.IGNORECASEflag - But verify query is lowercased in detection
- Patterns use
-
Add Debug Logging:
logger.info(f"Testing pattern: {pattern}")logger.info(f"Against query: {query}")logger.info(f"Match result: {match}") -
Consider Variations:
- Add more patterns for common phrasings
- Test with typos and variations
Common Configuration Errors
-
Missing Required Fields:
// ❌ Missing "active" field{"name": {...},"url": "...","keywords": {...}}// ✅ Correct{"name": {...},"url": "...","keywords": {...},"active": true} -
Invalid URL Format:
// ❌ Missing http://"url": "example.com/forms/employment"// ✅ Correct"url": "https://example.com/forms/employment" -
Wrong Detection Keywords Format:
// ❌ Array instead of string"detection_keywords": {"en": ["room", "service"]}// ✅ Correct"detection_keywords": {"en": "room service"}
Best Practices
Forms Configuration
-
Use Descriptive Keywords:
- Include common variations and synonyms
- Add both full form names and abbreviations
- Consider typos and common misspellings
-
Localize Thoroughly:
- Provide translations for all supported languages
- Use native speakers for translations
- Test with native speakers
-
Keep URLs Updated:
- Use absolute URLs (https://)
- Test URLs regularly
- Provide fallback URLs if needed
Services Configuration
-
Clear Service Names:
- Use descriptive, user-friendly names
- Keep names concise
- Avoid technical jargon
-
Helpful Descriptions:
- Explain what the service does
- Include any prerequisites or requirements
- Set user expectations
-
Appropriate Categories:
- Group related services
- Use consistent category names
- Consider UI grouping
Pattern Design
-
Start Broad, Then Narrow:
- Begin with general patterns
- Add specific patterns for edge cases
- Test with real user queries
-
Avoid Over-Matching:
- Be specific enough to avoid false positives
- Test patterns with unrelated queries
- Monitor false positive rates
-
Document Patterns:
- Comment complex patterns
- Explain why patterns are needed
- Keep pattern database organized
Performance
-
Cache Management:
- Forms and services are cached in memory
- Clear cache after configuration changes
- Monitor cache size for large domains
-
Early Detection First:
- Always enable early detection for cost savings
- Monitor detection accuracy
- Adjust patterns based on metrics
-
Error Handling:
- Gracefully handle missing files
- Provide fallback messages
- Log errors for debugging
Conclusion
The Forms and Services functionality provides a powerful way to extend the chatbot beyond simple Q&A. By following this documentation, you can:
- Configure forms and services for your domain
- Understand the complete workflow from user query to response
- Troubleshoot common issues
- Extend the system with new patterns and handlers
For additional support, refer to:
domain-chatbot/docs/Technical-documentation.md- General technical documentationdomain-chatbot/docs/Features.md- Feature overviewdomain-chatbot/docs/APIs.md- API documentation