英雄卡中长文本的工具提示

Tool tip for long texts in Hero Cards

我正在使用 Bot Framework Webchat(基于 React)。我使用 Card Actions(Hero Cards)来建议类似问题的列表。有时英雄卡中的文字可能太长。在这种情况下,文本会被截断并替换为三个点。是否可以提供英雄卡的工具提示?

我查看了代码中的 HeroCard 选项,但没有找到任何相关内容。

我已在 Github 上提出此问题:https://github.com/microsoft/BotFramework-WebChat/issues/2032

请帮忙解决这个问题?

网络聊天利用 Adaptive Cards NPM package to render cards, and, unfortunately, Adaptive Cards does not support adding tooltip descriptions to elements in the card. There are, however, several issues 在 GitHub 上打开的关于添加工具提示功能的功能,因此希望该功能很快会在网络聊天中可用。

即使 Adaptive Cards 不支持添加工具提示,您也可以为 Web Chat 创建自定义附件中间件并实现您自己的 Hero Card 渲染器。下面的代码片段显示了一个没有任何样式的基本 Hero Card 渲染器。

<script type="text/babel">

  const HeroCardAttachment = ({ buttons, images, title, store }) =>
    <div className='ac-container'>
      <div className='ac-container'>
        { images.map(({ url }, index) => 
          <window.React.Fragment key={ index }>
            <div>
              <img src= { url } />
            </div>
            <div style={{height: '8px'}}/>
          </window.React.Fragment>
        )}
        <div>{ title }</div>
      </div>
      <div />
      <div >
        { buttons.map(({ title, type, value }, index) => (
          <window.React.Fragment key={ index }>
            <button 
              aria-label={ title }
              type='button' 
              title={ title }
              onClick={ () => {
                switch (type) {
                  case 'openUrl':
                    window.open(value)
                    break;
                  case 'postBack':
                    store.dispatch({
                      type: 'WEB_CHAT/SEND_POST_BACK',
                      payload: { value }
                    });
                    break;
                  default:
                    store.dispatch({
                      type: 'WEB_CHAT/SEND_MESSAGE_BACK',
                      payload: { value, text: value, displayText: value }
                    });
                }
              }}
            >
              <div title={ title }>
                { title }
              </div>
            </button>
            <div />
          </window.React.Fragment>
        ))}
      </div>
    </div>;

  (async function () {

    const res = await fetch('/directline/token', { method: 'POST' });
    const { token } = await res.json();
    const { createStore, ReactWebChat } = window.WebChat;
    const store = createStore();

    const attachmentMiddleware = () => next => card => {
      switch (card.attachment.contentType) {
        case 'application/vnd.microsoft.card.hero':
          return <HeroCardAttachment {...card.attachment.content} store={ store }/>;
        default:
          return next(card);
      }
    };

    window.ReactDOM.render(
      <ReactWebChat
        attachmentMiddleware={ attachmentMiddleware }
        directLine={ window.WebChat.createDirectLine({ token }) }
        store={ store }
      />,
      document.getElementById('webchat')
    );

    store.dispatch({
      type: 'WEB_CHAT/SET_SEND_BOX',
      payload: { text: 'sample:github-repository' }
    });

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

有关附件中间件的更多详细信息,请查看此 sample

希望这对您有所帮助。