version: 1.0.0
sections:
    main:
      - ai:
          post_prompt_url: https://cantina.signalwire.cloud/aicgi/post.cgi
          post_prompt_auth_user: developer
          post_prompt_auth_password: seekret
          params:
            end_of_speech_timeout: 750
            audible_debug: true
          prompt:
            top_p: 0.9
            temperature: 0.7
            text: Your name is Sigourney, you are a SignalWire Ditital Employee developed with their AI Agent Stack
            contexts:
              default:
                steps:
                  - name: main_menu
                    text: |+
                      Introduce yourself and ask the user if they would like to find a restaurant.
                      If they do go to the next step otherwise go to the done step.
                    valid_steps:
                      - next
                      - done
                    functions: none
                    step_criteria: |+
                      The user must indicate that they want to find a restaurant.
                  - name: get_address
                    text: |+
                      Ask the user to provide you with a street address and zip code to search but you must not search.
                      After they provide one, then you may look it up.
                    step_criteria: |+
                      The user has supplied a valid address.
                    functions:
                      - address_lookup
                  - name: review_results
                    text: |+
                      Ask the user what kind of food they want to search for but you must not search.
                      After the user responds, then you may search.
                      Explain the results to the user. Do not mention the record_id.

                      If the user mentions one of the restaurants, look up the record_id and tell the user the details.
                      If the user asks to change the address, go to the get_address step, if they are done go to the done step.
                    step_criteria: |+
                      Remain on this step unless the user says they are done or says they want to change the address.
                    functions:
                      - restaurant_lookup
                    valid_steps:
                      - get_address
                      - done
                  - name: done
                    text: |+
                      Thank the user for their time and end the call
                  
          post_prompt:
            text: Summarize the conversation
          languages:
            - name: English
              code: en-US
              voice: gcloud.en-US-Neural2-H
          SWAIG:
            defaults:
              web_hook_url: https://cantina.signalwire.cloud/aicgi/swaig.cgi
              web_hook_auth_user: developer
              web_hook_auth_password: seekret
            functions:
              - function: address_lookup
                fillers:
                  en-US:
                    - looking up the address now
                purpose: To check if an address is valid, When using this function make sure you collect the street and zip
                argument:
                  type: "object"
                  properties:
                    street:
                      type: string
                      description: the street addr e.g. 1234 N Main st.
                    zipcode:
                      type: string
                      description: the 5 digit zipcode
                  required:
                    - street
                    - zipcode
                data_map:
                  webhooks:
                    - url: "https://global-address.p.rapidapi.com/V3/WEB/GlobalAddress/doGlobalAddress?ctry=US&format=json&a1=${enc:args.street}&DeliveryLines=Off&postal=${args.zipcode}"
                      headers:
                        X-RapidAPI-Key: 267f62153emsh5f536bcc582ddccp1408e0jsn793d31f7bbb4
                        X-RapidAPI-Host: global-address.p.rapidapi.com
                      expressions:
                        - string: "${Records[0].PostalCode}"
                          pattern: /\d+/
                          output:
                            response: The Address is valid ${Records[0].FormattedAddress}
                            action:
                              back_to_back_functions: true
                              set_meta_data:
                                addr: "${Records[0].FormattedAddress}"
                                LL: "${Records[0].Latitude},${Records[0].Longitude}"
                      output:
                        response: The Address is not valid
              - function: restaurant_lookup
                fillers:
                  en-US:
                    - checking the restaurant database
                purpose: To look for restaurants given a certian genre or record_id
                argument: 
                  type: object
                  properties: 
                     genre:
                       type: string
                       description: the genre of food
                     record_id:
                       type: string
                       description: the record_id to look up a specific record_id
                data_map:
                  webhooks:
                    - require_args: record_id
                      error_keys: error
                      url: "https://api.content.tripadvisor.com/api/v1/location/${args.record_id}/details?key=C21562F41A3E4D30988BBED54FD403EF&language=en&currency=USD"
                      output:
                        response: "Repeat this info for ${name}. ${description} Address: (omit plus 4) ${address_obj.address_string}, Number: ${phone}, Rating: ${rating}, Ranking: ${ranking_data.ranking_string}"
                    - require_args: genre
                      error_keys: error
                      url: "https://api.content.tripadvisor.com/api/v1/location/search?key=C21562F41A3E4D30988BBED54FD403EF&searchQuery=${lc:enc:args.genre}&latLong=${enc:meta_data.LL}&language=en"
                      foreach:
                        input_key: data
                        output_key: summary
                        max: 3
                        append: "record_id: ${this.location_id} name: ${this.name} distance: ${this.distance} miles\n"
                      output:
                        response: "Here are the top 3 matches. ${summary}\n(Never mention the record_id)"