How to update a card-message already sent in microsoft-teams using connectors?

I am developing two microservices, one that sends a card-message to microsoft-teams, and another that receives the action taken on that card, and I am using the office 365 connectors that are created within Microsoft-teams chat itself.

The two microservices are working perfectly, one sends, another receives the action taken.

The issue in this scope is that when the action is taken on the card, I want the button to disappear so that the user cannot more take the same action on that card.

Microsoft says: https://docs.microsoft.com/pt-br/outlook/actionable-messages/message-card-reference#httppost-action

  • to update a card as a result of an HttpPOST action, a service will need to do the following: >
  • include the JSON load of the new card in the response body for the received HTTP POST request.
  • add the HTTP CARD-UPDATE-in-BODY: true header to the response, to inform the receiving client > > that it should analyze the response body and extract a new card (this is to avoid unnecessary processing > > when no updated card is included.)

If you are unable to access the cards through GitHub you have on the microsoft website https://docs.microsoft.com/pt-br/outlook/actionable-messages/message-card-reference

Code used to send the card using python.

import requests
import json
        
# Endereço gerado pelo teams-connector para envio de cards
address = "https://outlook.office.com/webhook/??????-????-????-????-d22b62fe5943@ba201131-9621-49ca-b50d-57d968b4ac35/IncomingWebhook/ce2ec4ae6f284993ad788e4e0bcec186/72683000-b59c-491c-b930-????????"
headers = {"Content-Type": "application/json"}

# Cartão usado no exemplo descrito
message_json = requests.get("https://raw.githubusercontent.com/GuiLuccaDev/msteams-python/master/card-message.json", headers=headers).json()

# Adicionar um endereço para o HTTPPost do Teams quanto a ação do botão, eu usei ngrok.io para isso
# Sera usado para o código de recebimento da ação
httppost = "https://???????????.ngrok.io"

potential_action = message_json["potentialAction"]
potential_action[0]["actions"][0]["target"] = httppost
potential_action[1]["actions"][0]["target"] = httppost
potential_action[2]["actions"][0]["target"] = httppost

retorno = requests.post(address, data=json.dumps(message_json), headers=headers)

print(retorno)

Card sending code result

To receive the action of the messages a simple flask server.

from flask import Flask, request
import requests
import json

app = Flask(__name__)

@app.route("/", methods=["POST"])
def index():
    card_simple = requests.get("https://raw.githubusercontent.com/GuiLuccaDev/msteams-python/master/card-simple.json", headers={"Content-Type": "application/json"}).json()

    address = "https://outlook.office.com/webhook/??????-????-????-????-d22b62fe5943@ba201131-9621-49ca-b50d-57d968b4ac35/IncomingWebhook/ce2ec4ae6f284993ad788e4e0bcec186/72683000-b59c-491c-b930-????????"
    headers = {"Content-Type": "application/json", "CARD-UPDATE-IN-BODY": "true"}

    retorno = requests.post(address, data=json.dumps(card_simple), headers=headers)    
    
    return "ok"

if __name__ == "__main__":
    app.run()

Starting from this point, I have tried in numerous ways to update this card and could not, it always creates a new one when I try to send a new card using "CARD-UPDATE-IN-BODY: true" in the header, I have already sent the header that comes from the HTTPPost of the entire teams back to the request. Above is an example of code forwarding a simple card with the header informed by microsoft.

Author: Guilherme Antonio De Luca, 2020-07-08