如何格式化自适应卡,例如旧版的网络聊天 [英] How to format adaptive cards like the old version of webchat

查看:76
本文介绍了如何格式化自适应卡,例如旧版的网络聊天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准版网络聊天频道("gemini")的新版本去除了所有格式.我可以通过botframework-webchat实现中的调整来复制大多数旧界面,但是我无法获得匹配的自适应卡格式.使用常规格式,我可以将其关闭,然后在Github上的 距离更近一些,但是我仍然不知道如何复制它.具体地说,聊天气泡(在我的实现中为灰色)不再出现​​在自适应卡的后面.对于轮播来说,这一点尤其明显,因为轮播曾经是一个带有多个卡的泡泡",现在是离散卡.此外,按钮不再是交互式的(鼠标悬停时曾经显示蓝色边框),并且没有气泡"nub".请参见下面的示例.请注意,我确实知道如何将卡本身的背景设置为灰色以匹配气泡,但这不是我想要的外观或以前显示的外观.

The new version of the standard webchat channel ("gemini") stripped out all of the formatting. I was able to replicate most of the old interface via tweaks in the botframework-webchat implementation, but I cannot get the adaptive card formatting to match. With the general formatting I was able to get it close, and the adaptiveCardHostConfig tweaks shown here on Github got a bit closer, but I still can't figure out how to replicate it. Specifically, the chat bubble (which is gray in my implementation) no longer appears behind the adaptive card. This is especially noticeable for carousels, where it used to be one "bubble" with multiple cards and is now discrete cards. Furthermore, the buttons are no longer interactive (blue border used to appear on mouseover), and the bublle "nub" is absent. Please see below for examples. Note that I DO know how to make the background for the card itself gray to match the bubbles, but that is not the look that I want or that displayed previously.

总之,我要问

  1. 如何格式化以前版本中出现的灰色背景.
  2. 如何将气泡小块添加到卡片中(或更准确地说,是使卡片出现在气泡中).
  3. 如何使自适应卡上的按钮互动

单张卡(新在左,旧在右)

Single Card (new on left, old on right)

轮播(新在左侧,老在右侧)

Carousel (new on left, old on right)

这是网站代码

