【问题标题】:How to retrieve Adaptive Card data on Microsoft Teams bot?如何在 Microsoft Teams bot 上检索自适应卡片数据?
【发布时间】:2021-10-14 17:41:31
【问题描述】:

我在 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 框中,我想获取该信息并将其发送回用户聊天。我如何做到这一点?

【问题讨论】:

标签: node.js botframework microsoft-teams


【解决方案1】:

这对我有用。所以不要使用

"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);
    }

上述功能确保我得到反馈,并将自适应卡更新到英雄卡中,这样我就可以阻止用户对反馈进行更多更新。

【讨论】:

    猜你喜欢
    • 2019-02-24
    • 2019-01-18
    • 2020-10-21
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 2020-05-30
    • 2020-12-09
    • 2021-09-18
    相关资源
    最近更新 更多