如何在 Microsoft Teams 机器人上检索自适应卡片数据?

How to retrieve Adaptive Card data on Microsoft Teams bot?

我有一个使用 Microsoft Teams 上的 Microsoft Bot Framework 创建的机器人。对话结束后,我使用以下自适应卡片询问用户反馈:

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.3",
    "msteams": {
        "width": "Full"
    },
    "body": [
    {
        "type": "Container",
        "items": [
        {
            "type": "Container",
            "items": [
            {
                "type": "TextBlock",
                "text": "Feedback",
                "horizontalAlignment": "center",
                "weight": "bolder",
                "size": "large",
                "isSubtle": true,
                "color": "accent"
            },
            {
                "type": "TextBlock",
                "text": "What would you like to share with us?",
                "horizontalAlignment": "center",
                "weight": "bolder",
                "isSubtle": true
            },
            {
                "type": "ColumnSet",
                "columns": [
                {
                    "type": "Column",
                    "items": [
                    {
                        "type": "ActionSet",
                        "actions": [{
                            "type": "Action.ToggleVisibility",
                            "title": "Question",
                            "targetElements": [
                            {  
                                "elementId" : "Question",
                                "isVisible": true
                            },
                            {  
                                "elementId" : "Suggestion",
                                "isVisible": false 
                            },
                            {  
                                "elementId" : "Comments",
                                "isVisible": false 
                            }] 
                        }]
                    }]
                },
                {
                    "type": "Column",
                    "items": [
                    {
                        "type": "ActionSet",
                        "actions": [{
                            "type": "Action.ToggleVisibility",
                            "title": "Suggestion",
                            "targetElements": [
                            {  
                                "elementId" : "Question",
                                "isVisible": false
                            },
                            {  
                                "elementId" : "Suggestion",
                                "isVisible": true 
                            },
                            {  
                                "elementId" : "Comments",
                                "isVisible": false 
                            }] 
                        }]
                    }]
                },
                {
                    "type": "Column",
                    "items": [
                    {
                        "type": "ActionSet",
                        "actions": [{
                            "type": "Action.ToggleVisibility",
                            "title": "Comments",
                            "targetElements": [
                            {  
                                "elementId" : "Question",
                                "isVisible": false
                            },
                            {  
                                "elementId" : "Suggestion",
                                "isVisible": false 
                            },
                            {  
                                "elementId" : "Comments",
                                "isVisible": true 
                            }] 
                        }]
                    }]
                }]
            },
            {
                "type": "Input.Text",
                "id": "Question",
                "placeholder": "Enter Your Question...",
                "maxLength": 500,
                "isMultiline": true,
                "isVisible": true
            },
            {
                "type": "Input.Text",
                "id": "Suggestion",
                "placeholder": "Give Your Suggestion...",
                "maxLength": 500,
                "isMultiline": true,
                "isVisible": false
            },
            {
                "type": "Input.Text",
                "id": "Comments",
                "placeholder": "Give Your Feedback...",
                "maxLength": 500,
                "isMultiline": true,
                "isVisible": false
            },
            {
                "type": "ActionSet",
                "actions": [{
                    "type": "Action.Submit",
                    "title": "Submit Feedback",
                    "data": {
                        "msteams": {
                            "type": "imBack",
                            "value": "Feedback Submitted."
                        }
                    },
                    "style": "positive"
                }]
            }]
        }]
    }]
}

因此,一旦用户选择 QuestionSuggestionComments 三个选项中的任何一个并在 Input.Text 框中添加反馈,我想得到该信息并将其发送回聊天中的用户。我该如何实现?

这对我有用。所以不用

"data": {
    "msteams": {
        "type": "imBack",
        "value": "Feedback Submitted."
     }
},

在自适应卡片动作中,我只是将其保留为

"actions": [{
    "type": "Action.Submit",
    "title": "Submit Feedback",
}]

在此之后我在对话框中添加了一个函数作为

async getFeedBack(stepContext) {
        let authHeaders = stepContext.options;
        if(stepContext.context.activity.value) {
            let feedBackData = stepContext.context.activity.value;
            feedBackData['Question'] = feedBackData['Question'] ? feedBackData['Question'] : ' ';
            feedBackData['Suggestion'] = feedBackData['Suggestion'] ? feedBackData['Suggestion'] : ' ';
            feedBackData['Comments'] = feedBackData['Comments'] ? feedBackData['Comments'] : ' ';
            const card = CardFactory.heroCard(
                'Your Feedback',
                '<b>Question:</b> ' + feedBackData['Question'] + '<br>' + '<b>Suggestion:</b> ' + feedBackData['Suggestion'] + '<br>' + '<b>Comments:</b> ' + feedBackData['Comments'],
                null
            );
            card.id = stepContext.context.activity.replyToId;
            const message = MessageFactory.attachment(card);
            message.id = stepContext.context.activity.replyToId;
            await stepContext.context.updateActivity(message);
            await stepContext.context.sendActivity({ type: ActivityTypes.Typing });
            await stepContext.context.sendActivity("Thank You for your feedback.");
        }
        return await stepContext.endDialog(authHeaders);
    }

以上功能确保我获得反馈并将自适应卡片更新为英雄卡片,这样我就可以阻止用户对反馈进行任何更新。