Multi-lingual Support for idle messages.
# support
s
Is there away I can specify a multi lingual support for idle messages @Shubham Bajaj
s
To implement multi-lingual support for idle messages, you can use the API's batch request capabilities to dynamically set the appropriate idle messages based on the detected or specified language of the call. #### Implementation Approach: 1. Create Language-specific Idle Message Sets First, create a mapping of idle messages for different languages:
Copy code
javascript
const IDLE_MESSAGES_MULTILINGUAL = {
  "en": [
    "Are you still there?",
    "Is there anything else you need help with?",
    "Feel free to ask me any questions."
  ],
  "es": [
    "¿Sigues ahí?",
    "¿Hay algo más en lo que pueda ayudarte?",
    "No dudes en hacerme cualquier pregunta."
  ],
  "fr": [
    "Êtes-vous toujours là?",
    "Y a-t-il autre chose dont vous avez besoin?",
    "N'hésitez pas à me poser des questions."
  ],
  // Add more languages as needed
};
2. API Batch Request Implementation Here's how you can implement a webhook or API endpoint that responds to assistant requests and sets the appropriate idle messages based on language:
Copy code
javascript
// Example implementation for a webhook handling assistant-request
app.post('/webhook/assistant-request', async (req, res) => {
  // Extract data from the incoming request
  const { call, customer, assistant } = req.body;
  
  // Determine language from call context or customer preference
  // This could come from customer data, call metadata, or other sources
  const language = customer?.preferredLanguage || call?.detectedLanguage || 'en';
  
  // Get idle messages for the determined language, fallback to English if not available
  const idleMessages = IDLE_MESSAGES_MULTILINGUAL[language] || IDLE_MESSAGES_MULTILINGUAL['en'];
  
  // Create assistant overrides or a new assistant configuration
  const response = {
    // You can either reference an existing assistant and override its messagePlan
    assistantId: assistant?.id,
    assistantOverrides: {
      messagePlan: {
        idleMessages: idleMessages,
        // Keep other messagePlan settings like timeout the same or override them
        idleTimeoutSeconds: 10,
        idleMessageMaxSpokenCount: 3
      }
    },
    
    // Alternatively, you can create a completely new assistant on the fly
    /* 
    assistant: {
      name: `Multilingual Assistant (${language})`,
      messagePlan: {
        idleMessages: idleMessages,
        idleTimeoutSeconds: 10,
        idleMessageMaxSpokenCount: 3
      },
      // Include other required assistant configuration
      model: {...},
      voice: {...},
      ...
    },
    */
  };
  
  // Send back the response
  res.json(response);
});
3. Integrating with VAPI System You can integrate this with the VAPI system in two ways: #### Option 1: Using Assistant Request Webhook Configure your phone number to use a webhook for assistant selection. When a call comes in, VAPI will send an
assistant-request
to your webhook, and you can respond with the appropriate language-specific idle messages. Example configuration:
Copy code
json
{
  "webhooks": {
    "assistantRequest": "https://your-api.com/webhook/assistant-request"
  }
}
#### Option 2: Using the API Directly Create multiple assistant variants for different languages and use the appropriate one based on the customer's language preference:
Copy code
javascript
// Using the VAPI API to create a new assistant with language-specific idle messages
const createMultilingualAssistant = async (language) => {
  const idleMessages = IDLE_MESSAGES_MULTILINGUAL[language] || IDLE_MESSAGES_MULTILINGUAL['en'];
  
  const assistantConfig = {
    name: `Support Assistant (${language.toUpperCase()})`,
    messagePlan: {
      idleMessages: idleMessages,
      idleTimeoutSeconds: 10,
      idleMessageMaxSpokenCount: 3
    },
    // Other assistant configuration
    model: {...},
    voice: {...},
    // Language-specific system prompt if needed
    firstMessage: `Hello! I'm your assistant. How can I help you today?`
  };
  
  const response = await fetch("https://api.vapi.ai/assistant", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${YOUR_API_KEY}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify(assistantConfig)
  });
  
  return response.json();
};

// Create assistants for multiple languages
const createAllLanguageAssistants = async () => {
  const languages = ["en", "es", "fr", "de", "ja"];
  const assistants = {};
  
  for (const lang of languages) {
    assistants[lang] = await createMultilingualAssistant(lang);
  }
  
  return assistants;
};
### Implementation Example: Dynamic Language Selection in Call Routing You can also implement a system that determines the language dynamically during the call and switches assistants if needed:
Copy code
javascript
app.post('/webhook/assistant-request', async (req, res) => {
  const { call } = req.body;
  
  // Initial response with default language (English)
  if (!call.detectedLanguage) {
    return res.json({
      assistantId: "your-default-assistant-id",
      // Any other configuration
    });
  }
  
  // If language is detected during the call, select the appropriate assistant
  const languageToAssistantMap = {
    "en": "english-assistant-id",
    "es": "spanish-assistant-id",
    "fr": "french-assistant-id",
    // Add more mappings
  };
  
  // Get the appropriate assistant ID or use default
  const assistantId = languageToAssistantMap[call.detectedLanguage] || 
                     languageToAssistantMap["en"];
  
  return res.json({
    assistantId: assistantId
  });
});
This implementation allows you to provide a fully multi-lingual experience for your VAPI assistants, including dynamic idle messages that match the user's language preferences.
s
Thanks let try it out
a
Marking this ticket as Solved ✅
3 Views