Function
Start Function
The Start Function is a special function triggered unconditionally at the beginning of a conversation. Its purpose is to setup the call before it starts, and it runs synchronously which means the greeting message will not be read until it has finished executing. This setup process typically involves gathering relevant data, such as reading SIP headers or fetching the current date and time. It may also include making API calls or performing other necessary setup actions to ensure the conversation has the correct context.
Use Cases
The Start Function can be leveraged in a variety of ways, including but not limited to:
- Reading SIP Headers: You may want to capture information from the SIP headers for metadata such as caller ID, call origin, or any other relevant telephony data. This could be used to find user information, or determine which hotel site is being called.
- Retrieving Date and Time: Gathering the current date and time at the start of the conversation to timestamp the interaction or use in later conversation logic.
- Making API Calls: If external data or systems are needed to set up the conversation, the start function can initiate API calls to gather required information, such as fetching customer data or pulling user preferences.
import datetime as dt
import re
def start_function(conv: Conversation):
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")
conv.state.available_times=None
conv.state.user_bookings= None
conv.state.phone_number= None
from_header=conv.sip_headers.get('From','')
match=re.search("sip:(.+?)@",from_header)
if match:
conv.state_phone_number=match.group(1)
return str()