Google script Get function
# support
c
Can anyone help me with the following task? I'm using the dashboard to create an assistant, and I need to implement a function that the assistant asks for an address and then verifies it using the link below. This link points to a Google Apps Script that takes the address and validates it. If the address is correct, it returns the full address. If there are issues, like an incorrect suite number or name, it returns a message indicating the specific error. How can I integrate this into my system using the functions? Here is the link: https://script.google.com/macros/s/app_script_ID/exec?func=VerifyAddress&address={address}
v
Hi @Chaim T, I'm an AI assistant for Vapi. I'll analyze available sources and get back to you shortly.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Pizza Website Example]() * [Web Calling]() * [Voice Widget Example]() * [Server Events]() -----------------------------
### Answer To integrate a function that interacts with a Google Apps Script for address verification into your assistant created through Vapi, you'll need to define a custom function in your assistant's configuration. This custom function will make HTTP requests to your Google Script URL, passing it the address and handling the response accordingly. Here's a step-by-step guide on how you can set this up using Vapi: 1. **Define the Assistant Model and Custom Function**: You need to set up your assistant model in Vapi to include a custom function that can call your Google Apps Script. You will use the
function-call
message type to integrate this custom function. 2. **Configure the Function**: Define a function in the
functions
array of your assistant's model. This function should be capable of making an HTTP GET request to your Google Apps Script URL. You'll pass the address as a query parameter. 3. **Handling the Function in Server Code**: On your server, you'll need to handle the function call by making an HTTP request to the Google Apps Script. Depending on the response ("valid address" or "error message"), your server can then send the appropriate response back to the assistant. 4. **Assistant Uses the Function**: In the conversation flow, when an address is provided by the user, your assistant should trigger this function, sending the address to your server, which in turn calls the Google Apps Script. Here is an example of how you might define the assistant model and a custom function in your JSON configuration:
Copy code
json
{
  "model": {
    "provider": "openai",
    "model": "gpt-3.5-turbo",
    "functions": [
      {
        "name": "verifyAddress",
        "description": "Verifies the address using a Google Apps Script",
        "parameters": {
          "type": "object",
          "properties": {
            "address": {
              "type": "string",
              "description": "The address to verify."
            }
          }
        }
      }
    ]
  },
  "firstMessage": "Hello! Please provide the address you want to verify."
}
[(1)]() Ensure that your server handling the
function-call
type messages is set up to make an HTTP GET request to the Google Apps Script URL with the address parameter. Here's a basic example of how the server might handle this:
Copy code
javascript
const axios = require('axios');

async function handleVerifyAddress(address) {
  try {
    const response = await axios.get(`https://script.google.com/macros/s/app_script_ID/exec`, {
      params: {
        func: 'VerifyAddress',
        address: address
      }
    });
    return response.data; // Response from Google Script
  } catch (error) {
    console.error('Failed to verify address:', error);
    return "Error verifying address.";
  }
}
Integrate these configurations and code snippets into your system to enable your Vapi assistant to verify addresses through your Google Apps Script. Ensure your Google Apps Script is properly set to accept requests and return the expected results based on the inputs it receives.
Got it. Tagging @User for additional help.
s
You will need to use custom_function for it.
c
Can you refer me to someone who could help me? I'm not a developer.
s
Sure, you can contact to @Bruno Gomez he is pretty good.
2 Views