Help with hosting BotPress in IIS

Hello,

I am looking at setting up BotPress but running it through IIS.

I have had some success with loading through the site but when i try and testing a bot nothing is shown in the emulation windows.

When try and see what traffic is been sent i can see it is getting a connection failure through the WebSocket connection:

When i have googled the issue you can fix it by turning WebSocket off in the BotPress config but I get a 404 instead.

Out of curiosity I tried hitting localhost:3000 with the same URL parameters and it did give me JSON response back so I am assuming it seems to be an issue with the URL rewrite I have configured so that it can be accessed outside of my local server.

The only rule I have is:

                rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="false"
                    match url="(.*)" /
                    action type="Rewrite" url="http://localhost:3000/botpress/{R:1}" appendQueryString="false" logRewrittenUrl="true" /
                /rule

Am I missing something.

I would apricate any help on this.

Thanks,
Tom

Hello @STTom ,

Thanks for taking the time to ask a question on the forum. Unfortunately, I cannot answer your question right away. I don’t have any experience with IIS and I don’t have a windows-server to test :frowning_face: .

Thanks

Hi @STTom , please check this documentation for Nginx, there are some configs for port redirection, proxy and sockets. I am not an expert on this area but you may try to understand and perform equivalent configs on IIS.

Hi @saurabh ,

Thanks, I cannot see a link for this documentation could you try and post it again?

oh yes, I missed to put the link, here it is: Amazon Web Services · | Developer’s Guide (botpress.com)

Thanks @saurabh ive had a look at this, while it couldnt implement this in IIS it did give me a couple of ideas and it looks like I have got it working, I will write it up incase anyone else needs to know

Just incase anyone else needs this I think I have got it working on IIS. I cannot take all the credit for the solution as I have implemented a chunk of what is suggested here: https://github.com/botpress/botpress/issues/2265

When I was testing this out I configured the site to run under the “Default Web Site” within IIS, I would assume that this would work with URL rewrite rules that are described in the above article but this seems to be where the issues occurred. You will need to set BotPress to work under its own binding within IIS.

At the bottom of this git post I have requested that the OP provides the XML that you need to put into your web.config as some of the key words he has mentioned are cropped. I have made a best guess on what these are from a lot of Googling and I think they are HTTP_CONNECTION, UPGRADE, HTTP_SEC_WEBSOCKET_EXTENSIONS.

These variables will need to be added for IIS to work, to do this, go into the rewrite module and on the right hand side you should see an item called “View Server Variables” go into there and click the “Add…” in the new window. Add each variable as stated above and you should be ok.

Also for anyone who needs it here is what I have set in web.config (this will need to go into the root folder of BotPress where bp.exe is)

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules useOriginalURLEncoding="false">
                <clear />
                <rule name="Reverse Proxy Websocket Rule" enabled="true" stopProcessing="true">
                    <match url="(socket.io.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{CACHE_URL}" pattern="^(.+)://" />
                    </conditions>
                    <serverVariables>
                        <set name="HTTP_CONNECTION" value="Upgrade" />
                        <set name="UPGRADE" value="websocket" />
                        <set name="HTTP_SEC_WEBSOCKET_EXTENSIONS" value="" />
                    </serverVariables>
                    <action type="Rewrite" url="http://localhost:3000/{R:1}" appendQueryString="true" logRewrittenUrl="true" />
                </rule>
                <rule name="Reverse Proxy Inbound Rule" enabled="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://localhost:3000/{R:1}" appendQueryString="false" logRewrittenUrl="true" />
                </rule>
                <rule name="Correct skills URL" enabled="true" stopProcessing="true">
                    <match url=":3000(.*)flow/skills/(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://localhost:3000{R:1}/flow/skils%2F{R:2}" appendQueryString="false" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Also while it is mentioned in the Git post you need to set the “externalUrl” which BotPress will be exposed to, this is done in the botpress.config.json file which can be found in data\global, some people also mentioned that you need to get rid of “websocket” within the “socketTransports” config item, I did try removing this but I kept getting timeouts when I was running the bot, when both items are in the timeouts seemed to be resolved.

If anyone has any questions about this I will help out where I can. If I have any other updates I will post them in here.