The goal
recently, we've been trying to integrate our own python app into MS Teams. For this purpose we implemented some ActionCards that get sent to our MS Teams channel via incoming webhook.
Those cards have a button that does something (in our case label as good vs. no-good). The result of this button press is something we want to communicate on the card, using the card-action-status header of the response. In an MWE this looks like this screenshot
The problem
The problem is, this seems to work only on one certain pc (let's call it machine A). If started from any other device (e.g. PC, raspberry, virtual machine, let's call them machine B) the response does not show up below the card in MS Teams. There are no error messages or anything of the sorts, just the response not showing.
What we've tried
- exported the python environment from machine A, imported it on machine B
- inspected all HttpPost requests sent from python on both machine A and B using postman and webhook.site, and they are exactly alike
- sending the card via pymsteams
A MWE that reproduces the issue can be found below:
import requests
import json
from flask_ngrok import run_with_ngrok
from flask import Flask, request, jsonify, make_response
webhook_url = <my_webhook_url> # <-- teams webhook url or url from webhook.site goes here
app = Flask(__name__)
run_with_ngrok(app) #starts ngrok when the app is run
def create_card():
#get ngrok tunnel https url
tunnel_url = requests.get("http://localhost:4040/api/tunnels").text
j = json.loads(tunnel_url)
tunnel_url = j['tunnels'][0]['public_url']
if not tunnel_url.startswith("https"):
tunnel_url = j['tunnels'][1]['public_url']
#create teams card
card = {'potentialAction': [{
'@type': 'HttpPost',
'name': 'Test Button',
'target': tunnel_url + '/test_route',
'body': 'tender_id'},
],
'summary': 'Summary'}
return card
def send_card(card):
r = requests.post(
webhook_url,
json=card,
headers= {"Content-Type": "application/json"}
)
# route for when the button was clicked
@app.route("/test_route",methods = ['POST', 'GET'])
def test_route():
resp = make_response("success", 200)
resp.headers['CARD-ACTION-STATUS'] = 'Great Success'
return resp
# initial route
@app.route("/",methods = ['POST', 'GET'])
def start():
card = create_card()
send_card(card)
return 'success'
app.run()
We use the following package versions
flask_ngrok: 0.0.25
json : 2.0.9
requests : 2.25.1
flask : 1.1.2