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

Directline bot echo back inputted message after implementing token instead of secret?

issue 我开发了自己的 API,它使用直线 api 生成和刷新令牌。问题是当我在上面的代码中集成令牌而不是 Secret 时,我的机器人正确地回复了答案,但也回显了所提供的输入。没有在代码中完成这样的实现,并且使用秘密和模拟器都可以正常工作。

(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 令牌输入的消息。

非常感谢

查看上面发布的代码,您似乎正在将令牌作为秘密传递。我建议你只通过一个而不是两个。

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