Extract Phone Number from Call Log for Conversatio...
# support
h
How can we extract the phone number form the call log, so that the assistant does not have to ask the customer for their full phone number? As this seems to glitch out a lot and assiatnts are struggling with collecting full phone number. We need the assistant to instead say something along the lines of "So, is the number you're calling on ending in [says last 3 digits] the best number for your appointment booking?".
v
You can extract the customer's phone number from the call log's
customer.number
property and use it in your assistant's prompt. For example, in JavaScript:
Copy code
js
const phoneNumber = call.customer.number; // e.g., "+12345678901"
const last3 = phoneNumber.slice(-3);
const prompt = `So, is the number you're calling on ending in ${last3} the best number for your appointment booking?`;
This approach lets the assistant reference the caller's number without asking for the full phone number, improving user experience. Reference: [Vapi dynamic variables documentation](https://docs.vapi.ai/assistants/dynamic-variables) Source: - [Vapi dynamic variables documentation](https://docs.vapi.ai/assistants/dynamic-variables)
k
Use the incoming call’s customer.number metadata to extract the caller’s phone number, then have the assistant say, avoiding the need to ask for the full number and reducing glitches.
h
@Kings_big💫 Hi, unfortunately the AI is not extracting the phone correctly. We've added the above into the prompts for the conversation but the last 3 digits generated in the conversations is not the call number. Are you kindly able to confirm we've implemented this correctly or what we need to adjust? We tried both "call.customer.number" and "customer.number" in the prompts. ASSISTANT ID - 4b8914d8-54c9-40f7-ae74-4f778b54647c CALLS: Call 1 ID - 43272341-b640-4ac4-a88d-89548c94a093 TS - 1:47:14 PM (+01:20.29) >>> Incorrect last 3 digits spoken, was added from automated example code above so now removed. Call 2 ID - 6a915c29-558b-47ee-8115-fe2db9bdd9b5 TS - 1:52:55 PM(+01:02.76) >>> Incorrect last 3 digits spoken, seems to be from one of our test numbers from within prompts. Call 3 ID - 3e9f4772-4dbd-45ce-a05c-87269826032f TS - 1:58:49 PM(+01:17.65)) >>> Incorrect last 3 digits spoken, seems to be from one of our test numbers from within prompts.
c
Thank you for providing that information. We will review the details and get back to you shortly with an update
h
Hi Kyle, any progress on this one please?
c
In your system prompt, please use
{{customer.number}}
as the variable for iterating the user's phone number. This is a default variable in Vapi and an example of using this can be seen below:
Copy code
When repeating the number back to the customer, say the last 4 digits of {{customer.number}} and ask if that is the correct contact number.
More variables can be found in the documentation page:
h
@Kyle thank you, we have this working. However, the AI seems to be making up a 3 digit number if someone calls from a private number (no caller ID showing). Is there a fallback or an adjusted prompt to handle this scenario?
c
You can just write a simple
if statement
in front of the prompt we sent earlier. For example:
Copy code
If {{customer.number}} is empty, ask the user which number they would like to be called back on. When repeating the number back to the customer, say the last 4 digits of {customer.number}} and ask if that is the correct contact number.