【问题标题】:Tool tip for long texts in Hero Cards英雄卡中长文本的工具提示
【发布时间】:2019-05-29 09:40:16
【问题描述】:

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

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

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

有什么帮助吗?

【问题讨论】:

  • 希望你能成功。如果您觉得我的回答足够,请“接受”它,以便我可以从我的支持跟踪器中清除这张票。如果没有,请告诉我我还能提供哪些帮助!

标签: botframework adaptive-cards


【解决方案1】:

网络聊天使用Adaptive Cards NPM 包来呈现卡片,不幸的是,自适应卡片不支持向卡片中的元素添加工具提示描述。然而,在 GitHub 上有几个关于添加工具提示功能的 issues 打开,因此希望该功能将很快在网络聊天中可用。

即使自适应卡片不支持添加工具提示,您也可以为网络聊天创建自定义附件中间件并实现自己的英雄卡片渲染器。下面的代码 sn-p 显示了一个基本的英雄卡片渲染器,没有任何样式。

<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

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-02
    • 2021-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多