<!DOCTYPE html>
<html>
    <head>
        <title>Support Bot</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />

        <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>

        <style>
        html,
        body {
            height: 100%;
        }

        body {
            margin: 0;
        }

        html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, table, caption, tbody, tfoot, thead, tr, th, td {
            margin: 0;
            padding: 0;
            border: 0;
        }

        #chatbotTitle {
            display: flex;
            align-items: center;
            height: 40px;
            width: 100%;
            background-color: #0067CC;
            color: #FFFFFF;
            font-family: Calibri, Helvetica Neue, Arial, sans-serif;
            justify-content: space-between;
        }

        #webchat {
            height: calc(100% - 40px);
            width: 100%;
        }

        .btn {
            display: flex;
            background-color: white;
            border: 1px solid #767676;
            color: #0067CC;
            text-align: center;
            margin: 15px;
        }

        .btn:hover {
            border-color: #444444;
        }

        .btn:active {
            background-color: #CCCCCC;
        }

        </style>
    </head>
    <body>
        <div id="chatbotTitle"><h3 style="padding-left:10px;">Support Bot</h3><button class="btn" id="transcriptButton">Email Transcript</button></div>
        <div id="webchat" role="main"></div>
        <script>
            let interval;

            var PageTitleNotification = {
                Vars:{
                    OriginalTitle: document.title,
                    Interval: null
                },    
                On: function(notification, intervalSpeed){
                    var _this = this;
                    _this.Vars.Interval = setInterval(function(){
                        document.title = (_this.Vars.OriginalTitle == document.title)
                                 ? notification
                                 : _this.Vars.OriginalTitle;
                    }, (intervalSpeed) ? intervalSpeed : 1000);
                },
                Off: function(){
                    clearInterval(this.Vars.Interval);
                    document.title = this.Vars.OriginalTitle;   
                }
            }

            // We are using a customized store to add hooks to connect event
            const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {

                if (action.type === 'WEB_CHAT/SEND_MESSAGE') {
                    // Message sent by the user
                    PageTitleNotification.Off();
                    clearTimeout(interval);
                } else if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY' && action.payload.activity.name !== "inactive") {
                    // Message sent by the bot
                    clearInterval(interval);
                    interval = setTimeout(() => {
                        // Change title to flash the page
                        PageTitleNotification.On('Are you still there?');

                        // Notify bot the user has been inactive
                        dispatch({
                            type: 'WEB_CHAT/SEND_EVENT',
                            payload: {
                                name: 'inactive',
                                value: ''
                            }
                        });
                    }, 300000)
                }

                return next(action);
            });

            const adaptiveCardHostConfig = {
                "spacing": {
                    "small": 3,
                    "default": 8,
                    "medium": 20,
                    "large": 30,
                    "extraLarge": 40,
                    "padding": 10
                },
                "separator": {
                    "lineThickness": 1,
                    "lineColor": "#EEEEEE"
                },
                "supportsInteractivity": true,
                "fontTypes": {
                    "default": {
                    "fontFamily": "Calibri, sans-serif",
                    "fontSizes": {
                        "small": 12,
                        "default": 14,
                        "medium": 17,
                        "large": 21,
                        "extraLarge": 26
                    },
                    "fontWeights": {
                        "lighter": 200,
                        "default": 400,
                        "bolder": 600
                    }
                    },
                    "monospace": {
                    "fontFamily": "'Courier New', Courier, monospace",
                    "fontSizes": {
                        "small": 12,
                        "default": 14,
                        "medium": 17,
                        "large": 21,
                        "extraLarge": 26
                    },
                    "fontWeights": {
                        "lighter": 200,
                        "default": 400,
                        "bolder": 600
                    }
                    }
                },
                "containerStyles": {
                    "default": {
                    "backgroundColor": "#FFFFFF",
                    "foregroundColors": {
                        "default": {
                        "default": "#000000",
                        "subtle": "#767676"
                        },
                        "accent": {
                        "default": "#0063B1",
                        "subtle": "#0063B1"
                        },
                        "attention": {
                        "default": "#FF0000",
                        "subtle": "#DDFF0000"
                        },
                        "good": {
                        "default": "#54a254",
                        "subtle": "#DD54a254"
                        },
                        "warning": {
                        "default": "#c3ab23",
                        "subtle": "#DDc3ab23"
                        }
                    }
                    },
                    "emphasis": {
                    "backgroundColor": "#F0F0F0",
                    "foregroundColors": {
                        "default": {
                        "default": "#000000",
                        "subtle": "#767676"
                        },
                        "accent": {
                        "default": "#2E89FC",
                        "subtle": "#882E89FC"
                        },
                        "attention": {
                        "default": "#FF0000",
                        "subtle": "#DDFF0000"
                        },
                        "good": {
                        "default": "#54a254",
                        "subtle": "#DD54a254"
                        },
                        "warning": {
                        "default": "#c3ab23",
                        "subtle": "#DDc3ab23"
                        }
                    }
                    },
                    "accent": {
                    "backgroundColor": "#C7DEF9",
                    "foregroundColors": {
                        "default": {
                        "default": "#333333",
                        "subtle": "#EE333333"
                        },
                        "dark": {
                        "default": "#000000",
                        "subtle": "#66000000"
                        },
                        "light": {
                        "default": "#FFFFFF",
                        "subtle": "#33000000"
                        },
                        "accent": {
                        "default": "#2E89FC",
                        "subtle": "#882E89FC"
                        },
                        "attention": {
                        "default": "#cc3300",
                        "subtle": "#DDcc3300"
                        },
                        "good": {
                        "default": "#54a254",
                        "subtle": "#DD54a254"
                        },
                        "warning": {
                        "default": "#e69500",
                        "subtle": "#DDe69500"
                        }
                    }
                    },
                    "good": {
                    "backgroundColor": "#CCFFCC",
                    "foregroundColors": {
                        "default": {
                        "default": "#333333",
                        "subtle": "#EE333333"
                        },
                        "dark": {
                        "default": "#000000",
                        "subtle": "#66000000"
                        },
                        "light": {
                        "default": "#FFFFFF",
                        "subtle": "#33000000"
                        },
                        "accent": {
                        "default": "#2E89FC",
                        "subtle": "#882E89FC"
                        },
                        "attention": {
                        "default": "#cc3300",
                        "subtle": "#DDcc3300"
                        },
                        "good": {
                        "default": "#54a254",
                        "subtle": "#DD54a254"
                        },
                        "warning": {
                        "default": "#e69500",
                        "subtle": "#DDe69500"
                        }
                    }
                    },
                    "attention": {
                    "backgroundColor": "#FFC5B2",
                    "foregroundColors": {
                        "default": {
                        "default": "#333333",
                        "subtle": "#EE333333"
                        },
                        "dark": {
                        "default": "#000000",
                        "subtle": "#66000000"
                        },
                        "light": {
                        "default": "#FFFFFF",
                        "subtle": "#33000000"
                        },
                        "accent": {
                        "default": "#2E89FC",
                        "subtle": "#882E89FC"
                        },
                        "attention": {
                        "default": "#cc3300",
                        "subtle": "#DDcc3300"
                        },
                        "good": {
                        "default": "#54a254",
                        "subtle": "#DD54a254"
                        },
                        "warning": {
                        "default": "#e69500",
                        "subtle": "#DDe69500"
                        }
                    }
                    },
                    "warning": {
                    "backgroundColor": "#FFE2B2",
                    "foregroundColors": {
                        "default": {
                        "default": "#333333",
                        "subtle": "#EE333333"
                        },
                        "dark": {
                        "default": "#000000",
                        "subtle": "#66000000"
                        },
                        "light": {
                        "default": "#FFFFFF",
                        "subtle": "#33000000"
                        },
                        "accent": {
                        "default": "#2E89FC",
                        "subtle": "#882E89FC"
                        },
                        "attention": {
                        "default": "#cc3300",
                        "subtle": "#DDcc3300"
                        },
                        "good": {
                        "default": "#54a254",
                        "subtle": "#DD54a254"
                        },
                        "warning": {
                        "default": "#e69500",
                        "subtle": "#DDe69500"
                        }
                    }
                    }
                },
                "imageSizes": {
                    "small": 40,
                    "medium": 80,
                    "large": 160
                },
                "actions": {
                    "maxActions": 100,
                    "spacing": "default",
                    "buttonSpacing": 8,
                    "showCard": {
                    "actionMode": "inline",
                    "inlineTopMargin": 8
                    },
                    "actionsOrientation": "vertical",
                    "actionAlignment": "stretch"
                },
                "adaptiveCard": {
                    "allowCustomStyle": false
                },
                "imageSet": {
                    "imageSize": "medium",
                    "maxImageHeight": 100
                },
                "factSet": {
                    "title": {
                    "color": "default",
                    "size": "default",
                    "isSubtle": false,
                    "weight": "bolder",
                    "wrap": true,
                    "maxWidth": 150
                    },
                    "value": {
                    "color": "default",
                    "size": "default",
                    "isSubtle": false,
                    "weight": "default",
                    "wrap": true
                    },
                    "spacing": 8
                }
            };

            window.WebChat.renderWebChat(
                {
                    adaptiveCardHostConfig,
                    directLine: window.WebChat.createDirectLine({
                        token: 'MYTOKENHERE'
                    }),
                    store: store,
                    userID: 'userID',
                    username: 'userName',
                    locale: 'en-US',
                    styleOptions: {
                        botAvatarInitials: 'BOT',
                        userAvatarInitials: 'USR',
                        accent: '#0067CC',
                        backgroundColor: 'White',
                        cardEmphasisBackgroundColor: '#F0F0F0',
                        paddingRegular: 10,
                        paddingWide: 10 * 2,
                        messageActivityWordBreak: 'break-word',
                        fontSizeSmall: '80%',
                        avatarSize: 40,
                        botAvatarBackgroundColor: '#0067CC',
                        botAvatarImage: '',
                        botAvatarInitials: '',
                        userAvatarBackgroundColor: '#ECEFF1',
                        userAvatarImage: '',
                        userAvatarInitials: '',
                        bubbleBackground: '#ECEFF1',
                        bubbleBorderColor: '#E6E6E6',
                        bubbleBorderRadius: 8,
                        bubbleBorderStyle: 'solid',
                        bubbleBorderWidth: 1,
                        bubbleFromUserBackground: '#0067CC',
                        bubbleFromUserBorderColor: '#E6E6E6',
                        bubbleFromUserBorderRadius: 8,
                        bubbleFromUserBorderStyle: 'solid',
                        bubbleFromUserBorderWidth: 1,
                        bubbleFromUserNubOffset: 'bottom',
                        bubbleFromUserNubSize: 10,
                        bubbleFromUserTextColor: 'White',
                        bubbleImageHeight: 240,
                        bubbleMaxWidth: 480,
                        bubbleMinHeight: 30,
                        bubbleMinWidth: 250,
                        bubbleNubOffset: 'bottom',
                        bubbleNubSize: 10,
                        bubbleTextColor: 'Black',
                        markdownRespectCRLF: true,
                        richCardWrapTitle: false,
                        rootHeight: '100%',
                        rootWidth: '100%',
                        hideScrollToEndButton: false,
                        hideSendBox: false,
                        hideUploadButton: true,
                        microphoneButtonColorOnDictate: '#F33',
                        sendBoxBackground: 'White',
                        sendBoxButtonColor: '#767676',
                        sendBoxButtonColorOnDisabled: '#CCC',
                        sendBoxButtonColorOnFocus: '#0067CC',
                        sendBoxButtonColorOnHover: '#0067CC',
                        sendBoxDisabledTextColor: '#767676', // defaults to subtle
                        sendBoxHeight: 40,
                        sendBoxMaxHeight: 200,
                        sendBoxTextColor: 'Black',
                        sendBoxBorderBottom: 'solid 5px #DBDEE1',
                        sendBoxBorderLeft: 'solid 5px #DBDEE1',
                        sendBoxBorderRight: 'solid 5px #DBDEE1',
                        sendBoxBorderTop: 'solid 5px #DBDEE1',
                        sendBoxPlaceholderColor: undefined, // defaults to subtle
                        sendBoxTextWrap: false,
                        showSpokenText: false,
                        suggestedActionBackground: 'White',
                        suggestedActionBorder: undefined,
                        suggestedActionBorderColor: '#CCCCCC',
                        suggestedActionBorderRadius: 0,
                        suggestedActionBorderStyle: 'solid',
                        suggestedActionBorderWidth: 1,
                        suggestedActionDisabledBackground: '#F9F9F9',
                        suggestedActionDisabledBorder: null,
                        suggestedActionDisabledBorderColor: '#E6E6E6',
                        suggestedActionDisabledBorderStyle: 'solid',
                        suggestedActionDisabledBorderWidth: 1,
                        suggestedActionDisabledTextColor: '#767676',
                        suggestedActionHeight: 30,
                        suggestedActionImageHeight: 20,
                        suggestedActionLayout: 'carousel',
                        suggestedActionTextColor: null,
                        groupTimestamp: false,
                        sendTimeout: 20000,
                        sendTimeoutForAttachments: 120000,
                        timestampColor: '#767676',
                        timestampFormat: 'relative',
                        transcriptOverlayButtonBackground: 'rgba(0, 0, 0, .6)',
                        transcriptOverlayButtonBackgroundOnFocus: 'rgba(0, 0, 0, .8)',
                        transcriptOverlayButtonBackgroundOnHover: 'rgba(0, 0, 0, .8)',
                        transcriptOverlayButtonColor: 'White',
                        transcriptOverlayButtonColorOnFocus: 'White',
                        transcriptOverlayButtonColorOnHover: 'White',
                        typingAnimationBackgroundImage: null,
                        typingAnimationDuration: 5000,
                        typingAnimationHeight: 20,
                        typingAnimationWidth: 64,
                        subtle: '#767676'
                    }
                },
                document.getElementById('webchat')
            );

            document.querySelector('#transcriptButton').addEventListener('click', () => {
                store.dispatch({
                    type: 'WEB_CHAT/SEND_MESSAGE',
                    payload: { text: 'Email me a transcript' }
                });
            });

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

