We are deploying a PYTHON WEBHOOK for our US/EASTERN COGNIGY.AI instance to handle DYNAMIC SLOT FILLING on the COMPLIANCE ROUTING BOT. The script watches incoming utterances, checks for missing values, and fires clarification prompts through the DIALOG API based on priority. We wrote a FLASK endpoint that grabs the request payload, runs REGEX patterns against the text to pull out entities, and compares them to the SESSION CONTEXT to catch conflicts. The SLOT UPDATE LOGIC keeps overwriting valid data when the PRIORITY CHECK runs. It is breaking the context entirely. The flow never advances even after every REQUIRED FIELD gets a value. We are calling the COGNIGY DIALOG API to push the updated variables back but the response just loops the same intent instead of moving to the next node. REGEX works fine in isolation. Just not holding together in the loop. Here is the current handler we are testing against the STAGING ENVIRONMENT.
import re
from flask import Flask, request, jsonify
import requests
app = Flask(__name__)
@app.route('/cognigy-slot-webhook', methods=['POST'])
def handle_slots():
data = request.json
utterance = data.get('input', {}).get('text', '')
session_vars = data.get('session', {}).get('variables', {})
required = ['case_number', 'agent_id', 'compliance_flag']
missing = [s for s in required if s not in session_vars]
if missing:
priority_slot = missing[0]
regex_map = {'case_number': r'CASE-(\d+)', 'agent_id': r'AGT-\w{3}'}
match = re.search(regex_map.get(priority_slot, ''), utterance)
if match:
new_val = match.group(1)
if priority_slot in session_vars and session_vars[priority_slot] != new_val:
pass
session_vars[priority_slot] = new_val
else:
requests.post('https://api.cognigy.ai/v1/dialog', json={'action': 'clarify', 'slot': priority_slot})
if not missing:
requests.post('https://api.cognigy.ai/v1/dialog', json={'action': 'advance', 'vars': session_vars})
return jsonify({'status': 'complete'})
return jsonify({'status': 'pending', 'vars': session_vars})