Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
578 views
in Technique[技术] by (71.8m points)

html - How can I use offline-directline for Microsofts Botframework v4?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...