使用 MS Bot Framework 在 TelegramBot 中自定义键盘

Custom keyboard in TelegramBot using MS Bot Framework

据我所知,我可以使用 Actions (http://blog.botframework.com/2016/05/13/BotFramework.buttons/) 在 Telegram 和其他消息中创建内联键盘。 但是自定义键盘 (https://core.telegram.org/bots#keyboards) 呢?我如何使用 Bot Framework 添加它们?

我阅读了有关 ChannelData (http://docs.botframework.com/connector/custom-channeldata/#custom-telegram-messages) 的信息,但我没有明白,如何将 JSON 传递给 CreateReplyMessage 方法。

使用 CreateReplyMessage 创建消息对象:

var replyMessage =  incomingMessage.CreateReplyMessage("Yo, I heard you.");

然后设置ChannelData

replyMessage.ChannelData = {custom Telegram JSON}

对于 Bot Framework v4:

{
    var reply = context.Context.Activity.CreateReply(messageText);

    if (BotDialogHelpers.ExtractMessengerFromDialogContext(context) == BotDialogHelpers.Messengers.Telegram)
    {
        GenerateReplyMarkupForTelegram(reply);
    }

    await context.Context.SendActivityAsync(reply, token);
}

/// <summary>
/// https://docs.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-channeldata?view=azure-bot-service-3.0
/// https://core.telegram.org/bots/api#message sendMessage reply_markup
/// </summary>
private void GenerateReplyMarkupForTelegram(IActivity reply)
{
    var replyMarkup = new
    {
        reply_markup = new
        {
            remove_keyboard = true,
        }
    };

    var channelData = new
    {
        method = "sendMessage",
        parameters = replyMarkup,
    };

    reply.ChannelData = JObject.FromObject(channelData);
}