MS Teams and adaptive Cards

Hello,

i just did try to send a simple adaptive card to MS Teams. I did try the following way:

  1. action Server

class Welcome(Action): def name(self) → Text: return “action_welcome”

async def run(
    self,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any],
) -> List[EventType]:

    message ={ "type": "AdaptiveCard",  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",  "version": "1.3", "body": [{  "type": "TextBlock", "text": "New TextBlock","wrap": True }]}

    dispatcher.utter_message(json_message = message)
    return []

which ends up with the error: 2021-07-13 17:04:33 INFO root - Rasa server is up and running. 2021-07-13 17:04:51 ERROR rasa.core.channels.botframework - Exception when trying to handle message.‘str’ object has no attribute ‘setdefault’

Is there any working example of MS Teams cards in action Server?

content of the message send to MS Teams: {‘type’: ‘AdaptiveCard’, ‘$schema’: ‘http://adaptivecards.io/schemas/adaptive-card.json’, ‘version’: ‘1.3’, ‘body’: [ {‘type’: ‘TextBlock’, ‘text’: ‘New TextBlock’, ‘wrap’: True}], ‘recipient’: {‘id’: ‘xxxg’}, ‘from’: {‘id’: ‘2xxx2’, ‘name’: ‘xxxTest’}, ‘channelData’: {‘notification’: {‘alert’: ‘true’}}, ‘text’: ‘’}

correct code:

class Welcome(Action): def name(self) → Text: return “action_welcome”

async def run(
    self,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any],
) -> List[EventType]:


    newmessage = {
      "attachments": [
        {
          "contentType": "application/vnd.microsoft.card.adaptive",
          "content": {
            "type": "AdaptiveCard",
            "version": "1.0",
            "body": [
              {
                "type": "TextBlock",
                "text": "Hello World!",
                "size": "large"
              },
              {
                "type": "TextBlock",
                "text": "*Sincerely yours,*"
              },
              {
                "type": "TextBlock",
                "text": "Adaptive Cards",
                "separation": "none"
              }
            ],
            "actions": [
              {
                "type": "Action.OpenUrl",
                "url": "http://adaptivecards.io",
                "title": "Learn More"
              }
            ]
          }
        }
      ]
    }
    dispatcher.utter_message(json_message = newmessage)


    return []

Hi Sven, please help out with an issue! Been stuck for over days now! In the same code you shared, if I create buttons using “type”: “Action.Submit”. Then how am I supposed to attach respective intent(s) to the buttons, so that next action can be triggered! For more clarification on this, refer to the link to my query:

Please suggest! You would really help a lot!

intents are done with the following syntax /intent

Where do I attach this syntax- /intent, in the “newmessage”! Can you please correct my code and send the same back to me! Really grateful to you for reaching back! Appreciate your time, @dx111ge !

newmessage = {
      "attachments": [
        {
          "contentType": "application/vnd.microsoft.card.adaptive",
          "content": {
            "type": "AdaptiveCard",
            "version": "1.0",
            "body": [
              {
                "type": "TextBlock",
                "text": "Please select your choice!"
              }
            ],
            "actions": [
              {
                    "type": "Action.Submit",
                    "title": "Button1"                             # Where to attach "/intent1" ?
                },
                {
                    "type": "Action.Submit",
                    "title": "Button2"                      # Where to attach "/intent2" ?
                       
                }
            ]
          }
        }
      ]
    }
    dispatcher.utter_message(json_message = newmessage)


    return []

{ “type”: “Action.Submit”, “title”: “abbrechen”, “data”: { “msteams”: { “type”: “imBack”, “value”: “/restart” } }, “style”: “positive” }

That works! Thanks mate! @dx111ge

I am stuck with a similar issue, I am trying to use datepicker, but unable to get the user selected date in the actions server.

The date selected should be identified as “requested_departure_date entity”, from “modify_departure_date” intent, examples are present in my NLU.yml.

Below is the code of adaptive card:

adaptive_card_json = {
                                "type": "AdaptiveCard",
                                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                                "version": "1.3",
                                "body": [
                                            {
                                            "type": "Input.Date",
                                            "id": "requested_departure_date",
                                            "title": "Select a date:",
                                            "value": "2023-08-01",
                                            "min": "2023-01-01",
                                            "max": "2023-12-31"
                                            }
                                        ],
                                "actions": [
                                            {
                                                "type": "Action.Submit",
                                                "title": "Submit",
                                                "text" : "August 23, 2023",
                                                "channel": "botframework",
                                                "id" :"requested_departure_date", 
                                                "data": {
                                                    "msteams":{
                                                    "text":"${requested_departure_date}",
                                                    "title":"Select",
                                                    "type":"messageBack",
                                                    "value" : "/modify_departure_date"
                                                    }, 
                                                "style": "positive"
                                                }
                                                }
                                            ]
                            }
            


            message = {
                "type": "message",
                "text": "Here is the calendar:",
                "attachments": [
                    {
                        "contentType": "application/vnd.microsoft.card.adaptive",
                        "content": adaptive_card_json
                    }
                ]
            }

            dispatcher.utter_message(json_message=message)
            print('will be exiting calendar now')

Hello!

I developed a bot using Rasa, and it’s currently connected to an Azure Bot via a webhook, and I have it activated on the Teams channel. In general, it’s functioning normally and provides responses within the Teams bot conversation. However, there are occasions when I’m using dispatcher.utter_message(text="example text") in the actions.py file to display messages within the bot conversation, but although no error is generated, the response message isn’t displayed within the conversation. Typically, the dispatcher works fine, even with AdaptiveCards that I’m using for Teams, but sometimes the messages fail to appear. I’ve been thinking that there might be a time limit, and after this time, it’s not possible to display the message with the dispatcher within the bot in Teams.

I would appreciate it if someone has knowledge about this and can clarify this issue for me.

Thank you!

@anemptyhead Did you get any solution?