Ejemplo n.º 1
0
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            CallbackQuery cq = context.Update.CallbackQuery;

            _chatProcessor.CallBackMessageId = cq.Message.MessageId;

            ConsoleHelper.WriteLine(cq.ToJson());
            ConsoleHelper.WriteLine($"CallBackData: {cq.Data}");

            var partsCallback = cq.Data.SplitText(" ");

            ConsoleHelper.WriteLine($"Callbacks: {partsCallback.ToJson()}");

            switch (partsCallback[0]) // Level 0
            {
            case "help":
                var sendText = await partsCallback[1].LoadInBotDocs();
                ConsoleHelper.WriteLine($"Docs: {sendText}");
                var subPartsCallback = partsCallback[1].SplitText("/");

                ConsoleHelper.WriteLine($"SubParts: {subPartsCallback.ToJson()}");
                var jsonButton = partsCallback[1];

                if (subPartsCallback.Count > 1)
                {
                    jsonButton = subPartsCallback[0];

                    switch (subPartsCallback[1])
                    {
                    case "info":
                        jsonButton = subPartsCallback[1];
                        break;
                    }
                }

                var keyboard = await $"Storage/Buttons/{jsonButton}.json".JsonToButton();


                await _chatProcessor.EditMessageCallback(sendText, keyboard);

                // var a = new HelpCallbackQuery(cq);
                break;

            case "verification":
                break;
            }

            // await context.Bot.Client.AnswerCallbackQueryAsync(cq.Id, "PONG", true);

            await next(context);
        }
Ejemplo n.º 2
0
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            _telegramService = new TelegramService(context);
            CallbackQuery cq = context.Update.CallbackQuery;

            _telegramService.CallBackMessageId = cq.Message.MessageId;

            Log.Information("CallbackQuery" + cq.ToJson(true));
            // Log.Information($"CallBackData: {cq.Data}");

            var partsCallback = cq.Data.SplitText(" ");

            Log.Information($"Callbacks: {partsCallback.ToJson()}");

            switch (partsCallback[0]) // Level 0
            {
            case "action":
                var callbackResult = new ActionCallback(_telegramService);
                Log.Information($"ActionResult: {callbackResult.ToJson(true)}");
                break;

            case "help":
                var helpCallback = new HelpCallback(_telegramService);
                Log.Information($"HelpResult: {helpCallback.ToJson(true)}");
                break;

            case "setting":
                var settingsCallback = new SettingsCallback(_telegramService);
                Log.Information($"SettingsResult: {settingsCallback.ToJson(true)}");
                break;

            case "verify":
                var verifyCallback = new VerifyCallback(_telegramService);
                Log.Information($"VerifyResult: {verifyCallback.ToJson(true)}");
                break;
            }

            // await context.Bot.Client.AnswerCallbackQueryAsync(cq.Id, "PONG", true);

            await next(context, cancellationToken)
            .ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        public async Task ProcessCallbackQuery(ITelegramSender telegramSender, CallbackQuery callbackQuery)
        {
            await Log.WriteInfoAsync(nameof(ChatSubscriber), nameof(ProcessCallbackQuery), $"callbackQuery: {callbackQuery.ToJson()}",
                                     "Command received.");

            if (!await ValidateChat(callbackQuery.Message.Chat.Id, telegramSender))
            {
                await Log.WriteInfoAsync(nameof(ChatSubscriber), nameof(ProcessCallbackQuery), $"callbackQuery: {callbackQuery.ToJson()}",
                                         "Unrecognized chat.");

                return;
            }

            await ProcessCallbackQueryInternal(telegramSender, callbackQuery);
        }