如何在Facebook Messenger上使用MS Bot Framework创建快速回复?

Ale*_*der 1 facebook node.js facebook-messenger botframework

我已经有相当一段时间使用了Node.js和MS Bot Framework(3.0)来满足我的机器人开发需求。

我的需求之一是要求用户与机器人共享其电子邮件地址。
Facebook 为此提供了一个快速答复 API。

我很难理解如何使用该框架通过快速回复选项创建自定义消息。

我的第一个尝试是使用自定义渠道数据将本机元数据传递到渠道,
我已经成功实现了Messenger平台支持的各种模板,但是与按钮,列表和其他模板相比,快速答复是种其他野兽。目前,我努力使用框架提供的工具来创建快速回复消息

请指出正确的方向。

tdu*_*ord 5

您可以通过BotFramework V3中的源数据或通过框架V4中的通道数据发送Facebook快速答复。请参阅下面的两个示例:

节点

V4

await turnContext.sendActivity({
    text: 'What is your email?',
    channelData: {
        "quick_replies":[
            {
                "content_type": "user_email"
            }
        ]
    }
});
Run Code Online (Sandbox Code Playgroud)

V3

var message = new botbuilder.Message(session)
   .text('What is your email?')
   .sourceEvent({
      facebook: {
         "quick_replies":[
            {
               "content_type": "user_email"
            }
         ]
      }
   });

session.send(message);
Run Code Online (Sandbox Code Playgroud)

尖锐的

V4

Activity reply = turnContext.Activity.CreateReply();
reply.Text = "What is your location?";
reply.ChannelData = JObject.FromObject( new {
    quick_replies = new object[]
    {
        new
        {
            content_type = "location",
        },
    },
});

await turnContext.SendActivityAsync(reply, cancellationToken);
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!