twilio / twilio-voice.js

Twilio's JavaScript Voice SDK
Other
50 stars 53 forks source link

In my application using Twilio Voice JavaScript SDK 2.6.0, when the receiver ends a call, the dialer does not receive the disconnect event. Although the dialer hears the 'call ended' voice notification, the UI does not update to reflect the call's end." #229

Closed afnanjanjua closed 8 months ago

afnanjanjua commented 9 months ago
          In my application using Twilio Voice JavaScript SDK 2.6.0, when the receiver ends a call, the dialer does not receive the disconnect event. Although the dialer hears the 'call ended' voice notification, the UI does not update to reflect the call's end." 

this is twillio web hooks async incomingCall(siteOrigin: string, data: any, direction: string) { data.Direction = direction; await this.saveCallLog(data, 'incoming', siteOrigin);

const clientDetails = await this.clientService.getClientIdsByPhonenumber(
  siteOrigin,
  data.To,
);
const userIds = clientDetails.map((client) => client.userId) || [];
const twiml = new twilio.twiml.VoiceResponse();
//https://${origin}:3000
const dial = twiml.dial({
  record: 'record-from-ringing',
  action: `https://url/atmos-api/v1/voicemail-twiml-voice/${data.To}`,
  method: 'POST',
});

userIds.forEach((userId: string) => {
  const client = dial.client({
    statusCallbackEvent: ['initiated', 'ringing', 'answered', 'completed'],
  });
  const entryData = {};

  client.identity(`user${userId}`);
  client.parameter({
    name: 'entry_data',
    value: JSON.stringify(entryData),
  });
});

data.user_id = userIds.join(',');
// Update call log
this.updateCallLog(siteOrigin, data);
return twiml.toString();

} dial action end point function call async generateVoicemailTwiML(phoneNumber: string, req: any) { console.log("Request body:", req.body); const voiceResponse = new twilio.twiml.VoiceResponse(); const phoneSetting = await this.twilioPhoneNumberModel .findOne({ phoneNumber: phoneNumber }) .exec();

if (!phoneSetting) {
  console.log("Phone settings not found for number:", phoneNumber);
  return;
}

console.log("Dial Call Status:", req.body.DialCallStatus);
if (req.body.DialCallStatus === 'completed') {
  console.log("Call is completed, hanging up.");
  voiceResponse.hangup();
} else {
  if (phoneSetting.voicemailEnabled) {
    if (phoneSetting.voicemailType === 'recording') {
      console.log("Playing voicemail recording.");
      voiceResponse.play(phoneSetting.voicemailGreetingMessage.voiceFilePath);
    } else {
      console.log("Saying voicemail message.");
      voiceResponse.say(phoneSetting.voicemailGreetingMessage.text);

    }
    voiceResponse.record({
      maxLength: 5,
      finishOnKey: '#',
      action: 'https://534a-206-84-151-61.ngrok-free.app/atmos-api/v1/hang-up', // Add this line
      method: 'POST'
    });

  }
  voiceResponse.hangup();
}
const twimlString = voiceResponse.toString();
console.log("Generated TwiML:", twimlString);
return twimlString;

} Angular frontened // Method to handle incoming call events handleIncomingCall(call: any): void { this._call = call;

this._callStatus = 'incoming';
this.currentCallNext(call.parameters['To'], call.parameters['From'], call);

call.on('accept', (call: Call) => {
  console.log('Call accepted');
  this._call = call;

  // Update and emit call status
  this._callStatus = 'active';
  this.currentCallNext(call.parameters['To'], call.parameters['From'], call);
});

call.on('reject', () => {
  console.log('Call rejected');
  this._callStatus = 'rejected';
  this.currentCallNext('', '', null);
});

call.on('disconnect', () => {
  console.log('Call ended');

  // Check if the call was never answered (missed call)
  if (this._callStatus === 'incoming') {
    console.log('Missed call');
    // Handle the missed call scenario
  }

  // Update and emit call status
  this._callStatus = 'ended';
  this._call = null;
  this.currentCallNext('', '', this._call);
});

} diconect event not working

Originally posted by @afnanjanjua in https://github.com/twilio/twilio-voice.js/issues/109#issuecomment-1854367365

charliesantos commented 8 months ago

@afnanjanjua it's a bit hard to understand your code snippet. To start, can you please provide a call sid that has this issue? Then we'll follow up if we have any questions. Also, please try to submit a support ticket if you can. This kind of ticket is better handled by our support team.

charliesantos commented 8 months ago

Closing due to inactivity. We can reopen or create a new ticket once the requested information has been provided.