TelegramBots / Telegram.Bot

.NET Client for Telegram Bot API
https://telegrambots.github.io/book
MIT License
3.22k stars 692 forks source link

Unable to send Custom Keyboard to channel #1262

Closed danijeljw-RPC closed 1 year ago

danijeljw-RPC commented 1 year ago

I found a bug to report

Please use the following template to ensure maintainers can reproduce the bug and solve it quickly.

Bug reports that do not follow this template will be kept closed because not-reproducible until the creator edits the post properly.

Steps to reproduce

Copied the code directly from the guide produced by this repository https://telegrambots.github.io/book/2/reply-markup.html. Tried to compile the application and it failed.

Actual code used instead of photo in Program.cs:

using System.Threading;
using Telegram.Bot;
using Telegram.Bot.Exceptions;
using Telegram.Bot.Polling;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;

namespace TgramBotTutorial;

class Program
{
    private static string API_KEY = "<INSERT_API_KEY>";
    private static long ChannelId = <REPLACE_WITH_CHANNEL_ID>;
    private static readonly TelegramBotClient botClient = new(API_KEY);

    static async Task Main(string[] args)
    {
        long chatId = ChannelId;
        CancellationToken cancellationToken = CancellationToken.None;

        ReplyKeyboardMarkup replyKeyboardMarkup = new(new[]
        {
            new KeyboardButton[] { "Help me", "Call me ☎️" },
        })
        {
            ResizeKeyboard = true
        };

        Message sentMessage = await botClient.SendTextMessageAsync(
            chatId: chatId,
            text: "Choose a response",
            replyMarkup: replyKeyboardMarkup,
            cancellationToken: cancellationToken);
    }
}

Expected behavior

The CLI tool would send a message to the channel like a normal message. The channel ID is correct, as I have been following steps from other areas of the guide with no problem. This is specifically targeting the Custom Keyboards. Inline Keyboards are compiling and running as expected.

Actual behavior

Click Run in Visual Studio and error happens when reaches the example code. Won't send message.

Error code: Telegram.Bot.Exceptions.ApiRequestException: "Bad Request: inline keyboard expected" at Telegram.Bot.TelegramBotClient.<MakeRequestAsync>d__211.MoveNext()\n at Telegram.Bot.TelegramBotClientExtensions.d7.MoveNext()\n at TgramBotTutorial.Program.

d3.MoveNext() in /Projects/TgramBotTutorial/Program.cs:30`

Screenshots

Screenshot 2023-05-21 at 14 34 06 Screenshot 2023-05-21 at 14 36 20

Environment data

NuGet Package Version: 19.0.0

.NET Version: 7.0.302

IDE: Visual Studio 2022 for Mac, Version 17.5.5 (build 12)

App: Compiled as a CLI application on macOS

danijeljw-RPC commented 1 year ago

It works outside the channel, and with direct message to user. Overlooked that. Closing ticket.