1
Answer

have problem

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

class Program
{

    private static TelegramBotClient botClient;

    static async Task Main(string[] args)
    {
        string token = "

";  // Tokeningizni kiriting
        botClient = new TelegramBotClient(token);

        using var cts = new CancellationTokenSource();
        var cancellationToken = cts.Token;

        var receiverOptions = new ReceiverOptions
        {
            AllowedUpdates = new[] { UpdateType.Message }  // faqat "message" update'larini oladi
        };

        botClient.StartReceiving(
            HandleUpdateAsync,
            HandleErrorAsync,
            receiverOptions,
            cancellationToken
        );

        var me = await botClient.GetMeAsync();  // Bot ma'lumotlarini olish
        Console.WriteLine($"Bot ishlayapti: @{me.Username}");

        Console.ReadLine();
        cts.Cancel();  // Ishga tushirishdan so'ng chiqish
    }

    private static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
    {
        if (update.Type != UpdateType.Message || update.Message?.Text == null)
            return;

        var message = update.Message;
        Console.WriteLine($"Yangi xabar: {message.Text}");

        if (update.Message.Text.ToLower() == "/start")
        {
            await botClient.SendTextMessageAsync(chatId: update.Message.Chat.Id, text: "???? ???", replyMarkup: new ForceReplyMarkup { Selective = true });
            return;
        }
        if (update.Message.ReplyToMessage != null && message.ReplyToMessage.Text.Contains("???? ???"))
        {
            //??????????? ????-???? ????????? ???
            await botClient.SendTextMessageAsync(chatId: update.Message.Chat.Id, text: "??????? ??? ???", replyMarkup: new ForceReplyMarkup { Selective = true });
            return;
        }
        if (update.Message.ReplyToMessage != null && message.ReplyToMessage.Text.Contains("??????? ??? ???"))
        {
            //???? ?????????? ?????????
        }
    }

    private static Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)
    {
        Console.WriteLine($"Xatolik yuz berdi: {exception.Message}");
        return Task.CompletedTask;
    }
}
  i have problem this code
 

Answers (1)