How to Filter Incoming Calls to Only Approved Numb...
# support
j
I know many have asked about getting an inbound phone number, and I've gathered from search the Discord that this can be done via the 'Get Call' API call. But I need further help with my use case. I have a list of members and their numbers in a Google Sheet. I want it so that when a call comes in, we filter to only allow member calls. This could be either: 1. If the incoming call is from a number that is not a member's number, then it is not even answered in the first place. 2. Or If that isn't possible, then at least after the call is answered, we perform a function call that checks that Google Sheet to check if the caller's phone number matches. If not, the call ends. If I wanted to do this, how would I get the Call ID in order to pass to the 'Get Call' request while the call is running (I think that's what's required?)?
v
Hi @JM, 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**: * [Create Phone Call]() * [Get Call]() * [List Calls]() * [Get Phone Number]() -----------------------------
### Answer To filter incoming calls to only approved numbers using Vapi, you can follow these two methods: ### 1. Preventing Non-Member Calls from Being Answered Unfortunately, Vapi does not provide a direct way to prevent calls from being answered based on the incoming number before answering the call. You will need to answer the call first and then implement the filtering logic. ### 2. Checking Caller Number and Ending the Call if Not a Member 1. **Answer the Call and Get the Call ID**: When an incoming call is received, you'll automatically get the
id
of the call in the response. Use this ID to fetch call details if necessary. 2. **Retrieve Call Details to Get Caller Number**: You can use the
Get Call
API to retrieve details of the call, including the caller's phone number. Here is an example of how to get the call details:
Copy code
python
   import requests

   call_id = "<call_id>"
   url = f"https://api.vapi.ai/call/{call_id}"
   headers = {
       "Authorization": "Bearer <token>"
   }

   response = requests.get(url, headers=headers)
   call_details = response.json()
   caller_number = call_details['customer']['number']
3. **Check Caller Number Against Google Sheets**: Use Google Sheets API to check if the caller's number exists in your members' list. 4. **End the Call if Caller is Not a Member**: If the number is not found, you can end the call programmatically. Example of ending the call (assuming a function to end the call):
Copy code
python
   import requests

   end_call_url = f"https://api.vapi.ai/call/{call_id}/end"
   headers = {
       "Authorization": "Bearer <token>",
       "Content-Type": "application/json"
   }

   response = requests.post(end_call_url, headers=headers)
   if response.status_code == 200:
       print("Call ended successfully")
In summary, you'll need to answer the call, retrieve the caller's number using the
Get Call
API [(1)]() , check it against your list in Google Sheets, and then end the call if the number is not approved. : [Get Call]()
j
How do I do this part? "Checking Caller Number and Ending the Call if Not a Member Answer the Call and Get the Call ID: When an incoming call is received, you'll automatically get the id of the call in the response. Use this ID to fetch call details if necessary."
v
Got it. Tagging @User for additional help.
s
Basically, you need to setup server url on the account level then it will request for assistant configuration to your server url and then you need to write logic to filter out it. If user is valid then provide the assistant configuration otherwise provide the error message
w
@JM did you get this figuired out. I can see the use case for this as well and would love to learn what you've done here
a
This should be fairly simple to set up
j
@weissm I haven’t yet, but will have a tinker to see if I can get it right. I think I understand in my head what @Sahil’s described, but it would help to actually see the process - eg I know where my account server url is, but when ‘it will request for assistant configuration’ to my server, I’m not sure what that entails or requires. I’m using Zapier/Make for this and will have a play, but if @Sahil or @Alexi have any further tips or community resources on this, would be very much appreciated. .
a
I was once where you were in terms of technical ability with APIs. It can be hugely worth it to learn some general purpose language like python to be able to control any API. It might be possible with low code tools only but you are going to need to find a way to make a call to the vapi API after an inbound call is initiated. That call to the vapi API has to cancel or end the call upon the evaluation that the caller is not on your list of members.
If you are figuring stuff out with zapier you would be surprised how easy it is to use python requests to interact with the same APIs.
Config your assistant to have a zapier web hook in the serverUrl part of the vapi assistant.
Your endpoint will be receiving events from that agent so when an inbound call is created your endpoint is notified.
In that payload is the id of the call which you will need to use to send an API request to the vapi server to end the call.
j
Appreciate the encouragement and tips! I think it’s valuable advice. I’m keen to learn actual coding along the way - I’m sure it will only be to my benefit. In the immediate term though, looking to see if I can pull it off with current skillset. Not at my computer now but will have a play with it and report back to this thread if I get stuck. Thanks again.
a
The first part can definitely be achieved. Receiving events and checking if the caller should be in the call . You just need to figure out how to make a call to vapi API from zapier
This is what I am referring to @JM
j
Many thanks for setting in the right direction. Will have a go.
7 Views