2

I have Azure Bot deployed with Virtual Assistant Template, which was working fine (And still working in Portal's Test In Web Chat feature) until I enabled Direct Line App Service Extension.

Primary objective to enable DL App Service extension is to isolate bot access and secure app service.

I have followed MS documentation https://learn.microsoft.com/en-us/azure/bot-service/bot-service-channel-directline-extension-net-bot?view=azure-bot-service-4.0 and ensured every step is configured correctly.

Primary step to make sure DL app service is working correctly is to check if https://xxx.azurewebsites.net/api/messages or https://xxx.azurewebsites.net/.bot/ url return correct json result f.x: {"v":"123","k":true,"ib":true,"ob":true,"initialized":true} But instead i am getting Error Response 400 Bad Request and error message appeared in browser is : "Upgrade to WebSocket is required."

I couldn't even reach to a step where troubleshooting guide mentioned here : https://learn.microsoft.com/en-us/azure/bot-service/bot-service-channel-directline-extension-net-bot?view=azure-bot-service-4.0#troubleshooting could help to resolve.

As i said earlier Bot is still working and the url : https://xxx.azurewebsites.net loads site correctly , can be seen in below enter image description here

Any help is appreciated

  • I attempted it myself and was able to reach the step in the troubleshooting guide. Did you make sure that you didn't miss the step that says `Still within the Configuration section, select the General settings section and turn on Web sockets.`? – AP01 Jan 14 '22 at 01:03
  • Hello @AP01, Yes, i have enabled WebSocket option from General settings section, i have a feeling that timeout is happening somewhere when calling app service as on client page i am getting web socket connection failed error (but even Always On option is also set to ON), for detailed explanation i have reported issue on github to botframework-solution team : https://github.com/microsoft/botframework-solutions/issues/3849 – Pravin Ambekar. Jan 14 '22 at 11:01
  • There is a further step on that troubleshooting page about ANCM Mixed Hosting. I could not get a response till I enabled that as well. Does that make a difference for you? – AP01 Jan 17 '22 at 16:11
  • Hello again @AP01, If ANCM Mixed Hosting meaning to configure OutOfProcess, Yes i have configured this in csproj file. OutOfProcess Is there any way to drill down and check what causing the issue ? – Pravin Ambekar. Jan 18 '22 at 06:22
  • You could open the bot in an IDE and step through the debugger to see if any errors pop up. For a C# bot I'd suggest Visual Studio, or maybe VSCode. – AP01 Jan 18 '22 at 23:27
  • Hi @AP01, As bot was working in emulator, i never thought of debugging in IDE and html page, but when today i started debugging , i realized that although token is getting generated correctly (when calling api call) but the renderwebchat method which initiate directline conversation (directLine: await window.WebChat.createDirectLineAppServiceExtension({ domain: 'http://localhost:3978/.bot/v3/directline', token) throws error as i said in initial post giving error (WebSocket connection to 'ws://localhost:3978/.bot/v3/directline/conversations/connect?xxx failed) – Pravin Ambekar. Jan 19 '22 at 06:38
  • @AP01 And when i tried calling https://directline.botframework.com/v3/directline/conversations from postman providing Authentication Bearer : my generated token, it is giving me error as : 403 Forbidden, I am not sure what exactly the above call expect but ideally it should return result of json payload with conversation id (if i am not mistaken here), This is the exact implementation i have : https://github.com/microsoft/BotFramework-WebChat/tree/main/samples/01.getting-started/i.protocol-direct-line-app-service-extension Do you see any problem here ? – Pravin Ambekar. Jan 19 '22 at 06:42
  • If you enable the Direct Line channel and use the supplied token, you should be able to communicate with the bot through Postman. – AP01 Jan 19 '22 at 16:28
  • Hello again @AP01, Yes, i have postman where https://directline.botframework.com/v3/directline/conversations returning correct response, but again the issue with web socket is still there, i think borframework-webchat js has some different way or issue with createDirectLineAppServiceExtension function implementation. – Pravin Ambekar. Jan 20 '22 at 11:57

1 Answers1

1

These are the changes I have done and it worked:

Refer Repo With sample code: https://github.com/SSanjeevi/VirtualAssistantDirectlineExtn

Wrote detailed here.

Project file:

 <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
<NoWarn>NU1701</NoWarn>
<Version>1.0.3</Version>

BotController.cs

 private readonly IBotFrameworkHttpAdapter adapter;

 public BotController(IBotFrameworkHttpAdapter httpAdapter, IBot bot)

Startup.cs

Configure Services method:

 // Register the Bot Framework Adapter with error handling enabled.
            // Note: some classes use the base BotAdapter so we add an extra registration that pulls the same instance.
            services.AddSingleton<IBotFrameworkHttpAdapter, DefaultAdapter>();
            services.AddSingleton<BotAdapter>(sp => sp.GetService<BotFrameworkHttpAdapter>());
            // Configure channel provider

Configure method:

using Microsoft.Bot.Builder.Integration.AspNet.Core; app.UseHsts();

            app.UseCors(x => x.AllowAnyOrigin()
                .AllowAnyHeader()
                .AllowAnyMethod());
            // Allow the bot to use named pipes.
            app.UseNamedPipes(System.Environment.GetEnvironmentVariable("APPSETTING_WEBSITE_SITE_NAME") + ".directline");

Webchat:

   let directLineConnection = await window.WebChat.createDirectLineAppServiceExtension({
                domain: domainUrl,
                token
            });

The attached repo code also contains serilog implementation to have logging in log stream in app service where you can see the error logs if you face any issues.

Follow this article and implement serilog in bot api and deploy . https://www.lkgforit.com/2022/10/troubleshooting-by-writing-logs-at_15.html

Sanjeevi Subramani
  • 501
  • 1
  • 5
  • 16
  • Hello @Sanjeevi, Thank you for your comment, these are the exact steps i followed, even i will say your PR helped me to understand overall process, unfortunately the issue is still there (even after having all these changes, in fact i commented in your github issue), could you once please check my thread here : https://github.com/MicrosoftDocs/bot-docs/issues/2170#issuecomment-1019087224 , the issue is to generate token when i use my own app service url to generate token : https://xxx.azurewebsites.net/.bot/v3/directline/tokens/generate, please see given thread you will understand my concern. – Pravin Ambekar. Jan 22 '22 at 16:19
  • When i use https://directline.botframework.com/v3/directline/tokens/generate as issuer i get token but if i use this i get web socket failed error as (and what i understood) is that this is public endpoint and the token generated from this domain does not work with DL ASE enabled my app service – Pravin Ambekar. Jan 22 '22 at 16:22
  • Try without mentioning your domain in directline connection in webchat and try. I don't remember exactly but I did some sought of this after I faced issue like you and it worked, some small step. Did you added the directline extension keyin app configuration? – Sanjeevi Subramani Jan 22 '22 at 17:54
  • Follow this article and implement serilog in bot api and deploy . https://lkgforit.com/troubleshooting-by-writing-logs-at-the-application-start-for-net-core-app-using-serilog-14a1914701af. After that check the log stream in app service when hitting from browser for .bot url and from front end webchat. You will get some errors in console. – Sanjeevi Subramani Jan 22 '22 at 18:29
  • Thank you for the link provided, i will give it a try, reg removing domain i can try but as you can see the window.WebChat.renderWebChat is called once we get token from api call, and in my case the token is not receiving, i am getting null token as the app service url : https://xxx.azurewebsites.net/.bot/v3/directline/tokens/generate returning null token and i think the log trace could help here or at least I should start investigating in this direction, thanks. – Pravin Ambekar. Jan 23 '22 at 05:49
  • 1
    @PravinAmbekar. - refer sample code in this repo : https://github.com/SSanjeevi/VirtualAssistantDirectlineExtn it worked for me with brand new app service and bot. – Sanjeevi Subramani Jan 23 '22 at 15:12
  • Don't check in rest API or postman, because it will initiate a websocket connection post generating token and chat will continue in socket connection. – Sanjeevi Subramani Jan 23 '22 at 17:55
  • Thank you, I will check this and let you know the result – Pravin Ambekar. Jan 24 '22 at 03:11
  • Please mark as answer if it solves your main problem of making direct line extension to work - as per your update in github issue - token based client webchat - you can check it further -i haven't done that with ASE yet. – Sanjeevi Subramani Jan 27 '22 at 07:57