Skip to content

Latest commit

 

History

History
59 lines (40 loc) · 5.45 KB

File metadata and controls

59 lines (40 loc) · 5.45 KB

Running & debugging your Bot locally while using Direct Line Speech Channel

This assumes:

  • You have a Visual Studio project of a bot, that has been modified to work with Direct Line Speech channel by adding suppot for web sockets
  • You would like to run your bot as a local host service on your PC, and debug your bot source code by putting breakpoints and stepping through the code
  • You have a client application that uses Speech SDK to manage communication with your bot. This could be your own application or any one of the client sample code in this repo. In this article we will assume you are using Windows Voice Assistant Client as your client application

We will use ngrok web service to expose a public URL, which we will register as the Bot messaging URL. Traffic to that URL will be redirected by ngrok web service to your local machine.

Visual Studio uses ISS Express to host your bot as a local service. ISS Express does not allow in-coming web-socket connections from external machines. Since Direct Line Speech channel uses web-socket to connect to the Bot, we need use a proxy. Note that you will typically not need a proxy for Bots written in Node JS. Node is the runtime that will host the service locally, and it does not have that issue.

We need to run ISS Express proxy between ngrok service and the local bot service, so they can communicate using web-sockets as shown in this diagram (URLs are example only):

Steps:

  1. Do this once to get ngrok setup:

    • Download the ngrok zip file and unzip it to a folder on your desktop. It will only contain one file: ngrok.exe
    • To route HTTPS traffic with ngork, you must sign-in on the ngrok website and get an auth token that you will install locally. Sign up here
    • After you log in there will be a section titled "connect your account", with a command line like this: ngrok authtoken xxxxxxxx
    • Open a command prompt where ngrok.exe is and type the above command. You should get a message like this if everything is okay: Authtoken saved to configuration file: C:\Users\<<userid>>/.ngrok2/ngrok.yml
  2. In Visual Studio, run your project (F5) to deploy your bot locally. Note the Bot messaging address (typically http://localhost:3978/api/messages. We will assume that's the URL from here on)

  3. Set up a proxy on your PC, by opening a command prompt and typing:

    • npm install -g iisexpress-proxy (you only need to do this once)
    • iisexpress-proxy 3978 to 12901 (note that port 12901 was picked arbitrarily)
  4. Open another command prompt, and run ngrok:

    • ngrok.exe http 12901
    • Note the https ngrok web address in the console printout (e.g. "Forwarding https://6bb0eda3.ngrok.io -->". We will assume that's the URL from here on).
  5. Go to your Azure portal and find your bot's "Bot Channel Registration" or "Web App Bot" resource (whichever you use)

    • Update the messaging end-point to what you got from ngrok. Don't forget to add the /api/messages). For example: https://6bb0eda3.ngrok.io/api/messages
    • Remember to check the box "Enable Streaming Endpoint"
    • Register it with Direct Line Speech channel if you have not yet done so
  6. Install Windows Voice Assistant client tool if you don't already have it. You can either build it from source code or download a package that contain the executable (VoiceAssistantClient.exe)

  7. Open the tool and create a new connection profile by entering the speech key used to register the bot with Direct Line Speech channel and the speech key region. Save and apply the profile

  8. You are now ready to debug:

    • In your bot's Visual Studio project, put a breakpoint in your bot source code and start the debugger. You bot is now running as local host waiting for a call
    • In Windows Voice Assistant client, press the microphone button and start speaking, or enter text in the text bar. This should result in your bot getting a Bot-Framework Activity from Direct Line Speech channel and your breakpoint being hit allowing you to step through your bot code

Related links

Feedback

Please provide feedback on the instruction above by opening a new GitHub issue