问题
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