0

I've pasted my code below. I've searched through some old posts and see that the Twilio dial feature can't delineate between a voicemail and an answer. Essentially - I only need one of the numbers to actually answer the call, but I can't have the call end if one of the numbers is out of service. Wondering if I should be looking at running a conference instead? Or using the REST API with machine detection? Cost is a consideration here.

`` router.post('/incoming-call', async (req, res) => { const incomingNumber = req.body.To; // The Twilio number that received the call

try {
    // Fetch forwarding number(s) from Supabase
    const { data, error } = await supabase
        .from('numbers')
        .select('forwardingnumbers')
        .eq('twilionumber', incomingNumber)
        .single();

    if (error) throw error;

   // Create a new TwiML response
    const response = new VoiceResponse();
    const dial = response.dial();

    // Assuming the array contains the numbers to be dialed simultaneously
    if (data.forwardingnumbers && data.forwardingnumbers.length) {
        data.forwardingnumbers.forEach(number => {
            dial.number(number);
        });
    } else {
        throw new Error('No for`warding numbers found');
    }

    res.type('text/xml');
    res.send(response.toString());
} catch (error) {
    console.error('Error handling incoming call:', error);
    const response = new VoiceResponse();
    response.say('An error occurred, please try again later.');
    res.type('text/xml');
    res.send(response.toString());
}

});

module.exports = router; ``

I've tested my current code and it works if both phones are on. It ends all of the forwarding if one of the two phones is off, declines the call or out of service. I'm looking at doing something with the REST API that handles voicemail and calls all numbers before connecting but thinking conference architecture might be better? Latency is a concern here. The only answer on the boards I could find was to set it up so that one of the receivers presses '1'. First person to press 1 gets the call connected. But that was from 2014....

0