state = {}
meta_prompt = "You're an assistant that helps the user book shifts."
res = say("Hello, I'm a chatbot. Let's start by gathering your details.")
loop:
# Initiate conversation to collect user details.
phone_response = talk(
f"{meta_prompt} Please provide your phone number, full name, and facility name. Confirm these details once provided.",
True,
{"phone_number": "+16179011508", "full_name": "John Doe", "facility_name": "Facility A"}
)
until "User has provided phone number, full name, and facility name and confirmed them":
# Extract the user details.
info = phone_response.ask(
question="Extract the user's phone number, full name, and facility name.",
example={"phone_number": "+16179011508", "full_name": "John Doe", "facility_name": "Facility A"}
)
random_value = RANDOM(10).generate()
answer_ = api.get_req(
url='https://apigateway.example.com/api/facilities',
headers={
'authorization': 'Bearer 123',
'cbh-facility-user-phone-number-auth': info["phone_number"],
'cbh-external-caller-session': random_value
}
).ask(
question="Verify the provided details. If successful, return the user's name, facility name, and email; otherwise, return 'ERROR'.",
example={"name": "John Doe", "facility_name": "Facility A", "email": "john.doe@example.com", "success": true}
)
print("Answer:", answer_)
if not answer_["success"]:
loop:
phone_response = talk("Sorry, we couldn't verify your details. Please re-enter your information.", True)
until "User confirms corrected details":
info = phone_response.ask(
question="Return the user's phone number, full name, and facility name.",
example={"phone_number": "+16179011508", "full_name": "John Doe", "facility_name": "Facility A"}
)
state["info"] = info
else:
print("Verification successful:", answer_)