microsoft/BotFramework-DirectLineJS

Directline bot echo back inputted message after implementing token instead of secret?

Basavarajsk1992 opened this issue · 13 comments

If I use the token instead of secret in direct line channel. Inputted message is getting echo.
There is no such implementation done in code and with secret and emulator all works fine.
var botConnection = new BotChat.DirectLine({ token: botToken, webSocket: true });
BotChat.App({ botConnection: botConnection, user: { id: userId, name: userName }, bot: { id: 'botid' }, resize: 'detect' }, document.getElementById("divID"));
Bot behavior.
image

Bot should not echo back the inputted message on use of Directline Token.

Many thanks in Advance.

Hello, @Basavarajsk1992

I suspect the problem is related to your use of Bot Chat. Bot Chat is Web Chat v3. Do you encounter the problem when you use Web Chat v4?

@v-kydela The issue reported by Basavaraj is in V4 bot. Please let us know for any additional details.

@urdurgaprasad - I'm not talking about the bot, so whether or not the bot is "v4" is irrelevant. I presume you mean the bot was built with the Bot Builder v4 SDK, but v4 uses the same activity schema as v3 so there's no difference in the clients those bots can connect to. Web Chat v3 can connect to v4 bots and Web Chat v4 can connect to v3 bots. Please don't think of the Bot Builder version as being the same thing as the Web Chat version.

There's nothing about v4 bots that prevents them from connecting to Web Chat v3, but if you're using Bot Builder v4 then that's all the more reason to use Web Chat v4 as well.

@v-kydela Thank you for the quick response.

In my previous update, I meant we are using Bot Builder v4 SDK.

Now, I understood the point you are referring to. You are referring to the implementation mentioned in the below example right? https://github.com/microsoft/BotFramework-WebChat

Let me try and get back to you.

Thank again for quick response.

Yes, I am referring to Web Chat v4 as seen in the default branch of that repo, which I had linked to

@v-kydela We tried to change the approach to as you recommend i.e. to Web Chat v4 and we are struck with another issue, Reaching out here to see if you can help with any inputs.

We are hosting this chatbot in salesforce application (SFDC), and SFDC application does not allow to refer URL paths for the java script. i.e. we are not able to directly refer CDN URL path. We have to copy the webchat.js file content and create a static resource in SFDC application.

While SFDC locker console evaluating this file, it is throwing error message "regeneratorRuntime is not defined".
Can you please let us know if we need to load any other dependent JS files to resolve this issue?

https://developer.salesforce.com/docs/component-library/tools/locker-service-console

image

@urdurgaprasad - Should I assume what you're doing is going to that website, pasting the Web Chat code into the box, and clicking the evaluate button? And are you using the latest full bundle of Web Chat found here? https://cdn.botframework.com/botframework-webchat/latest/webchat.js

I'm afraid I don't know what that evaluate button does and I don't know what Lightning Locker is but I can see that a lot of things aren't compatible with it. Salesforce is a bit outside of our scope but I'll see what help I can lend.

@v-kydela You are right. I have taken latest webchat.js file code from CDN site and evaluating in salesforce locker site https://developer.salesforce.com/docs/component-library/tools/locker-service-console

@urdurgaprasad - I've learned that the duplicate activity you were seeing in Bot Chat is because of an "echoback" activity that's sent by Direct Line by design. You can see a diagram explaining that flow here. Web Chat v4 knows how to handle the echoback, but I guess Bot Chat does not (at least not with a token).

About the problem of Web Chat v4 not working in Lightning Locker, I've discovered this Stack Overflow issue: https://stackoverflow.com/questions/58385471/get-rid-of-regeneratorruntime-is-not-defined-without-importing-the-polyfill

regeneratorRuntime is from Babel. It is a helper function injected when Webpack + Babel is run during the bundling of Web Chat. The scripts run in Salesforce are enforced in "strict mode", and regeneratorRuntime isn't happy. Do you suppose there's some way to get Salesforce to relax on strict mode?

@v-kydela I tried to disable strict CSP in the locker service console to see the results. Even with disabling strict CSP, am seeing the same error.

But in my last discussion with salesforce team, they mentioned without successful validation from locker console, they will not be able to host the JS file in salesforce which triggers security issues.

image

@urdurgaprasad - I'm afraid we're no longer supporting Bot Chat, so I can't help you on that end. As far as getting Web Chat v4 to work, I can see that @compulim has opened another issue to investigate that. It seems like you have a few choices:

  1. Use the secret instead of a token in Bot Chat
  2. Try to find a way to fix Bot Chat on your own
  3. Wait for the Web Chat team to come up with a solution for Web Chat v4
  4. Try to build Web Chat yourself from the source code such that it works in Salesforce

I think I've done everything I can here so I will unassign myself

@v-kydela Thank you for all your support and inputs here.

@urdurgaprasad I am closing this issue as the original question regarding Web Chat v3/v4 appears resolved. For any new questions please file a new issue - thank you!