I am having an issue with Teams Bot adaptive card action submit, when testing Bot Emulator it works as expected, but when it's published and performing the same action in Teams conversation, the action submit returns undefined. I have attempted with both adaptive card version 1.0, and version 1.3, the issue is the same in both cases. Anyone know a solution for this?
2 Answers
The other answer provides some useful background, but I think it's only applicable to specific scenarios - I think the issue you're having here is that you're sending a raw string value in the data
property ("My Action") which Teams doesn't like, but the emulator doesn't mind at all. You can see more about that described in this Microsoft blog post. You should instead be sending an actual object. I describe it in more detail in this answer: QnA Maker Bot AdaptiveCards: how to add Data object in C#.
What @billoverton is referring to is a specific use case where you want the button behaviour to be, for instance, actually putting a message into the text stream as a response, as well as sending it to your bot. There are various options for these specific use cases, as described here, but they are optional if you want this specific behaviour. If you're happy for the user to click the button and that to simply invoke the message to your bot, you don't need the "msteams" section in the data payload.

- 9,809
- 2
- 10
- 24
-
1Thanks for the additional context. One thing I will note is that if you are using any middleware that automatically processes the activity, that will happen before you can manually set `context.activity.text` in your `onMessage` handler. For instance, my transcript middleware will not have the text value if I do this. I agree this is a specific use case, but having null `activity.text` can mess up some things if you don't or are unable to handle it. – billoverton Jun 09 '21 at 14:49
A "standard" action.submit won't work in Teams. You need to add an msteams object under the data attribute. I'm guessing you are using a standard definition like
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "My Action",
"data": "My Action"
}
]
}
For Teams, it instead needs to look like this:
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "My Action",
"data": {
"msteams": {
"type": "imBack",
"value": "My Action"
}
}
}
]
}
Of course when you do this, it won't work in the emulator or any non-teams channel. I've seen some people update their onMessage handler to account for this by extracting the value so a single card definition can work for both channels, but it made the selection a backchannel event for one of the channels (can't remember if it was web or Teams) which was not the experience I was looking for. So instead, I just conditionally display a Teams or non-Teams card based on channel. For example:
if (context.activity.channelId == 'msteams') {
var welcomeCard = CardHelper.GetMenuCardTeams();
} else {
var welcomeCard = CardHelper.GetMenuCard();
}
If you are not using a helper to generate your cards you can define them explicitly here, though I do recommend using a helper to keep things clean. This does mean that you need to maintain two versions of your cards, but for me it was worth it to ensure a consistent experience across channels.

- 2,705
- 2
- 9
- 32
-
-
Perhaps you can help me with a different issue as well? I am experiencing some issues with logins, I am using Oauth provider to let users log in with their Auth0 user. The flow works, but not consistently. Example: "Login" command is input by user, this starts the flow and pops up the card for "Sign in". User clicks "Sign in", and a new "Sign In" card pops up. The user clicks Sign in again, and a new "Sign in" card pops up. User clicks sign in, and this time gets "You are now logged in", but the user is not successfully logged in. After some further forcing of logins, it works. – T-Rex Jun 09 '21 at 06:51
-
I'm not using Oauth so I don't think I can help, but regardless your best bet is to post this as a separate question. – billoverton Jun 09 '21 at 14:38