Effective data collection is essential for voice agents that need to gather information from callers. Hamsa provides multiple methods to collect, validate, and use data throughout conversations, from simple name collection to complex multi-field forms.
Data Collection Methods:
Natural Language Extraction - AI extracts data from spoken conversation
DTMF Input Capture - Collect digits via keypad
Structured Prompting - Guide users to provide specific information
The most natural method - AI extracts information from conversation.How It Works:
User speaks naturally
AI identifies and extracts specific data
Data stored in variables
Available for use throughout the flow
Example: Collecting Customer Information
Conversation Node: Collect_Info Message: "I'll need a few details to help you. What's your name and phone number?" Variable Extraction: - Variable: customer_name Instructions: "Extract the customer's full name" - Variable: phone_number Instructions: "Extract phone number in format XXX-XXX-XXXX"User Response: "My name is John Smith and my number is 555-123-4567"Extracted: customer_name: "John Smith" phone_number: "555-123-4567"
Ask specific questions to collect structured data.How It Works:
Ask focused, single questions
Extract one piece of information
Confirm understanding
Move to next question
Example: Appointment Scheduling
Node 1: Get_Date Message: "What date would you like to schedule? For example, January 15th." Extract: appointment_dateNode 2: Confirm_Date Message: "Got it, {{appointment_date}}. And what time works best for you?" Extract: appointment_timeNode 3: Verify_All Message: "Perfect! I have you scheduled for {{appointment_date}} at {{appointment_time}}. Is that correct?" Extract: confirmation (yes/no)
Extracted Variables: Collected during conversation
Custom Variables: Passed via API when call starts
System Variables: Built-in (time, caller ID, etc.)
✗ name (too vague)✗ customerName (use snake_case, not camelCase)✗ customer-name (no hyphens)✗ Customer Name (no spaces or capitals)✗ var1 (not descriptive)✗ temp (unclear purpose)
✓ "Extract the customer's full name"✓ "Extract email address in format [email protected]"✓ "Extract appointment date in MM/DD/YYYY format"✓ "Extract order number (starts with ORD-)"✗ "Get the name"✗ "Extract email"✗ "Get the date"
With Examples:
Variable: phone_numberInstructions: "Extract 10-digit phone number. Examples: 555-123-4567, (555) 123-4567, 5551234567. Store in format: XXX-XXX-XXXX"Variable: appointment_dateInstructions: "Extract date mentioned by caller. Examples: 'next Tuesday', 'January 15th', '1/15/2024'. Convert to YYYY-MM-DD format."
Node 1: Request_Account Message: "For security, I'll need to verify your account. Please enter your account number using your keypad, followed by the pound key." DTMF Input Capture: Variable: account_number Digit Limit: 10 Termination Key: #Node 2: Request_PIN Message: "Thank you. Now please enter your 4-digit PIN." DTMF Input Capture: Variable: pin_code Digit Limit: 4 Timeout: 15sNode 3: Verify_Credentials (Tool) Tool: verify_account Parameters: account: {{account_number}} pin: {{pin_code}} call_id: {{call_id}} Transitions: - API returns success → Authenticated_Menu - API returns failure → Retry_Authentication - After 3 failures → Transfer_SecurityNode 4: Retry_Authentication Message: "I couldn't verify those credentials. Let's try again. Please enter your account number."Node 5: Authenticated_Menu Message: "Thank you for verifying your identity, {{customer_name}}. How can I help you today?"
Node 1: Collect_ZIP Message: "What's your ZIP code? You can say it or enter it on your keypad, followed by pound." DTMF Input Capture: Variable: zip_code Digit Limit: 5 Termination Key: # Extract Variables: - zip_code: "Extract 5-digit ZIP code if spoken" # Either method populates zip_code variableNode 2: Collect_Date Message: "What date would you like? You can say something like 'next Tuesday' or 'January 15th'." Extract Variables: - appointment_date: "Extract date, convert to YYYY-MM-DD"Node 3: Confirm_Details Message: "I have ZIP code {{zip_code}} and date {{appointment_date}}. Is that right?"
Survey Flow:Node 1: Introduction Message: "This quick survey takes about 2 minutes. Your feedback helps us improve."Node 2: Question_1 Message: "On a scale of 1 to 5, with 5 being very satisfied, how satisfied are you with our service? You can say the number or press it on your keypad." DTMF Input Capture: Variable: satisfaction_score Digit Limit: 1 Extract Variables: - satisfaction_score: "Extract number 1-5" Validation: - satisfaction_score must be 1-5Node 3: Question_2 Message: "Would you recommend us to a friend? Yes or no?" Extract Variables: - would_recommend: "Extract yes or no"Node 4: Question_3 (Conditional) Condition: satisfaction_score < 3 Message: "I'm sorry to hear that. Can you tell me what we could improve?" Extract Variables: - improvement_feedback: "Extract detailed feedback"Node 5: Submit_Survey (Tool) Tool: submit_survey_results Parameters: satisfaction: {{satisfaction_score}} recommend: {{would_recommend}} feedback: {{improvement_feedback}} caller: {{user_number}} date: {{current_date}}Node 6: Thank_You Message: "Thank you for your feedback, we really appreciate it!"
Ensure data meets expected format.Email Validation:
Node: Collect_Email Message: "What's your email address?" Extract Variables: - email_address: "Extract email in format [email protected]"Validation Node: Condition: email_address contains "@" AND email_address contains "." If valid → Continue If invalid → "That doesn't look like a valid email. Could you spell it out for me? For example, john at example dot com."
Phone Number Validation:
Validation Logic: - Length: Must be 10 digits - Format: (XXX) XXX-XXXX or XXX-XXX-XXXX or XXXXXXXXXX - Area code: First digit cannot be 0 or 1Error Message: "I need a 10-digit phone number. For example, 555-123-4567. What's your phone number?"
Date Validation:
Validation Logic: - Must be future date (for appointments) - Must be valid calendar date - Must be within acceptable rangeError Message: "That date doesn't work. I can schedule appointments up to 6 months out. What date would you like?"
Node: Collect_Age Message: "For verification, how old are you?" Extract Variables: - age: "Extract age as number"Validation: - age >= 18 AND age <= 120 → Valid - age < 18 → "I'm sorry, you must be 18 or older." - age > 120 → "That doesn't seem right. What's your age?"Node: Collect_Quantity Message: "How many would you like to order?" Extract Variables: - quantity: "Extract number"Validation: - quantity >= 1 AND quantity <= 100 → Valid - quantity < 1 → "I need at least 1 item." - quantity > 100 → "For orders over 100, please contact our sales team directly."
Node: Collect_Order_Number Message: "What's your order number?" Extract Variables: - order_number: "Extract order number (format ORD-XXXXX)"Validation Tool: Tool: check_order_exists Parameters: order_number: {{order_number}} Transitions: - Order found → Display_Order_Info - Order not found → "I couldn't find that order number. Can you double-check and try again?" - After 3 attempts → "Let me transfer you to customer service."
Node: Collect_Email Message: "What's your email address?" Extract: email_addressNode: Confirm_Email Message: "I heard {{email_address}}. Is that correct?" Extract: confirmation Transitions: - "yes" → Continue - "no" → "Let's try again. Can you spell it out? For example, J-O-H-N at G-M-A-I-L dot com."
Strategy: Phonetic Spelling
After Error: "I'm having trouble hearing that. Let me try a different way. Can you spell your email letter by letter? For example, J for John, O for Oscar, H for Hotel..."Extract as: Phonetic sequenceConvert to: email_address
Node: Collect_Date Message: "What date would you like?"User: "Soon"Problem: Too vagueResponse: "I can schedule appointments starting tomorrow through the next 6 months. What specific date works for you? For example, next Monday, or January 15th?"User: "Monday"Problem: Which Monday?Response: "Did you mean Monday, January 15th, or Monday, January 22nd?"
Node: Collect_Address Message: "What's your street address?"User: "123 Main Street"Problem: No city, state, ZIPSolution: Follow-up questions "And what city is that in?" "What's the ZIP code?"Or: Structured prompting "I'll need your complete address. What's the street address?" [collect] "And the city?" [collect] "State?" [collect] "ZIP code?"
Node: Collect_All_At_Once Message: "To send you a quote, I'll need your email and phone number." Extract Variables: - email_address: "Extract email address" - phone_number: "Extract phone number"User: "My email is [email protected] and you can reach me at 555-1234"Extracted: email_address: "[email protected]" phone_number: "555-1234"Validation Node: Check both variables: - If email exists AND phone exists → Continue - If only email → "Great! And your phone number?" - If only phone → "Got it. And your email address?" - If neither → "Let me ask separately. What's your email?"
Router: Check_Existing_DataCondition: {{user_number}} in customer_database → Lookup customer data → "Welcome back, {{customer_name}}! I have your email as {{email_address}}. Is that still correct?"Condition: {{user_number}} NOT in customer_database → "I don't have your information yet. What's your name?" → Full collection flow
Variables stored in call context: - Available throughout conversation - Passed between nodes - Used in tools and routing - Included in call logs
After Call:
Method 1: Webhooks - Send data to your server - Store in your database - Trigger workflowsMethod 2: Outcomes - Define outcome schema - Automatically extract at call end - Retrieve via APIMethod 3: Tools - Call your API during conversation - Store data real-time - Return confirmation