I wanted to end the chatbot session manually which is developed using Copilot Studio.
The Copilot I have developed is embedded to a custom website where one website user session is logged out and on the same tab when I login with another website user I am getting the old user chatbot messages which is wrong. Please help on providing solution to end the chatbot session manually.
The sample I shared is just an excerpt. Have a look at the full sample referenced in my previous comment.
const [directLineURL, token] = await Promise.all([ fetch(new URL(`/powervirtualagents/regionalchannelsettings?api-version=${apiVersion}`, tokenEndpointURL))
We have tried as below to use the fetch new URL part as per your code snippet shared above.
useEffect(() => {
const fetchDirectLineToken = async () => {
try {
const response = await fetch(new URL(`/powervirtualagents/regionalchannelsettings?api-version=2022-03-01-preview`, endPOINTURL));
if (!response.ok) {
throw new Error('Failed to retrieve DirectLine token.');
}
const { token } = await response.json();
setDirectLineToken(token);
console.log("tokenprint",token)
} catch (error) {
console.error('Error fetching Direct Line token:', error);
}
};
fetchDirectLineToken();
}, []);
has context menu
But we are getting the tokenprint console.log value as undefined. What are we missing? How does new URL() connects to PVA to get the token from our custom website?
When you reload the iframe within the same browser tab, the conversation id stays the same, so the message history will remain as well. However, there is no risk of user A seeing messages from a conversation that user B initiated, as user A's browser will never have user B's conversation ID.
That being said, if you want more granular control of conversations, and have conversations initiated/abandoned as part of your login/logout flow, you should consider using a custom canvas.
This is where a Directline token is generated. If you generate a new token, a new conversation will be initiated as well:
const [directLineURL, token] = await Promise.all([
fetch(new URL(`/powervirtualagents/regionalchannelsettings?api-version=${apiVersion}`, tokenEndpointURL))
.then(response => {
if (!response.ok) {
throw new Error('Failed to retrieve regional channel settings.');
}
return response.json();
})
.then(({ channelUrlsById: { directline } }) => directline),
fetch(tokenEndpointURL)
.then(response => {
if (!response.ok) {
throw new Error('Failed to retrieve Direct Line token.');
}
return response.json();
})
.then(({ token }) => token)
]);
Was the above code snippet shared was helpful adilei?
Hi adilei,
Sharing you the excerpt of embedding the developed copilot in our website's frontend footer page. Let me know if this helps & please provide me a solution for this problem. Also wanted to mention our website frontend tech stack is reactjs.
Can you share an excerpt of your HTML where the copilot canvas is being called/rendered?