Director bot在实施令牌而不是秘密后回显输入的消息?

问题描述 投票:0回答:2

issue我已经开发了自己的API,该API使用Directline API生成并刷新令牌。问题出在那之后,当我在上面的代码中集成令牌而不是Secret时,我的机器人正确地回答了问题,而且回显了所提供的输入。没有用代码完成这种实现,并且使用secret和emulator都可以正常工作。

(function () {

    $('head').append('<link rel="stylesheet" type="text/css" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/9.6.0/css/fabric.min.css">');
    $('head').append('<link rel="stylesheet" type="text/css" href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css">');
    $('head').append('<link rel="stylesheet" type="text/css" href="chatbot.css">');


    var chatIsVisible = false;

    $(function () {

        $(".botwrapper").toggle();



        $('<i class="ms-Icon ms-Icon--ChromeMinimize minimizeIcon" aria-hidden="true"></i>').appendTo(".wc-header");

        $("#botbutton").click(function () {
            chatIsVisible = true;
            $("#botbutton").toggle("fade", function () {
                $("#BotChatGoesHere").toggle("fade", function () {
                    $(".chatbot .wc-shellinput").focus();
                });
            });

        });

        $(".wc-header .minimizeIcon").click(function () {
            $("#BotChatGoesHere").toggle("fade", function () { $("#botbutton").toggle("fade"); chatIsVisible = false; });

        });

        setTimeout(showBot, 3000);
        setInterval(shakeBot, 10000);


        function showBot() {
            $("#botbutton").toggle("fade").effect("bounce", { times: 3 }, "slow");
        }

        function shakeBot() {

            if (!chatIsVisible) {
                $("#botbutton").effect("bounce", { times: 3 }, "slow");
            }
        }


    });

    const params = BotChat.queryParams(location.search);

    const user = {
        id: params['userid'] || 'userid',
        name: params['username'] || 'User'
    };

    const bot = {
        id: params['botid'] || 'SAM',
        name: params['botname'] || 'SAM'
    };

    const speechOptions = {
        speechRecognizer: new CognitiveServices.SpeechRecognizer({ locale: 'de-DE', subscriptionKey: '' }),
        speechSynthesizer: new CognitiveServices.SpeechSynthesizer({
            gender: CognitiveServices.SynthesisGender.Female,
            subscriptionKey: '',
            voiceName: 'Microsoft Server Speech Text to Speech Voice (de-DE, Stefan, Apollo)'
        })
    };

    window['botchatDebug'] = params['debug'] && params['debug'] === 'true';

    function ConnectWebBotChat() {
        let headers = {
        };
        if (botConnection !== null) {
            // for refresh token
            headers = {
                old_token: TokenResult.token,
                user_id: TokenResult.userId
            };
        }
        $.ajax({
            url: "http://localhost:64102/api/DLToken",
            //async: "false",
            method: "POST",
            data: "",
            dataType: 'json',
            contentType: "application/json",
            headers: headers,
            success: function (result, status, jqXHR) {
                TokenResult = result;
                botConnection = new BotChat.DirectLine({
                    domain: params['domain'],
                    secret: result.token,
                    token: result.token,
                    webSocket: params['webSocket'] && params['webSocket'] === 'true'
                });
                BotChat.App({
                    bot: bot,
                    resize: 'detect',
                    user: user,
                    speechOptions: speechOptions,
                    directLine: botConnection
                }, document.getElementById('BotChatGoesHere'));
                PingBotConnection(true);
                console.log("SAM Connection Refreshed : " + status);
            },
            error(jqXHR, textStatus, errorThrown) {
                console.log("SAM Connection Refresh : " + errorThrown);
            }
        });
    }
    function PingBotConnection(_IsFirstTime = false) {
        botConnection
            .postActivity({
                from: user,
                name: 'Connection Test',
                type: 'event',
                value: ''
            })
            .subscribe(function (id) {
                console.log('SAM Pinged OK!');
            });
        botConnection.connectionStatus$
            .subscribe(connectionStatus => {
                handleConnection(connectionStatus);
                if (!_IsFirstTime)
                    ConnectWebBotChat();
            });
    }
    function handleConnection(connectionStatus) {
        switch (connectionStatus) {
            case 0:
                console.log("SAM Uninitialized");
                break;
            case 1:
                console.log("SAM Connecting");
                break;
            case 2:
                console.log("SAM Online");
                break;
            case 3:
                console.log("SAM ExpiredToken");
                break;
            case 4:
                console.log("SAM FailedToConnect");
                break;
            case 5:
                console.log("SAM Ended");
                break;
        }
    }

    let botConnection = null;
    let TokenResult = null;
    ConnectWebBotChat();
    setInterval(() => { PingBotConnection(false); }, 1780000);

})();

