Hi,
I am migrating from Webchat v3 to Webchat v4, and I am having problems when I post an event activity for welcome trigger. I was using the workable solution given in official botframework blog:
.postActivity({
from: user,
name: 'requestWelcomeDialog',
type: 'event',
value: ''
})
.subscribe(function (id) {
console.log('"trigger requestWelcomeDialog" sent');
});
But when I try to do it in Webchat v4 React version, using the next code:
let directLine = window.WebChat.createDirectLine({ secret: '' });
directLine.postActivity({
from: user,
name: 'requestWelcomeDialog',
type: 'event',
value: ''
})
.subscribe(function (id) {
console.log('"trigger requestWelcomeDialog" sent');
});
the event arrives to the bot correctly, but I get a "conversation ended" error in the web browser console, and the messages don't arrive to the client.
Anybody can gimme an example about how to do it correctly in v4?
Thanks in advance!
The code looks good to me. Web Chat v4 is still using the very same version of DirectLineJS.
Will investigate the code. But since I am locked down on something else more urgent (#1336), my response may be slow.
p.s. we are drafting PR #1286 to make the "send welcome event" story more standard. You can peek into it for details.
We got same error on sending greeting message, with botchatDebug enabled and override DirectLine.end(), we found that seems the DirectLine conversation ended on creating WebSocket connection.
We reverted to v3 since we did not find solution for this problem.
@xinfli if there are any JavaScript errors inside the business logic of Web Chat, we will close the Direct Line connection. This is a new behavior.
I believe the code that call directLine.postActivity() is causing JavaScript errors in Web Chat. We need to dig into that error.
@compulim Thanks, I guess it's caused we transfer customized value in activity and caused this problem, but: 1. same code works fine with v3; 2. in v4 it failed random, sometime it works.
And, how can we catch the error caused the DirectLine connection closed?
Below is our code:
// ...
var dl = window.WebChat.createDirectLine({ secret: token });
var botContainer = document.getElementById('grantBot');
const styleOptions = {
// Color options
};
window.WebChat.renderWebChat({ directLine: dl, styleOptions }, botContainer);
var activity = {
from: {
id: userId,
name: userName
},
name: 'startConversation',
type: 'event',
value: '',
channelData: {
"personId": userId,
"environment": window.location.host
}
};
dl.postActivity(activity).subscribe(function(id) {
if (console) {
console.log('"trigger requestWelcomeDialog" sent');
}
});
// ...
Fix is coming in, #1405. More details over there.
(@xinfli, your code is very useful)
Great! waiting for the new release :-)
It's coming, in Travis CI now.
how to send the post activity for any event type from webchatV4? please provide me the exact syntax and dummy code.
I am also looking for. Can u help me with the syntax
Most helpful comment
@compulim Thanks, I guess it's caused we transfer customized value in activity and caused this problem, but: 1. same code works fine with v3; 2. in v4 it failed random, sometime it works.
And, how can we catch the error caused the DirectLine connection closed?
Below is our code: