How to message back in an OpenUrl Card Action?

谁说胖子不能爱 提交于 2020-01-06 05:57:12

问题


I am sending a cardAction with openURL where a user is supposed to click the button, follow instructions from said URL, and then report back the data. I would like a message displayed when the user clicks on the button, which is also when the URL is opened.

From what I have tested, I can only either ImBack or OpenUrl. Is there a way to do both in one CardAction?

var card = new SigninCard()
{
    Buttons = new List<CardAction>()
    {
        new CardAction()
        {
            Title = "Open a URL",
            Type = ActionTypes.OpenUrl,
            Value = this.myURL,   
            DisplayText = "I want to show text when I open myURL but this text doesn't show",
        },
        new CardAction()
        {
            Title = "Message Back",
            Type = ActionTypes.ImBack,
            Value = "MessageBackButtonClicked",
        },
    },
};

回答1:


Unfortunately, each channel is responsible for handling user actions and most channels do not notify you when a user clicks on a link. However, in Web Chat, you can use the card action middleware to dispatch a backchannel event when the user clicks on an open URL action. Note, this will only work with Web Chat and not any other channel.

Bot Framework Web Chat v4

const cardActionMiddleware = ({ dispatch }) => next => action => {
  const { cardAction: { type, value } } = action;
  if (type === 'openUrl') {
    dispatch({
      type: 'WEB_CHAT/SEND_EVENT',
      payload: {
        name: 'webchat/urlClickedEvent',
        value: `Navigating to ${value}`
      }
    });
  }
  return next(action);
}

window.WebChat.renderWebChat({
  cardActionMiddleware,
  directLine,
}, document.getElementById('webchat'));

Hope this helps!



来源:https://stackoverflow.com/questions/57455089/how-to-message-back-in-an-openurl-card-action

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!