推荐答案

网络聊天自适应卡都是开源的,因此,如果您想弄清楚它们的源代码,最好下载它们弄清楚它们是如何工作的.在Web聊天库中,您可以切换到v3分支以查看v3的工作方式. Web聊天使用Adaptive Cards JavaScript SDK,并且处理解析和呈现的代码在

Web Chat and Adaptive Cards are both open source, so it's a good idea to download their source code if you want to figure out how they work. In the Web Chat repo you can switch to the v3 branch to see how v3 works. Web Chat uses the Adaptive Cards JavaScript SDK, and the code that handles parsing and rendering is in card-elements.ts.

botchat.css 中,您可以看到在此处创建您想要的背景:

In botchat.css, you can see the styles that create the background you want here:

.wc-message-content {
  border-radius: 2px;
  box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.2);
  padding: 8px;
  word-break: break-word; }

.wc-message-from-bot .wc-message-content {
  background-color: #eceff1;
  color: #000000; }

Web Chat v4中未使用这些类,但是您可以将其应用于附件和轮播,如下所示:

Those classes aren't used in Web Chat v4, but you can apply it to your attachments and carousels like this:

div.attachment.bubble,
div.content > ul.webchat__carousel__item_indented {
    background-color: #eceff1;
    color: #000000;
    border-radius: 2px;
    box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.2);
    padding: 8px;
}

我对选择器非常具体,因为还有另一种样式会尝试将padding设置为0.如果需要,您可以只使用!important关键字.

I'm being pretty specific with the selector because there's another style that will try to set the padding to 0. You can just use the !important keyword if you want.

您已经看到Web聊天不允许在v4中的附件上出现气泡.负责此操作的行是这里:

You've already seen that Web Chat doesn't allow bubble nubs on attachments in v4. The line responsible for this is here:

<Bubble className="attachment bubble" fromUser={fromUser} key={index} nub={false}>

您可以根据

You can modify the way activities are rendered using activity middleware according to this sample. In your case you'll want to render an SVG element alongside the activity.

要向按钮添加悬停样式,您可以再次查看 botchat.css :

To add hover styles to your buttons, you can again have a look at botchat.css:

.wc-card button:hover {
  background-color: transparent;
  border-color: #0078d7;
  color: #0078d7; }

您可以使用所有这三个声明,也可以仅使用border-color:

You can use all three of those declarations or just border-color:

.ac-adaptiveCard button:hover {
    border-color: #0078d7;
}

这篇关于如何格式化自适应卡,例如旧版的网络聊天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