如何实现Power Automate自适应投票卡片的存储与结果展示?
解决Power Automate Teams自适应投票卡片提交无响应及完整投票功能实现
问题原因
你当前的自适应卡片仅包含提交按钮,但未配置Power Automate的后续触发与数据处理逻辑,导致点击提交后无任何响应。要实现完整投票功能,需分三步配置:处理提交数据存储、修改卡片添加结果查看入口、实现结果统计与展示。
步骤1:配置Power Automate处理投票提交
1.1 创建云流与触发器
- 新建Power Automate云流,选择当用户提交自适应卡片时触发器,关联目标Teams频道。
- 若需主动发送卡片,可添加发送自适应卡片到Teams频道动作,将修改后的卡片代码填入(见步骤2)。
1.2 存储投票数据
推荐用SharePoint列表存储数据,先创建列表并添加字段:
- 用户名(单行文本)
- 投票选项(单行文本)
- 提交时间(日期时间)
在云流中添加创建项动作:
- 选择目标SharePoint站点与列表
- 映射字段:
- 用户名:
提交者显示名称(触发器输出) - 投票选项:
acPollChoices(卡片中选项的ID) - 提交时间:
utcNow()(当前时间表达式)
- 用户名:
1.3 提交确认反馈
添加发送自适应卡片回复动作,给提交用户发送确认消息,示例内容:
{ "type": "AdaptiveCard", "version": "1.0", "body": [{"type": "TextBlock", "text": "你的投票已提交:@{triggerBody()['data']['acPollChoices']}"}] }
步骤2:修改自适应卡片添加结果查看按钮
更新卡片代码,添加“查看结果”按钮,并通过data字段区分提交/查看动作:
{ "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.0", "body": [ { "type": "TextBlock", "text": "XXX的双周聚餐!🤤 🍜 ", "weight": "Bolder", "size": "ExtraLarge", "spacing": "None", "id": "acHeader" }, { "type": "TextBlock", "weight": "Bolder", "size": "Large", "text": "周四回顾会后你会参加聚餐/小酌吗?", "id": "acInstructions", "wrap": true }, { "type": "Input.ChoiceSet", "placeholder": "请选择", "choices": [ { "title": "是", "value": "yes" }, { "title": "否", "value": "no" }, { "title": "可能吧,不确定", "value": "maybe" } ], "id": "acPollChoices", "style": "expanded" } ], "actions": [ { "type": "Action.Submit", "title": "提交", "id": "btnSubmit", "data": {"action": "submitVote"} }, { "type": "Action.Submit", "title": "查看结果", "id": "btnViewResults", "data": {"action": "viewResults"} } ] }
步骤3:实现投票结果统计与展示
在云流中添加条件动作,判断触发动作类型:
- 条件:
triggerBody()['data']['action']等于submitVote→ 执行步骤1.2-1.3的提交逻辑 - 条件:
triggerBody()['data']['action']等于viewResults→ 执行结果统计逻辑
结果统计与回复
- 添加获取项目动作,获取SharePoint列表中所有投票数据
- 用表达式统计各选项票数:
- 是:
length(filter(body('获取项目'), equals(item()?['投票选项'], 'yes'))) - 否:
length(filter(body('获取项目'), equals(item()?['投票选项'], 'no'))) - 可能吧:
length(filter(body('获取项目'), equals(item()?['投票选项'], 'maybe')))
- 是:
- 添加发送自适应卡片回复动作,展示统计结果:
{ "type": "AdaptiveCard", "version": "1.0", "body": [ { "type": "TextBlock", "text": "聚餐投票结果", "size": "Large", "weight": "Bolder" }, { "type": "TextBlock", "text": "是:@{length(filter(body('获取项目'), equals(item()?['投票选项'], 'yes')))} 票", "size": "Medium" }, { "type": "TextBlock", "text": "否:@{length(filter(body('获取项目'), equals(item()?['投票选项'], 'no')))} 票", "size": "Medium" }, { "type": "TextBlock", "text": "可能吧:@{length(filter(body('获取项目'), equals(item()?['投票选项'], 'maybe')))} 票", "size": "Medium" } ] }
注意事项
- 确保SharePoint列表字段名称与云流中映射的字段完全一致
- 测试时先发送卡片到频道,提交投票后检查列表是否存入数据,再点击查看结果验证反馈
内容的提问来源于stack exchange,提问作者Phi Tiet
相关产品推荐
相关产品推荐

