5

I need to run the microsoft botframework v4 on-premise since company internal restrictions forbid me to register the bot on Microsoft Azure or use the connector in the cloud. My idea is to use offline-directline to emulate the connector locally. To my knowledge, the package has been built for Microsoft Botframework V3 and not v4. Has anybody managed to use it for v4?

I followed through instructions however got stuck trying to implement the web chat client. Where and how do I implement

BotChat.App({
    directLine: {
        secret: params['s'],
        token: params['t'],
        domain: params['domain'],
        webSocket: false // defaults to true
    },

in the index.html file of directline v4? The documentation of "offline-directline" is only for Botframework v3.

Is there a sample repository where I could find some info from?

Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
MoritzB
  • 61
  • 4

1 Answers1

5

Please refer to the instructions in the BotFramework-WebChat repo to see how to host Web Chat v4 in a website. You'll find something that looks like this:

<!DOCTYPE html>
<html>
  <body>
    <div id="webchat" role="main"></div>
    <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
    <script>
      window.WebChat.renderWebChat({
        directLine: window.WebChat.createDirectLine({ token: 'YOUR_DIRECT_LINE_TOKEN' }),
        userID: 'YOUR_USER_ID',
        username: 'Web Chat User',
        locale: 'en-US',
        botAvatarInitials: 'WC',
        userAvatarInitials: 'WW'
      }, document.getElementById('webchat'));
    </script>
  </body>
</html>

Rather than passing the same kind of object to window.WebChat.renderWebChat's directLine parameter as you would to BotChat.App's directLine parameter, you need to pass the object to window.WebChat.createDirectLine. The object in question is a DirectLineOptions object.

    window.WebChat.renderWebChat({
        directLine: window.WebChat.createDirectLine({
            secret: params['s'],
            token: params['t'],
            domain: params['domain'],
            webSocket: false // defaults to true
        }),

If you don't want to have to pass in any parameters to your Web Chat client, you can include them inline:

            secret: '',
            token: '',
            domain: 'http://localhost:3000/directline',
            webSocket: false // defaults to true

And if you're not particular about running Web Chat in your own HTML page, I recommend foregoing offline-directline and just using the Bot Emulator, which is great for interacting with local bots.

Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
  • Thx, that works. Now I want to disconnect completely from azure but with Luis running. Even though I deleted the BotFileSecret and all .bot settings except for luis, Im still connected to azure. When testing, I can see activity in azures request monitoring for the bot. This seems strange. – MoritzB Apr 24 '19 at 14:59
  • Are you running the bot locally or on a remote server? Did you delete your bot resource from Azure? Do your bot settings still contain an app ID and password? – Kyle Delaney Apr 25 '19 at 15:41
  • Its running locally. I deleted credentials in the files: "botname".bot, .env and index.js and still get requests activity. It runs fine locally when I stop the bot service and disable directline app service. Are the credentials and endpoints cached somewhere? Also disabling luis and running offline works. What concerns are there to run offline-directline in production? We need a local connector due to comp. policy. – MoritzB Apr 26 '19 at 16:36
  • I haven't tried this, but have you considered running LUIS in a container? https://learn.microsoft.com/en-us/azure/cognitive-services/luis/luis-container-howto – Kyle Delaney May 01 '19 at 19:54
  • @KyleDelaney looks like it is not working anymore, I tried using direct line of bot emulator and it worked without an issue but with offline-directline I am always getting "RangeError: Invalid time value", can you help if possible? – Shubham Sep 22 '19 at 06:52
  • @Shubham - I don't know what time value you're talking about. You should post a new question. – Kyle Delaney Sep 23 '19 at 16:47
  • I tried the exact above html and changed the js code to pass the correct params but I get an error as shown here - https://i.imgur.com/8sa58Fz.png. I have the bot deployed using java botbuilder framework that exposes an endpoint http://localhost:8080/api/messages hence I entered http://localhost:8080/directline as the domain url. Wonder what could be wrong? Any suggestions? – Andy Dufresne Oct 13 '20 at 11:06
  • 1
    @AndyDufresne - You say you have a bot deployed, but then you say you're trying to access it using localhost. These two things do not go together. My suggestion is to post a new question. – Kyle Delaney Oct 13 '20 at 18:31