Code Monkey home page Code Monkey logo

Comments (5)

MajMcCloud avatar MajMcCloud commented on June 15, 2024

Which kind of keyboard are you using ? The answer depends on it. If using the ButtonGrid control it does manage everything for you.

from telegrambotframework.

bretbas avatar bretbas commented on June 15, 2024

But i want to handle this pressing in the Action method. How can i to do that?

from telegrambotframework.

MajMcCloud avatar MajMcCloud commented on June 15, 2024

Which kind of Keyboard are you using ? The Reply one or the Inline one? You have to use the InlineReplyKeboard to get the Action method invoked. Check Readme and Telegram documentaion.

from telegrambotframework.

bretbas avatar bretbas commented on June 15, 2024

Ok, but i need Reply keyboard.
I try this:

public class StartForm : AutoCleanForm
{
    public StartForm()
    {
        Init += OnInit;
    }

    private async Task OnInit(object sender, InitEventArgs ev)
    {
        var btn = new ButtonForm();
        btn.AddButtonRow(new ButtonBase(KeyboardButtons.SearchTrips, Commands.SearchTrips));
        btn.AddButtonRow(new ButtonBase(KeyboardButtons.SetFilters, Commands.SetFilters));
        btn.AddButtonRow(new ButtonBase(KeyboardButtons.CreateTrip, Commands.CreateTrip));

        var grid = new ButtonGrid(btn)
        {
            KeyboardType = TelegramBotBase.Enums.eKeyboardType.ReplyKeyboard,
            Enabled = true,
            HideKeyboardOnCleanup = true,
            ResizeKeyboard = true
        };

        grid.ButtonClicked += async (s, e) =>
        {
            FormBase form = e.Button.Value switch
            {
                Commands.SearchTrips => new SearchTripsForm(),
                Commands.SetFilters => new SetFiltersForm(),
                Commands.CreateTrip => new CreateTripForm()
            };
            await NavigateTo(form);
        };

        AddControl(grid);
    }
}
  1. Is it a good practice?
  2. Where is it better to unsubscribe from ButtonClicked or is it not needed?

from telegrambotframework.

MajMcCloud avatar MajMcCloud commented on June 15, 2024

The main reason, why it didnt worked in the first place was that ReplyKeyboard does only send "Text" back. So like a normal chat message. Thats why the Action method did not get invoked.

  1. I would say that looks fine.
  2. You dont have to, but you can add it to OnClosed event so i gets unsubscribed when navigated somewhere else

from telegrambotframework.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.