Twilio voice now uses first-class `Call` records as the source of truth for call state, instead of storing it on `conversation.additional_attributes` and `conversation.identifier`. Each call gets its own record, its own `voice_call` bubble matched by `call_sid`, and its own conference name keyed off `Call.id`. Multiple calls on the same conversation (for `lock_to_single_conversation` inboxes) now work correctly, and the conversation card stays in sync with the real latest message. Fixes https://linear.app/chatwoot/issue/PLA-121/lock-to-single-thread --------- Co-authored-by: Muhsin <12408980+muhsin-k@users.noreply.github.com>
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
/* global axios */
|
|
import ApiClient from '../../ApiClient';
|
|
import ContactsAPI from '../../contacts';
|
|
|
|
class VoiceAPI extends ApiClient {
|
|
constructor() {
|
|
super('voice', { accountScoped: true });
|
|
}
|
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
initiateCall(contactId, inboxId) {
|
|
return ContactsAPI.initiateCall(contactId, inboxId).then(r => r.data);
|
|
}
|
|
|
|
leaveConference({ inboxId, conversationId, callSid }) {
|
|
return axios
|
|
.delete(`${this.baseUrl()}/inboxes/${inboxId}/conference`, {
|
|
params: { conversation_id: conversationId, call_sid: callSid },
|
|
})
|
|
.then(r => r.data);
|
|
}
|
|
|
|
joinConference({ conversationId, inboxId, callSid }) {
|
|
return axios
|
|
.post(`${this.baseUrl()}/inboxes/${inboxId}/conference`, {
|
|
conversation_id: conversationId,
|
|
call_sid: callSid,
|
|
})
|
|
.then(r => r.data);
|
|
}
|
|
|
|
getToken(inboxId) {
|
|
if (!inboxId) return Promise.reject(new Error('Inbox ID is required'));
|
|
return axios
|
|
.get(`${this.baseUrl()}/inboxes/${inboxId}/conference/token`)
|
|
.then(r => r.data);
|
|
}
|
|
}
|
|
|
|
export default new VoiceAPI();
|