B4J Question jtelegrambot -how make keyboard

behnam_tr

Active Member
Licensed User
Longtime User
hi

i want to to make keyboard with jtelegrambot
i want to have three button in one row
how can i do it

B4X:
Dim ib As KeyboardButtonBuilder
        ib.Initialize
        
        Dim mark As ReplyKeyboardMarkup
        mark.initialize(ib.newRow.newButton("test2").newRow.newButton("test3").newRow.build,True,False,False)
        Dim buttons As Message = jtb.sendMessage(jtb.byId(from.Id),"please select......","MARKDOWN",False,False,message.MessageId,mark)
        glmap.Put(buttons.MessageId,buttons)
 

DonManfred

Expert
Licensed User
Longtime User
i want to have three button in one row
why you are adding a new row after each button?
B4X:
        Dim ibld As InlineKeyboardButtonBuilder
        Dim mark As InlineKeyboardMarkup
        mark.initialize(ibld.Initialize.newRow.newButton("1").withCallbackData("BTN1").newButton("2").withCallbackData("BTN2").newButton("3").withCallbackData("BTN3").newRow.newButton("Google").withUrl("https://www.google.com").newRow.build)
        Dim buttons As Message = jtb.sendMessage(jtb.byId(from.Id),"Click the Button!","MARKDOWN",False,False,message.MessageId,mark)
 
Upvote 0

behnam_tr

Active Member
Licensed User
Longtime User
i want to make keyboard menu not inline keyboard
in "ReplyKeyboardMarkup" after add "newbutton" dosen't newbutton method
i should add newrow then can use newbutton again
i want to have 2or3 button in one row

plz check attached image
thanks
 

Attachments

  • Untitled22222222.png
    Untitled22222222.png
    12.7 KB · Views: 237
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
in "ReplyKeyboardMarkup" after add "newbutton" dosen't newbutton method
when you add a button you then need to set data which is send to the bot when the user presses the button.
after you set the data you can add another button.
i want to make keyboard menu not inline keyboard
i´m not sure that i understand correctly.

Can you post a Picture of what exactly you want to archieve? Maybe a link to the Telegram-Documentationpage of the Feature you want.
 
Last edited:
Upvote 0

behnam_tr

Active Member
Licensed User
Longtime User
when you add a button you then need to set data which is send to the bot when the user presses the button.
after you set the data you can add another button.

i´m not sure that i understand correctly.

Can you post a Picture of what exactly you want to archieve? Maybe a link to the Telegram-Documentationpage of the Feature you want.


"KeyboardButtonBuilder" dont have setcallbackdata
setcallback only is in the inlinekeyboardbuilder

sorry for my bad english!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
v0.18 now has a changed ReplyKeyboardMarkup.
It now has a Initialisation for the Buttonsrows... You first init and say how many rows and columns you want to have.
then you set all the buttons one by one
and then you use the Keyboard for the answer.

Code something like

B4X:
        else If message.Text = "/replykeyboard" Then
            Log("ReplyKeyboard requested")
            Dim kmark As ReplyKeyboardMarkup
            kmark.initkeyboard(1,3)
            kmark.SetButton(0,0,"BTN0-0")
            kmark.SetButton(0,1,"BTN0-1")
            kmark.SetButton(0,2,"BTN0-2")
            kmark.SetButton(1,0,"BTN1-0")
            kmark.SetButton(1,1,"BTN1-1")
            kmark.SetButton(1,2,"BTN1-2")
            
            kmark.initialize(kmark.GetKeyboard,True,True,True)
            Dim buttons As Message = jtb.sendMessage(jtb.byId(from.Id),"Yo man","MARKDOWN",False,False,message.MessageId,kmark)

it results in

telegrambot089.png


After i press one of the buttons

telegrambot090.png


Isit this what you are searching?
 
Upvote 0

Ilya G.

Active Member
Licensed User
Longtime User
Hi DonManfred, help why this code does not display the keyboard?

B4X:
Private ibld As InlineKeyboardButtonBuilder, imark As InlineKeyboardMarkup

'does not work
ibld.Initialize
Do While Cursor.NextRow
    ibld.newRow.newButton(Cursor.GetString("ip")).withCallbackData(Cursor.GetString("ip"))
Loop
imark.initialize(ibld.newRow.build)
JTB.sendMessage(JTB.byId(from.Id), "Выберите хост:", "MARKDOWN", False, False, Null, imark)

' this work
imark.initialize(ibld.Initialize.newRow.newButton("1").withCallbackData("8.8.8.8").newRow.newButton("2").withCallbackData("2").newRow.build)
JTB.sendMessage(JTB.byId(from.Id), "Выберите хост:", "MARKDOWN", False, False, Null, imark)
 
Last edited:
Upvote 0
Top