The Start Function is executed immediately when a conversation begins, ensuring that the assistant is fully prepared to handle user interactions. It runs synchronously, meaning the greeting message will not be played until the Start Function has completed its tasks. This function is essential for setting up key context and initializing the conversation state.

Key features and functionality

  1. Synchronous execution: Ensures the setup process is complete before the conversation begins.

  2. Customizable initialization: Allows for dynamic setup tailored to the specific use case.

  3. Context preparation: Gathers and stores data that informs subsequent steps in the conversation.

Use cases

The Start Function:

1. Reads SIP headers

  • Capture metadata like caller ID, call origin, or telephony-specific information.

  • Example use case: Determine the hotel site or business branch the call is directed to based on telephony headers.

2. Retrieves date and time

  • Initialize state with the current date, time, or day of the week for timestamping or scheduling logic.

  • Example use case: Preload available time slots for scheduling queries or confirm user-requested dates.

3. Makes API calls

  • Fetch external data such as user preferences, account information, or customer records.

  • Example use case: Retrieve and preload personalized data to enhance the conversation’s responsiveness and user experience.

Implementation example

Below is a Python implementation of the Start Function:

import datetime as dt
import re

def start_function(conv: Conversation):
    # Retrieve the current date and time
    now = dt.datetime.now()
    conv.state.current_date = now.strftime("%A %d-%m-%Y")
    conv.state.current_weekday = now.strftime("%A")
    conv.state.current_time = now.strftime("%H:%M")

    # Initialize state variables
    conv.state.available_times = None
    conv.state.user_bookings = None
    conv.state.phone_number = None

    # Extract the phone number from SIP headers
    from_header = conv.sip_headers.get('From', '')
    match = re.search(r"sip:(.+?)@", from_header)
    if match:
        conv.state.phone_number = match.group(1)

    # Return an empty string to indicate successful execution
    return str()

Best practices for Start Function design

  1. Efficient execution: Ensure the function completes quickly to minimize delays in starting the conversation.

  2. Error handling:

    • Handle missing or malformed data gracefully to avoid runtime errors.

    • Provide fallbacks for incomplete or invalid information (like missing SIP headers).

  3. State initialization:

    • Predefine and initialize all state variables needed for the conversation to avoid undefined behaviors.
  4. Contextual relevance:

    • Only include setup steps that are directly relevant to the conversation’s purpose.

    • Avoid overloading the Start Function with unnecessary logic.

Add Context and Personalization with the Start Function

Personalization is essential for creating exceptional customer experiences. By leveraging the Start Function, the assistant can incorporate context to deliver personalized experiences seamlessly, ensuring every caller feels valued and understood. This not only enhances customer satisfaction but also boosts trust and engagement with your brand. Information collected from SIP headers, API calls or during the conversation can be stored in Variables.

Below are examples of how the Start Function can be used for personalization:

📞 Dynamic Caller Identification

Use information like the caller’s phone number or metadata to greet them personally and acknowledge their history with your business.

Example:

  • “Hello, John! Thank you for calling. How can we assist you today?”

  • “Hi! It looks like you’re calling about your recent order. Would you like to discuss that today?”

🛒 Personalized Recommendations

Make an API call to reference user preferences or interaction history to suggest products, services, or solutions tailored to the caller’s needs.

Example:

  • “Based on your recent purchases, we think you might like our new line of wireless headphones!”

  • “I see you’ve been interested in our premium package. Would you like to learn more about its benefits?”

📅 Preloading Relevant Context

Prepare scheduling information or past bookings to streamline conversations and save time for the caller.

Example:

  • “Your last appointment was on January 3rd. Would you like to book another one?”

  • “I see there’s an available time slot tomorrow at 2 PM. Should I reserve that for you?”

📂 Customized Support Based on Account Details

Retrieve account-specific information, such as subscription plans or recent activity, to provide targeted assistance.

Example:

  • “It looks like you’re on our Gold Membership plan. Let me share some exclusive offers with you.”

  • “I see you recently opened a support ticket. Would you like an update on its status?”