简体   繁体   English

Bot framework Webchat Postback 按钮在我单击它们后会在聊天中显示文本

[英]Bot framework Webchat Postback buttons show the text on the chat after I click them

Webchat version: 4.15.1 using CDN,网聊版本:4.15.1 使用CDN,

Description: I am using HeroCards with postback buttons but they show the text in the value after I click them, It also happens with SuggestedActions.描述:我正在使用带有回发按钮的 HeroCards,但在我单击它们后它们会在值中显示文本,这也发生在 SuggestedActions 中。 Since in some cases I am using special codes I need to hide them from the user由于在某些情况下我使用特殊代码,我需要对用户隐藏它们

Code of the cards:卡片代码:

 private async Task<DialogTurnResult> ProcesarEnvioMenu(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var tarjetaNecesitoPrueba = new HeroCard()
            {
                Buttons = new List<CardAction>()
                    {
                        new CardAction()
                        {
                           Title = "Pruebas",
                           Type = ActionTypes.PostBack,
                           Value = "Pruebas"
                        }
                    },
                Images = new List<CardImage>()
                    {
                        new CardImage()
                        {
                            Url="https://chatbotfcsblobstorage2.blob.core.windows.net/imagenes/63de5d7e-bf00-498f-bb1a-84c16feef299.png"
                        }
                    },
                Title = "Necesito una prueba diagnóstica ",
                Subtitle = "para saber si tengo COVID"
            }.ToAttachment();


            var mensaje = stepContext.Context.Activity.CreateReply($"Por favor elige la opción que deseas o si lo prefieres hazme una pregunta directamente.");
            mensaje.Attachments = new List<Attachment>();
            mensaje.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            mensaje.Attachments.Add(tarjetaNecesitoPrueba);
      
            await stepContext.Context.SendActivityAsync(mensaje, cancellationToken: cancellationToken);

            return await stepContext.EndDialogAsync();
        }

Code of the webchat:网络聊天代码:

<!DOCTYPE html> <html> <head>
    <script src="https://cdn.botframework.com/botframework-webchat/4.15.1/webchat.js"></script>
   
    <style>
        html,
        body {
            height: 100%;
        }

        body {
            margin: 0;
        }

        #webchat {
            height: 100%;
            width: 100%;
        }
    </style> </head> <body>
   
    <div id="webchat" role="main"></div>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script>

    
     const styleSet = window.WebChat.createStyleSet({
         rootHeight: '100%',
         rootWidth: '100%',

        
         bubbleFromUserBackground: '#EA431C',
         bubbleFromUserBorderRadius: 15,
         bubbleFromUserBorderColor: '#EA431C',
         bubbleFromUserTextColor: 'White',

         bubbleBackground: '#24B5B1',
         bubbleBorderRadius: 15,
         bubbleBorderColor: '#24B5B1',
         bubbleTextColor: 'White',

         sendBoxButtonColor: '#0063B1',
         sendBoxBorderBottom: 'solid 1px #006FBA',
         sendBoxBorderLeft: 'solid 1px #006FBA',
         sendBoxBorderRight: 'solid 1px #006FBA',
         sendBoxBorderTop: 'solid 1px #006FBA',

         suggestedActionBackgroundColor: '#EA431C',
         suggestedActionBorderColor: '#EA431C',
         suggestedActionBorderColor: 'White',
         suggestedActionTextColor: 'White',
         suggestedActionBorderStyle: 'none',
         suggestedActionBorderRadius: 5,
      

      });



        styleSet.textContent = {
            ...styleSet.textContent,
            fontFamily: "'Gotham', 'Calibri', 'Helvetica Neue', 'Arial', 'sans-serif'",
            fontColor: 'White'
        };

        const avatarOptions = {
            botAvatarBackgroundColor: '#FE9913',
            botAvatarImage: 'https://wikiaprendofcscontainer.blob.core.windows.net/imagenes/wikiaprendo/logowikiaprendofcs.png',
            botAvatarInitials: 'BF',
         
            hideUploadButton: true,
            
        };
        (async function () {
        const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
               if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
                     dispatch({
                        type: 'WEB_CHAT/SEND_EVENT',
                        payload: {
                            name: 'webchat/join'
                       }
                 });
           }

        return next(action);   });

            const token = '@ViewBag.Token';
            var d1 = window.WebChat.createDirectLine({ token })

            window.WebChat.renderWebChat({
                directLine: Object.assign({}, d1, {
                    postActivity: activity => {
                        var newActivity = Object.assign({}, activity, { channelData: { "MonitorId": "@ViewBag.IdMonitor" } });
                        return d1.postActivity(newActivity);
                    }
                }),
                styleSet,
                styleOptions:avatarOptions,
                store,
                sendTypingIndicator:true

            }, document.getElementById('webchat'));

            document.querySelector('#webchat > *').focus();
        })().catch(err => console.error(err));

    </script> </body> </html>

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

The error was in the webchat configuration on the html file.错误出现在 html 文件的网络聊天配置中。 This is the right way of having a welcome message AND passing arguments to a chatbot in the channel data这是在频道数据中发送欢迎消息并将参数传递给聊天机器人的正确方法

 (async function () {
         const token = '@ViewBag.Token';
            var d1 = window.WebChat.createDirectLine({ token });
            const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
                if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
                    dispatch({
                        type: 'WEB_CHAT/SEND_EVENT',
                        payload: {
                            name: 'webchat/join',
                            value: { language: window.navigator.language }
                        }
                    });
                }

                if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
                    action = window.simpleUpdateIn(
                        action,
                        ['payload', 'activity', 'channelData', 'MonitorId'],
                        () => '@ViewBag.IdMonitor'
                    );
                }

                return next(action);
            });

            window.WebChat.renderWebChat(
                {
                    directLine: window.WebChat.createDirectLine({ token }),
                    store,
                    styleSet,
                    styleOptions: avatarOptions
                },
                document.getElementById('webchat')
            );

            document.querySelector('#webchat > *').focus();
        })().catch(err => console.error(err));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft Bot Framework WebChat (DirectLine) 导致 AJAX 页面回发 - Microsoft Bot Framework WebChat (DirectLine) causing Postback on AJAX Page Microsoft Bot Framework WebChat:禁用AdaptiveCards提交上一条消息的按钮 - Microsoft Bot Framework WebChat: Disable AdaptiveCards submit buttons of previous message 如何使用 C# 在机器人框架 SDKV4 中开发的网络聊天中显示每条消息的聊天日期和时间? - How to display chat date and time for every message in webchat developed in bot framework SDKV4 using C#? Bot Framework-imBack或postBack消息没有按钮? 可能吗? - Bot Framework - imBack or postBack message without buttons? Is it possible? 如何从聊天机器人的网络聊天中删除聊天标题 - How to remove the chat caption from the webchat of chat bot 减少Bot Framework WebChat IFrame会话超时 - Reducing Bot Framework WebChat IFrame session timeout Webchat-Bot Framework(Nodejs)中的快速回复 - Quick Replies in Webchat- Bot Framework (Nodejs) 如何在 Bot Framework v4 中的某些对话后禁用聊天 - How to disable the chat after certain conversation in Bot Framework v4 Bot Framework嵌入式聊天 - 我可以自定义提示吗? - Bot Framework Embedded Chat - Can I customize the prompt? 带有 v4 网络聊天频道的 Bot Framework 问候语 - Bot Framework Greeting message with v4 Webchat Channel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM