pzgram

A pz-way to create your Telegram Bot


Project maintained by infopz Hosted on GitHub Pages — Theme by mattgraham

Inline Keyboard

Telegram allows to create two types of keyboards: “normal” keyboards and inline keyboards.

To create and manage normal keyboard, you can visit this page

The inline keyboard are connected to a particular message, and when a user will press one of the buttons, a special type of message, called query, will be sent to the bot. Unlike the normal keyboard, the data that is inside a query can be different from the text that the user see in the button. Moreover, a button can open a website, in that case, the bot will not receive a query.

To create an inline keyboard, first of all, you have to create the buttons. To create a button, you have to use the pzgram.create_button function. It receives two parameters, the first it the text fo the button, the second must be one of the following parameters:

For example:

button1 = pzgram.create_button("Command1", data="com1")
button2 = pzgram.create_button("WebSite", url="www.website.com")

Once you have done this, you have to create and array of arrays of buttons. The smaller arrays rappresent a row of the keyboard, tha bigger one, rappresents the entire keyboard. To obtain the keyboard object, you have to pass the created array to the function pzgram.create_inline, this will return an object that you have to pass as reply_markup in methods like chat.send.

For example:

k = [[button1, button2]]
keyboard = pzgram.create_inline(k)
chat.send("Press a Button!", reply_markup=keyboard)

To manage the query genarated by the buttons, pzgram has 2 methods:

The first allows you to connect to a specific query data a function, creating a dictionary that has as keys the data as string, and as values the function to call. Then, you have to pass this dict to the function bot.set_query.

The second method consist of creating a function that will receive and manage all queries. To connect this function to the bot you have to set it as the bot’s attribute callBackFunc.

Each the functions can receive these parameters:

The two methods can be used at the same time, when a new query will arrive, pzgram will chek first of all if the value data of it is inside the dict, in case of a positive result the associated function will be called, otherwise the general function will be called

At this link you can find an example of how to use the inline keyboard with a simple PoolBot