Search code examples
microsoft-teamsadaptive-cards

Fetch card information from HTML contentType from message action


I am developing a message action and trying to fetch the content of the card existing in the chat.


if, the content is normal text in the chat, then its not hard as seem below:

...
messagePayload: {
  ...
  body: { 
    contentType: 'text', 
    content: 'hello' 
  },
  ...
}
...

if, its an Adaptive / Hero card, I am fetching something like an HTML tag, as seen below:

...
messagePayload: {
  ...
  body: {
    contentType: 'html',
    content: '<attachment id="8a3e7358a8294a52ae95e8071c7e3ed3"></attachment>'
  },
  ...
}
...

Is there any way to get information from the above tag or any other way to fetch information?

Also, I achieved creating tasks using create work item from Azure Board message action. Looking for a similar thing working with my message action.


Please refer to the below attachment

enter image description here


Solution

  • To get the card content you have to do several steps:

    1. Create Extension Command.
    2. Select "Allow users to trigger actions in external services while inside of Teams". enter image description here
    3. Select "Fetch a dynamic set of parameters from your bot". enter image description here
    4. Handle "composeExtension/fetchTask" in your getInvokeHandler method (Here's an example), or handleTeamsMessagingExtensionSubmitAction.
    5. Your serialized card content has to be in event.value.messagePayload.attachments if you are using getInvokeHandler and in context._activity.value.messagePayload.attachments if you are using handleTeamsMessagingExtensionSubmitAction