in salesforce/aa-lwc/force-app/main/default/lwc/agentAssistContainerModule/helpers/conversationName.js [17:60]
export async function getConversationName(token, endpoint, contactPhone) {
/**
* Gets conversationName from Redis using conversationIntegrationKey.
* For voice channel, presence of this key in Redis triggers UI Module initialization.
*
* @param {string} token - The authentication token.
* @param {string} endpoint - The API endpoint.
* @param {string} contactPhone - The contact phone number.
* @returns {Promise<string | null>} The conversation name or null if not found.
*/
const getOptions = {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `${token}`
}
};
let conversationName = await fetch(
endpoint + "/conversation-name?conversationIntegrationKey=" + contactPhone,
getOptions
)
.then((res) => res.json())
.then((data) => data.conversationName)
.catch((err) => {
if (err.status === 404) {
return null;
}
console.error(err);
});
if (!conversationName) return null;
return await fetch(endpoint + "/v2/" + conversationName, getOptions)
.then((res) => res.json())
.then((conversation) => {
console.log("conversation lifecycle state:", conversation.lifecycleState);
if (conversation.lifecycleState === "COMPLETED") {
delConversationName(token, endpoint, contactPhone);
} else {
return conversation.name;
}
})
.catch((err) => console.error(err));
}