twilio / twilio-voice.js

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

[BUG] 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." #234

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

Is this a duplicate of https://github.com/twilio/twilio-voice.js/issues/229? If so, please close.

charliesantos commented 8 months ago

Is this a duplicate of #229? If so, please close.

Closing.