BotBuilder-Samples/samples/javascript_nodejs/86.echo-proxy-bot
Amrit10737726 1330610d8a
modified ftpState from AllAllowed to Disabled (#3981)
2024-06-06 08:56:50 -05:00
..
deploymentScripts
deploymentTemplates
.env
.eslintrc.js
README.md
bot.js
index.js
package.json

README.md

echo-proxy-bot

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.

Prerequisites

  • Node.js version 16.16.0 or higher

    # determine node version
    node --version
    

To try this sample

  • Clone the repository

    git clone https://github.com/microsoft/botbuilder-samples.git
    
  • In a terminal, navigate to samples/javascript_nodejs/86.echo-proxy-bot

    cd samples/javascript_nodejs/86.echo-proxy-bot
    
  • Install modules

    npm install
    
  • Set up the proxy variables

    • Add the HTTP_PROXY and HTTPS_PROXY values 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:8080
    

    This 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-proxy package 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 proxySettings of ConnectorClientOptions with the host and port for 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 ProxyUrl property 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.

  • Start the bot

    npm start
    

Testing the bot using Bot Framework Emulator

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

Connect to the bot using Bot Framework Emulator

  • Launch Bot Framework Emulator
  • File -> Open Bot
  • Enter a Bot URL of http://localhost:3978/api/messages

Interacting with the bot

Enter text in the emulator. The text will be echoed back by the bot.

Deploy the bot to Azure

To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.

Further reading