You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Node.js版Microsoft Bot Framework中获取Teams O365连接器卡片响应

嘿,我看你正在用Node.js版的Microsoft Bot Framework开发Teams机器人,还用到了O365连接器卡片~我帮你把这段代码整理得更规范,还补了一些必要的细节,让它能在Teams里正常工作:

const teams = require('botbuilder-teams'); // 记得先通过npm安装这个模块哦

// 假设session是当前的对话会话对象
let choice = "choice"; 
let cardAction2 = new teams.O365ConnectorCardActionCard(session)
    .id("cardAction-2")
    .name("Name of product")
    .inputs([
        // 多行文本输入框,用于用户填写问题描述
        new teams.O365ConnectorCardTextInput(session)
            .id("text-1")
            .title("Write your problem statement here....")
            .isMultiline(true),
        // 多选输入项,这里我补了示例选项,你可以根据需求修改
        new teams.O365ConnectorCardMultichoiceInput(session)
            .id("list-product-category")
            .title("Select a product category")
            .isMultiSelect(false) // 设为true就能允许多选
            .choices([
                { display: "Product A", value: "product-a" },
                { display: "Product B", value: "product-b" },
                { display: "Product C", value: "product-c" }
            ])
    ])
    // 给卡片添加提交按钮,指向你的后端接口
    .actions([
        new teams.O365ConnectorCardHttpPOST(session)
            .id("submit-feedback")
            .name("Submit")
            .target("https://your-api-domain.com/receive-feedback")
    ]);

// 组装完整的O365连接器卡片
const productFeedbackCard = new teams.O365ConnectorCard(session)
    .title("Product Feedback Form")
    .text("Feel free to share your thoughts or issues about our products below.")
    .summary("Submit product feedback")
    .themeColor("#0078D7") // 用Teams的默认主题色,视觉更协调
    .potentialAction([cardAction2]);

// 把卡片发送到Teams会话里
session.send(productFeedbackCard);

几个需要注意的点:

  • 先确认已经安装了botbuilder-teams模块:执行npm install botbuilder-teams
  • 多选输入项必须补充choices数组,不然用户看不到可选选项
  • 提交按钮的target要替换成你自己的后端接口,用来接收用户提交的数据
  • 输入项的id最好取有意义的名字,方便后续在后端处理时识别对应字段
  • 设置themeColor能让卡片和Teams的界面风格更统一

这样调整后,你的O365卡片就能在Teams里正常渲染,用户可以填写问题描述、选择产品类别,提交后数据会发送到你指定的接口啦~

内容的提问来源于stack exchange,提问作者chandra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:49:37