Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Greeting Message Web Chat v4 - Sending events from bot #1397

Closed
DanielTizon opened this issue Nov 26, 2018 · 10 comments · Fixed by #1405
Closed

Greeting Message Web Chat v4 - Sending events from bot #1397

DanielTizon opened this issue Nov 26, 2018 · 10 comments · Fixed by #1405
Assignees
Milestone

Comments

@DanielTizon
Copy link

DanielTizon commented Nov 26, 2018

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:

https://blog.botframework.com/2018/07/12/how-to-properly-send-a-greeting-message-and-common-issues-from-customers/

        botConnection
            .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!

@compulim
Copy link
Contributor

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.

@xinfli
Copy link

xinfli commented Nov 27, 2018

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.

@compulim compulim changed the title Greeting Message Webchat v4 - Sending events from bot Greeting Message Web Chat v4 - Sending events from bot Nov 28, 2018
@compulim
Copy link
Contributor

compulim commented Nov 28, 2018

@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.

@xinfli
Copy link

xinfli commented Nov 28, 2018

@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');
		}
	});
	// ...

@compulim
Copy link
Contributor

Fix is coming in, #1405. More details over there.

(@xinfli, your code is very useful)

@xinfli
Copy link

xinfli commented Nov 28, 2018

Great! waiting for the new release :-)

@compulim
Copy link
Contributor

It's coming, in Travis CI now.

@Bradrajkumar
Copy link

how to send the post activity for any event type from webchatV4? please provide me the exact syntax and dummy code.

@selvaduraiece
Copy link

I am also looking for. Can u help me with the syntax

@corinagum
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants