Search code examples
node.jsbotframeworkchatbotadaptive-cards

Calling a method/callback after adaptive card's Action.OpenUrl operation


I'm using adaptive card to show an article to user in node js.

My Adaptive card format:

function AdaptCard(Txt, Img, Url) {
let cardFormat = {
    contentType: "application/vnd.microsoft.card.adaptive",
    content: {
        "type": "AdaptiveCard",
        "version": "1.0",
        "body": [
            {
                "type": "TextBlock",
                "text": Txt,
                "size": "medium",
                "weight": "bolder",
                "wrap": true
            },
            {
                "type": "Image",
                "url": Img,
                "size": "auto"
            }
        ],
        "actions": [
            {
                "type": "Action.OpenUrl",
                "title": "View Article",
                "url": Url
            }
        ]
    }
};
return cardFormat; 
}

Session Code:

bot.beginDialog(message.address, 'ShowArticle'); 
bot.dialog('ShowArticle', [ 
 (session) => { 
 let dispCard = new builder.Message(session).addAttachment(AdaptCard("Title", "Image URL", "Link URL" ));
 session.send(dispCard ); 
}]);

I'm trying to ask a user that if the url provided is useful?, after he visits the article. Is there any event like bot.on('some event') that i can use once the user does Action.OpenUrl?

Need help pls.


Solution

  • OpenUrl actions just call a url. There is no call made to the bot.

    However, one option is to add a path to the website hosting the bot that receives the actual url as a query string parameter (also including userid, channel, and conversationid). Then, when the user clicks the link, redirect to the actual url and use the UserId, Channel, and ConverationId to proactively send the user a message asking if the link was helpful. (More information on ProactiveMessaging can be found here: https://learn.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-proactive-messages )

    If the channel you are targeting is WebChat, you can modify the source and make a call to the bot when the openUrl occurs: https://github.com/Microsoft/BotFramework-WebChat/blob/1587aa7972fba28d3a9adc8b2c6a090ab4e285a0/src/Chat.tsx#L280