Implementing AI Assistant with Call Transfer Capab...
# support
r
I'm working on an AI assistant with capabilities through webhooks, specifically for a FreePBX/Asterisk telephony system. The assistant would be accessible via a dedicated phone number through SIP trunking. Proposed Call Transfer Flow: 1. Human caller connects with AI assistant 2. When caller requests a human specialist, the AI triggers a
call_transfer
webhook 3. The transfer tool: - Places the caller on hold - Attempts to connect with an available human specialist - Either connects the caller to the specialist OR reconnects the caller to the AI if no specialist is available 4. The AI receives the result of the transfer attempt and continues the conversation if reconnected Key Questions: - Is this implementation approach feasible with Vapi? - What happens with the AI assistant's state during the on-hold period? - Will the AI wait for the webhook result or disconnect from the call? - How does Vapi integrate with FreePBX/Asterisk systems? I'm particularly concerned about maintaining the AI's conversational context through the transfer process, especially if the caller is reconnected to the AI after a failed transfer attempt.
v
Hi there! đź‘‹ I'd be happy to help with your questions about implementing an AI assistant with call transfer capabilities in FreePBX/Asterisk using Vapi. I can address all of your key questions based on the information I've found about Vapi's capabilities and integration with FreePBX/Asterisk systems. ## Is this implementation approach feasible with Vapi? Yes, your proposed call transfer flow is feasible with Vapi! According to [Vapi's documentation](https://docs.vapi.ai/call-forwarding), Vapi supports call transfers using the
transferCall
function. Vapi offers two types of call transfers: 1. Blind transfer - The call is transferred directly to another agent 2. Warm transfer - The call is transferred after providing context about the call For your specific flow, you can use the "On-Hold Specialist Transfer" functionality. According to the [On-Hold Specialist Transfer documentation](https://docs.vapi.ai/phone-calling/on-hold-specialist-transfer), when a user is transferred to a specialist, "the user is placed on hold in a Twilio conference." If the specialist doesn't answer, "control can be returned to the AI for scheduling." ## What happens with the AI assistant's state during the on-hold period? During the on-hold period, the user is placed in a Twilio conference while the system attempts to connect to a specialist. Vapi offers features to manage conversation history during assistant transfers, including a transfer mode that allows more control over this history. To keep the call on hold, you can create a
transfer_call
tool with
async: false
and a higher timeout. Additionally, you can add messages to
tool_delay
to keep static messages while the representative is unavailable. When the server receives the transfer call destination request, you should keep that HTTP connection open while checking the representative's availability. ## Will the AI wait for the webhook result or disconnect from the call?
Vapi's behavior during call transfers depends on several factors: 1. After the transfer is complete, Vapi can provide confirmation that the call has been successfully transferred. 2. When your server receives the transfer call destination request, you should keep that HTTP connection open while checking the representative. 3. Vapi doesn't set any timeouts—as soon as it receives a status callback from Twilio, it updates the status. However, there are some potential issues to be aware of: - Vapi might end the call when the assistant disconnects - There could be immediate hangup after a "Success" webhook result due to configuration issues ## How does Vapi integrate with FreePBX/Asterisk systems? Vapi integrates with FreePBX/Asterisk primarily through SIP trunking. Here's how to set it up: 1. Set up a SIP trunk in Asterisk that points to Vapi's SIP endpoint 2. Configure your Asterisk server to connect to Vapi as a SIP trunk 3. Set up the dial plan in Asterisk to route outbound calls through the Vapi SIP trunk 4. For inbound calls, configure a SIP URI in your Vapi account and point it to your Asterisk server For call transfers, Vapi utilizes SIP REFER messages, so ensure that your FreePBX/Asterisk system is configured to handle these messages correctly. If your SIP endpoint requires authentication, double-check that the credentials provided to Vapi are correct. ## Maintaining the AI's conversational context during the call transfer process To maintain the AI's conversational context during call transfers, you can: 1. **Use SIP headers to pass context**: Pass context from your servers to Vapi and back using SIP headers when forwarding a call. ```javascript const transferDestination = { type: 'sip', sipUri: 'sip:genesys@your-domain.com', transferPlan: { mode: 'blind-transfer-add-summary-to-sip-header', summaryPlan: { // Configure how the summary should be generated } }, sipHeaders: { 'X-Caller-Intent': 'policy_inquiry',
'X-Caller-Details': JSON.stringify({ name: customer.name, policy: customer.policyNumber }) } }; ``` 2. **Utilize warm transfers**: Vapi supports warm transfers, where context about the call is provided to the receiving agent. 3. **Configure `transferMode`**: Set the
transferMode
to
rolling-history
to maintain conversation context during the transfer. 4. **Store and preload conversation context**: When transferring calls back to the AI after a failed attempt, store and preload the conversation context. 5. **Retrieve previous call history**: Before each call, retrieve the customer's previous call history and include it in API calls to the language model. Is there anything specific about any of these aspects you'd like me to elaborate on further? Sources: - [Vapi's documentation](https://docs.vapi.ai/call-forwarding) - [On-Hold Specialist Transfer documentation](https://docs.vapi.ai/phone-calling/on-hold-specialist-transfer) - [Discord thread about call transfers and voicemail detection](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1336424026486079559) - [Discord thread about call transfer failures](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341953566801264690) - [Discord thread about caching issues](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1343768614209323018) - [Discord thread about call transfers](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1328028159949537341) - [Discord thread about integration with Asterisk](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1331674878092382218) - [Discord thread about SIP integration](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1334251359519641692) - [Discord thread about passing context](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1340813822193041499)
r
Thank you. The response incorrectly assumes I'm using Twilio, but I explicitly mentioned that I have a FreePBX/Asterisk system.
I'm familiar with that example using Twilio because I've read the docs, but that doesn't work for me.
k
Hey RPV, I will be answering your key questions in the following order: 1. Implementation approach 2. During the on-hold period 3. To integrate your FreePBX or Asterisk system with VAPI Yes, the implementation approach is feasible with VAPI - no doubt in that part. For the during the on-hold period, as of now, VAPI doesn't have any native logic or feature to check if a transfer is successful or unsuccessful. You have to handle it by yourself on the telephony side. As of now, what we do is we send a REFER request followed by a BYE request where we just do the transfer from our side without checking if there is someone to pick the call or not. In case webhook result comes at max, we can wait for a dynamic destination, but we won't be waiting if someone connects to the call on the other side or not. To integrate your FreePBX or Asterisk system with VAPI, the process is similar as I already mentioned. You went through the docs, so you have to follow the SIP trunking guide and get things done. For your information, when you make inbound calls, VAPI requires authorization, and at this time, you are supposed to return a username which has to be your SIP username registered with VAPI and then a password which can be anything except being empty white spaces.
8 Views