How to get the extension from the event assistant-...
# support
v
Hi there! 👋 I don't have the exact code for parsing the extension from the phone number string, but I can definitely help with accessing the phone number (which includes the extension) and returning an assistant based on criteria. According to the information I found, here's how you can work with the extension in the
assistant-request
event: 1. Access the phone number with extension from the request body:
Copy code
python
# Get the "To" phone number from the request body
request_body = request.json  # or however you access the request body
To = request_body.get("To", "")  # This will contain "+123456789,4321"
[Source](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1343574701909344297) 2. Extract the extension - While I don't have the exact code, the format is known to be a comma-separated value. You could use string manipulation to extract it:
Copy code
python
# Example of how you might extract the extension
if "," in To:
    phone_number, extension = To.split(",", 1)
    # Now extension would contain "4321"
3. Return an assistant based on the extension by adapting this server endpoint example:
Copy code
javascript
import express from 'express';
const app = express();
app.use(express.json());

// Map extensions to assistant IDs
const EXTENSION_MAPPING = {
  '4321': 'assistant-id-for-4321',
  '5678': 'assistant-id-for-5678',
  // Add more mappings as needed
};

app.post('/assistant-request', (req, res) => {
  const To = req.body.To || '';
  let extension = '';
  
  // Extract extension if present
  if (To.includes(',')) {
    extension = To.split(',')[1];
  }
  
  // Get the appropriate assistant ID based on extension
  const assistantId = EXTENSION_MAPPING[extension] || 'default-assistant-id';
  
  res.json({ assistantId });
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});
[Source](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341224148667600976)
Is there anything specific about handling the extension that you'd like me to clarify further? Sources: - [Discord Thread about retrieving phone numbers](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1343574701909344297) - [Discord Thread about routing calls](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341224148667600976)
s
Thank you for reaching out to us. We've received your message and will get back to you as soon as possible.
Hi, checking if this is resolved/solved for you?
A gentle reminder to continue this thread.