问题
I am new to Python and have been trying to integrate it with MS Teams using an outgoing webhook. I have created a simple web service to handle post request using flask and I am hosting it using ngrok and the resulting URL from ngrok have been used as the Outgoing webhook callback URL in teams.
I am able to receive message in my service and send an adaptive card as response. But if I fill out the information and click Submit I get 'Something went wrong. Please try again' error and I am not receiving anything in my service.
Any help will be highly appreciated.Screenshot for Adaptive card in Teams
from flask import Flask, request, jsonify
import hmac, hashlib, base64
app = Flask(__name__)
@app.route('/testjson',methods = ['POST', 'GET'])
def webhook():
try:
if request.method == 'POST':
# Reply
data = request.get_json()
channel = data['channelId']
message_type = data['type']
sender = data['from']['name']
sender_id = data['from']['id']
message_format = data['textFormat']
message = data['text']
conversation_id = data['conversation']['id']
# Authenticate
security_token = b"sWYCgxib4hRcuHSKcKJk6w8FF6dVOa3mgmgK6thBMBg="
request_data = request.get_data()
digest = hmac.new(base64.b64decode(security_token), msg=request_data,
digestmod=hashlib.sha256).digest()
signature = base64.b64encode(digest).decode()
# Verify that HMAC header == signature
if request.headers.get('Authorization').split(' ')[1] == signature:
return jsonify({
"type": "message",
"text": "hi",
"attachments": [{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Present a form and submit it back to the originator"
},
{
"type": "Input.Text",
"id": "firstName",
"placeholder": "What is your first name?"
},
{
"type": "Input.Text",
"id": "lastName",
"placeholder": "What is your last name?"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "I clicked this button",
"text": "text to bots",
"value": "{\"bfKey\": \"bfVal\", \"conflictKey\": \"from value\"}"
}
}
}
]
}
}]
})
else:
print("hi")
except Exception as ex:
print(ex)
if __name__ == '__main__':
app.run(debug=True)
来源:https://stackoverflow.com/questions/61825279/python-not-getting-the-response-for-message-back-action-in-ms-teams-adaptive-ca