Bot Framework v4 echo-proxy bot sample
This bot has been created using Bot Framework, it shows how to configure the bot to use it behind a corporative proxy.
-
Node.js version 18 or higher
# determine node version node --version
-
Clone the repository
git clone https://github.com/microsoft/botbuilder-samples.git
-
In a terminal, navigate to
samples/javascript_nodejs/86.echo-proxy-botcd samples/javascript_nodejs/86.echo-proxy-bot -
Install modules
npm install
-
Set up the proxy variables
- Add the
HTTP_PROXYandHTTPS_PROXYvalues in the .env file. For testing you can use the localhost and an available port:
HTTP_PROXY=http://127.0.0.1:8080 HTTPS_PROXY=http://127.0.0.1:8080This sample provides two options to work behind a proxy:
Option #1: Setting up the proxy variables globally for NodeJS.
- Make sure the code marked as option #1 is enabled in index.js.
It will use the
node-global-proxypackage to configure and start the global proxy with the provided env variables.
This option will route all the requests the bot makes through the proxy.
Option #2: Setting up the proxy in the Connector Client Options
- Make sure the code marked as option #2 is enabled in index.js.
- Fill in the
proxySettingsof ConnectorClientOptions with thehostandportfor your proxy. For testing you can use the localhost and an available port:
{ proxySettings: { host: '127.0.0.1', port: 8080 } }
- Additionally, you can set the
ProxyUrlproperty for the MSAL requests msal documentation.
This option will route the authentication requests that botbuilder makes through the proxy. Other requests, like calls to intranet APIs, will go out directly.
You can verify the routed requests with a tool like straightforward.
- Add the
-
Start the bot
npm start
Bot Framework Emulator is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.
- Install the latest Bot Framework Emulator from here
- Launch Bot Framework Emulator
- File -> Open Bot
- Enter a Bot URL of
http://localhost:3978/api/messages
Enter text in the emulator. The text will be echoed back by the bot.
To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.