Bot在使用Directline令牌时不应回显输入的消息。

非常感谢

botframework direct-line-botframework
2个回答
0
投票

[查看上面发布的代码,看来您是将令牌作为秘密传递的。我建议您只通过一个,不要同时通过。

enter image description here

另外,我建议您升级到网络聊天v4,因为它在自定义方面提供了更多支持。 sample提供了有关如何从Web Chat v3迁移到v4的详细指南。


0
投票
(function () {

    $('head').append('<link rel="stylesheet" type="text/css" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/9.6.0/css/fabric.min.css">');
    $('head').append('<link rel="stylesheet" type="text/css" href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css">');
    $('head').append('<link rel="stylesheet" type="text/css" href="chatbot.css">');




    var chatIsVisible = false;

    $(function () {

        $(".botwrapper").toggle();

        $("#BotChatGoesHere")[0].addEventListener("DOMNodeInserted", function (event) {
            twemoji.parse($("#BotChatGoesHere")[0]);
        }, false);

        $('<i class="ms-Icon ms-Icon--ChromeMinimize minimizeIcon" aria-hidden="true"></i>').appendTo(".wc-header");

        $("#botbutton").click(function () {
            chatIsVisible = true;
            $("#botbutton").toggle("fade", function () {
                $("#BotChatGoesHere").toggle("fade", function () {
                    $(".chatbot .wc-shellinput").focus();
                });
            });

        });

        $(".wc-header .minimizeIcon").click(function () {
            $("#BotChatGoesHere").toggle("fade", function () { $("#botbutton").toggle("fade"); chatIsVisible = false; });

        });

        setTimeout(showBot, 3000);
        setInterval(shakeBot, 10000);


        function showBot() {
            $("#botbutton").toggle("fade").effect("bounce", { times: 3 }, "slow");
        }

        function shakeBot() {

            if (!chatIsVisible) {
                $("#botbutton").effect("bounce", { times: 3 }, "slow");
            }
        }


    });

    const params = BotChat.queryParams(location.search);

    const user = {
        id: params['userid'] || 'userid',
        name: params['username'] || 'User'
    };

    const bot = {
        id: params['botid'] || 'SAM',
        name: params['botname'] || 'SAM'
    };

    const speechOptions = {
        speechRecognizer: new CognitiveServices.SpeechRecognizer({ locale: 'de-DE', subscriptionKey: '' }),
        speechSynthesizer: new CognitiveServices.SpeechSynthesizer({
            gender: CognitiveServices.SynthesisGender.Female,
            subscriptionKey: '',
            voiceName: 'Microsoft Server Speech Text to Speech Voice (de-DE, Stefan, Apollo)'
        })
    };

    window['botchatDebug'] = params['debug'] && params['debug'] === 'true';

(async function() {
    const res = await fetch('https://xyz/api/DLToken', { method: 'POST' });
        const { token } = await res.json();        
          window.WebChat.renderWebChat(
          {
            directLine: window.WebChat.createDirectLine({ token })
          }, document.getElementById('BotChatGoesHere'));
           // BotChat.App({
                    // bot: bot,
                    // resize: 'detect',
                    // user: user,
                    // speechOptions: speechOptions,
                    // directLine: window.WebChat.createDirectLine({ token })
                // }, document.getElementById('BotChatGoesHere'));

 })().catch(err => console.error(err));           



})();

我尝试了这个,但是仍然有随机发生的问题,并且也不再填充某些答案。

© www.soinside.com 2019 - 2024. All rights reserved.