Untitled

mail@pastecode.io avatar
unknown
javascript
a month ago
1.2 kB
4
Indexable
Never
static async outbondCallTwillioRetell(req, res) {
    const accountSid = 'YOUR_ACCOUNT_SID';
    const authToken = 'YOUR_AUTH_TOKEN';
    const twilioClient = twilio(accountSid, authToken);
    const toNumber = req.body.toNumber;
    const fromNumber = '+1 8446674624'
    try {

      await twilioClient.calls.create({
        machineDetection: "Enable", // mendeteksi jika pihak lain adalah IVR
        machineDetectionTimeout: 8,
        asyncAmd: "true", // memanggil webhook ketika status deteksi diketahui
        asyncAmdStatusCallback: `${process.env.NGROK_IP_ADDRESS}/twilio-voice-webhook/${agentId}`, // URL webhook untuk deteksi mesin
        url: `${process.env.NGROK_IP_ADDRESS}/twilio-voice-webhook/${agentId}`, // URL webhook untuk mendaftarkan panggilan
        to: toNumber,
        from: fromNumber,
      });
      console.log(`incoming call: ${fromNumber} ke: ${toNumber}`);
      // Kirimkan respons sukses jika fungsi dipanggil dari rute Express.js
      if (res) {
        res.status(200).json({ message: 'Success calling' });
      }
    } catch (error) {
      console.error('Fail to make call:', error);
      res.json(400).json({ message: 'Error Found', data: error.message })
    }
  }
Leave a Comment