I am writing a React native web app that connects to a bot in Copilot studio.
To render the chat I am using the `ReactWebChat` component with a directLine object, this object has its token set like this:
const initializeDirectLine = async () => {
try {
const storedToken = localStorage.getItem('directLineToken');
if (storedToken) {
return createDirectLine({ token: storedToken });
} else {
const response = await fetch('https://unitedstates.directline.botframework.com/v3/directline/conversations', {
method: 'POST',
headers: {
Authorization: `Bearer SECRET`
}
});
if (response.ok) {
const data = await response.json();
localStorage.setItem('directLineToken', data.token);
return createDirectLine({ token: data.token });
} else {
console.error('Failed to start conversation:', response.statusText);
return {};
}
}
} catch (error) {
console.error('Error initializing Direct Line:', error);
return {};
}
};
I am able to establish a connection with my bot and the conversations API call is successful, however the Conversation Start topic is not triggered (it is triggered for instance in the Test pane in Copilot Studio and also in the Demo Website, same if I were to just copy the iFrame HTML).
Anything I might be doing wrong with the above code? I also tried just copying a token from the conversations API call from the Demo website and the Conversation Start is triggered but not if I generate the token directly from a fetch call.