简体   繁体   English

自适应卡片 Action.OpenURL 跟踪

[英]Adaptive Card Action.OpenURL Tracking

Adaptive Card 1.2 / 1.3自适应卡 1.2 / 1.3

Issue问题

This is related to the Action.OpenURL button which we have in Adaptive Cards.这与我们在自适应卡片中的Action.OpenURL按钮有关。 When you display an Adaptive Card to a user with some links on it (Action.OpenURL), it simply open that URL in a new tab.当您向用户显示带有一些链接的自适应卡片 (Action.OpenURL) 时,它只需在新选项卡中打开该 URL。 Bot doesn't any idea whether the link was clicked or not, this makes the tracking of the event difficult to handle specially in case of when we wants to log which link was clicked for a particular utterance. Bot 不知道链接是否被点击,这使得事件的跟踪难以处理,特别是在我们想要记录特定话语点击了哪个链接时。

Can anyone please help us, what is the better way to handle this.任何人都可以帮助我们,有什么更好的方法来处理这个问题。

I believe there was something that changed in Adaptive Cards that no longer allows you to do something like this.我相信 Adaptive Cards 发生了一些变化,不再允许你做这样的事情。 But here is something I have discovered, but no idea if it actually works.但这是我发现的一些东西,但不知道它是否真的有效。

<script type="text/babel" data-presets="es2015,react,stage-3">
  (async function () {
    const { ReactWebChat } = window.WebChat;
    const cardActionMiddleware = () => next => async ( { cardAction } ) => {
      if (cardAction?.type === 'openUrl') {
        const urlButtonClickEvent = new Event('urlButtonClick')
        urlButtonClickEvent.data = cardAction.value;
        window.dispatchEvent(urlButtonClickEvent);
      }
      return next( { cardAction } );
    }
    const res = await fetch('http://localhost:3500/directline/token', { method: 'POST' });
    const { token } = await res.json();
    window.ReactDOM.render(
      <ReactWebChat
        directLine={ window.WebChat.createDirectLine({ token }) }
        cardActionMiddleware={cardActionMiddleware}
      />,
      document.getElementById('webchat')
    );
    document.querySelector('#webchat > *').focus();
    window.addEventListener( 'urlButtonClick', ( { data } ) => {
      store.dispatch({
        type: 'WEB_CHAT/SEND_EVENT',
        payload: {
          name: 'URL_BUTTON_CLICK',
          value: data
        }
      })
    } );
  })().catch(err => console.error(err));
</script>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM