Greetings!
I am building a custom web canvas for the the PVA (preview model) using the instructions here: Automatically start a chatbot conversation - Power Virtual Agents | Microsoft Learn
When I load the page, PVA doesn't seem to start the conversation by default. I have to use a trigger word to initiate any topic.
I've verified these:
Any idea what I might be doing wrong? Is there something specific I need to do to start the conversation?
Thank you! Your post saved me a ton of time trying to figure this out.
The documentation has been updated, https://learn.microsoft.com/en-us/microsoft-copilot-studio/customize-default-canvas?tabs=web.
It now contains JavaScript code that would send a greeting message to the copilot to start the conversation.
Thanks.
Figured it out. Now it works with the Bot initiating the conversation.
Replaced this:
var directline;
fetch(regionalChannelSettingsURL)
.then((response) => {
return response.json();
})
.then((data) => {
directline = data.channelUrlsById.directline;
})
.catch(err => console.error("An error occurred: " + err));
fetch(theURL)
.then(response => response.json())
.then(conversationInfo => {
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({
domain: `${directline}v3/directline`,
token: conversationInfo.token,
}),
styleOptions
},
document.getElementById('webchat')
);
})
.catch(err => console.error("An error occurred: " + err));
with this:
const store = window.WebChat.createStore(
{},
({ dispatch }) => next => action => {
if (action.type === "DIRECT_LINE/CONNECT_FULFILLED") {
dispatch({
meta: {
method: "keyboard",
},
payload: {
activity: {
channelData: {
postBack: true,
},
//Web Chat will show the 'Greeting' System Topic message which has a trigger-phrase 'hello'
name: 'startConversation',
type: "event"
},
},
type: "DIRECT_LINE/POST_ACTIVITY",
});
}
return next(action);
}
);
fetch(theURL)
.then(response => response.json())
.then(conversationInfo => {
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({
token: conversationInfo.token,
}),
store: store,
styleOptions: styleOptions
},
document.getElementById('webchat')
);
})
.catch(err => console.error("An error occurred: " + err));