Reputation: 63
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!
Upvotes: 1
Views: 973
Reputation: 6368
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!
Upvotes: 1