1
votes

I've created a bot in C# using the Microsoft Bot Framework, successfully hosted it in Azure, gotten it registered in Teams, and everything's working great - except when a user tries to click on a button that's supposed to open a URL. The user is presented with a card that has three options on it, and clicking one of the options in the Web Chat feature in Azure or when using the Teams app on a phone successfully launches a browser with the desired URL. However, clicking a button in the browser-based version of Teams on a desktop creates a new tab with the url https://teams.microsoft.com/null, and clicking a button on the desktop version of Teams doesn't seem to do anything. The code for the card looks like this:

private static async Task SendLinkCard(ITurnContext<IMessageActivity> turnContext, HeroCard card, CancellationToken cancellationToken)
        {
            card.Title = "Link Card";
            card.Text = "Choose an option:";
            card.Buttons.Add(new CardAction
            {
                Type = ActionTypes.OpenUrl,
                Title = "Link 1",
                Value = "https://google.com/​",
            });
            card.Buttons.Add(new CardAction
            {
                Type = ActionTypes.OpenUrl,
                Title = "Link 2",
                Value = "https://stackoverflow.com​"
            });
            card.Buttons.Add(new CardAction
            {
                Type = ActionTypes.OpenUrl,
                Title = "Link 3",
                Value = "https://example.com"
            });

            var activity = MessageFactory.Attachment(card.ToAttachment());

            await turnContext.SendActivityAsync(activity, cancellationToken);
        }

I'm out of ideas here, and this seems like it should be so simple - any help would be appreciated!

1
Offhand, everything looks correct, not sure why it's not working. Out of interest, do you need a Hero card specifically? You might have better luck with an Adaptive card, which has more (and growing) options anyway - Hilton Giesenow
Hilton, I don't specifically need a Hero card, but I could never get Adaptive cards to work properly, and I'm limiting myself to just some text and a couple of clickable buttons on each card so a Hero card seemed to be a good option. Steven, thanks for the help - I finally got back to my computer to try your code and it's in a much better place now. - Matthew Warren

1 Answers

1
votes

As you'll see in the docs, the below is the preferred method of assigning elements to a hero card button. I tested this implementation without error.

Buttons = new List<CardAction> { new CardAction(ActionTypes.OpenUrl, "Link 1", value: "https://google.com/") },
Buttons = new List<CardAction> { new CardAction(ActionTypes.OpenUrl, "Link 2", value: "https://stackoverflow.com") },
Buttons = new List<CardAction> { new CardAction(ActionTypes.OpenUrl, "Link 3", value: "https://example.com") }

Now, using Buttons.add() should work, but when in doubt go with the best practice.

All that aside, this also may have been more of a Teams issue than a BotFramework issue as when testing this the previous day, I also saw the bad link. However, testing today does not. It's worth noting I updated to the recently released 4.11.0 version of the SDK.

Hope of help!