首页 > 解决方案 > 使用 sourceEvent 在 bot 框架模拟器中显示按钮

问题描述

我不想使用builder.Prompts.choice,因为我想允许用户键入答案,而不仅仅是单击按钮。所以我使用 sourceEvent,与 facebook messenger 配合得很好,但我知道我没有能力在模拟器中测试我的机器人,因为按钮没有出现。

replyMessage.sourceEvent({
    facebook: {
        quick_replies: [
            {
                "content_type": "text",
                "title": "Money Management",
                "payload": "Money Management"
            },
            {
                "content_type": "text",
                "title": "Retirement Plans",
                "payload": "Retirement Plans"
            }
        ]
    },
});

如何在模拟器中显示带有 sourceEvent 的按钮?

标签: botframework

解决方案


在此处输入图像描述好的屏幕截图我们看到按钮作为附件进入机器人模拟器。

let replyMessage = new builder.Message(session).text("hi");
replyMessage.addAttachment(
            {
                "contentType": "application/vnd.microsoft.card.hero",
                "content": {
                    "buttons": [ {"type": "postBack", "title": "Your title", "value": "your value"} ]
                }
            }
        );

推荐阅读