最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Bidirectional phone call with Twilio - Stack Overflow

programmeradmin5浏览0评论

I'm trying to connect two personal numbers (two-way calling) through nodejs + express. Not even the current scenario is:

export const ligar = async(
    config: {idConta: string, token: string, idServico: string}, 
    originPhone: string,
    telefoneDestino: string) => {
    
    const client = new Twilio(config.idConta, config.token);
    const twilioPhone = "13347693216";

    try {
        const call = await client.calls.create({
            from: `+${twilioPhone}`,
            to: `+${originPhone}`,
            url: `${process.env.AVAIABLE_ORIGIN}:${process.env.PORT}/voz?destino=${telefoneDestino}`,
          });
        console.log('Start call');
        console.log(call);

        return {sid: call.sid, duracao: 0};
    } catch (error) {
        throw new TwilioError(`Ocorreu um problema ao iniciar a ligação: ${error}`);
    }
}


app.post('/voz', (req, res) => {
    var numeroDestino = req.query.destino as string;
    if(!numeroDestino) throw new TwilioError(`Número de destino ${numeroDestino} não foi recebido.`);

    const response = new VoiceResponse();
    const dial = response.dial();
    dial.number(numeroDestino);

    console.log(`Conectando com: ${numeroDestino}`);

    res.type('text/xml');
    res.send(response.toString());
});

Am I missing something?

I've already tested other scenarios, with Conference, for example. Also without success. Following the voice trace of the calls, the first one doesn't seem to end correctly. Does the number need to have something specific enabled? Does it need to be on and have a signal, for example?

In the scenario as it is here, the second party connects and the first doesn't.

发布评论

评论列表(0)

  1. 暂无评论