Welcome to EzTg’s documentation!

EzTg

EzTg package

Submodules

EzTg.inlinekeyboard module

class EzTg.inlinekeyboard.InlineKeyboard[source]

Bases: object

callback(text, callback_data)[source]

Add a new callback button to the keyboard.

Parameters
textstr

The text of the button

callback_datastr

The callback data of the button

callback_new_row(text, callback_data)[source]

Add a new callback button to the keyboard in a new row.

Parameters
textstr

The text of the button

callback_datastr

The callback data of the button

send()[source]

Return the keyboard.

url(text, url)[source]

Add a new url button to the keyboard.

Parameters
textstr

The text of the button

urlstr

The url of the button

url_new_row(text, url)[source]

Add a new url button to the keyboard in a new row.

Parameters
textstr

The text of the button

urlstr

The url of the button

EzTg.main module

class EzTg.main.Parse[source]

Bases: dict

class EzTg.main.TelegramClient(token)[source]

Bases: object

async copyMessage(chat_id, message_id, caption=None, disable_notification=False, reply_to_message_id=None, allow_sending_without_reply=False, reply_markup=None)[source]

Copy a message.

Parameters
chat_id: int

The chat id you want to forward the message to.

message_id: int

The message id you want to forward.

caption: str

The caption you want to send.

disable_notification: bool

Sends the message silently. Users will receive a notification with no sound.

reply_to_message_id: int

If the message is a reply, ID of the original message.

allow_sending_without_reply: bool

Pass True, if the message should be sent even if the specified replied-to message is not found.

reply_markup: InlineKeyboard.send

Additional interface options. Use the InlineKeyboard class to create a keyboard and use the send method to send it.

Create a chat invite link.

Parameters
chat_id: int

The chat id you want to make the invite link.

name: str

The name of the invite link.

expire_date: int

The expire date of the invite link.

member_limit: int

The member limit of the invite link.

creates_join_request: bool

Pass True, if the link should be created without a chat member limit.

async deleteMessage(chat_id, message_id)[source]

Delete a message.

Parameters
chat_id: int

The chat id you want to delete the message from.

message_id: int

The message id you want to delete.

async editMessageText(chat_id, message_id, text, inline_message_id=None, parse_mode='Markdown', entities=None, disable_web_page_preview=False, reply_markup=None)[source]

Edit a message.

Parameters
chat_id: int

The chat id you want to edit the message from.

message_id: int

The message id you want to edit.

text: str

The text you want to send.

inline_message_id: int

The inline message id you want to edit.

parse_mode: str

The parse mode you want to use.

entities: list

List of special entities that appear in message text, which can be specified instead of parse_mode.

disable_web_page_preview: bool

Disable link previews for links in this message.

reply_markup: InlineKeyboard.send

Additional interface options. Use the InlineKeyboard class to create a keyboard and use the send method to send it.

Export a chat invite link.

Parameters
chat_id: int

The chat id you want to make the invite link.

async forwardMessage(chat_id, from_chat_id, message_id, disable_notification=False)[source]

Foward a message.

Parameters
chat_id: int

The chat id you want to forward the message to.

from_chat_id: int

The chat id you want to forward the message from.

message_id: int

The message id you want to forward.

disable_notification: bool

Sends the message silently. Users will receive a notification with no sound.

async getMe()[source]

Get information about the bot.

async get_author_id(message)[source]

Get author id from message.

Parameters
message: dict

The message object.

async get_chat_id(message)[source]

Get chat id from message.

Parameters
message: dict

The message object.s

async leaveChat(chat_id)[source]

Leave a chat.

Parameters
chat_id: int

The chat id you want to leave.

async pinChatMessage(chat_id, message_id, disable_notification=False)[source]

Pin a message.

Parameters
chat_id: int

The chat id you want to pin the message.

message_id: int

The message id you want to pin.

disable_notification: bool

Sends the message silently. Users will receive a notification with no sound.

async send(method, **kwargs)[source]

Send a request to the telegram api.

Parameters
method: str

The method you want to use.

**kwargs: dict

The parameters you want to send to the method.

async sendMessage(chat_id, text, parse_mode='Markdown', disable_web_page_preview=False, disable_notification=False, reply_to_message_id=None, reply_markup=None)[source]

Send a message to a chat.

Parameters
chat_id: int

The chat id you want to send the message to.

text: str

The text you want to send.

parse_mode: str

The parse mode you want to use.

disable_web_page_preview: bool

Disable link previews for links in this message.

disable_notification: bool

Sends the message silently. Users will receive a notification with no sound.

reply_to_message_id: int

If the message is a reply, ID of the original message.

reply_markup: dict

Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

async setChatPhoto(chat_id, photo)[source]

Set the chat photo.

Parameters
chat_id: int

The chat id you want to set the photo.

photo: str

The photo you want to use.

async start_polling(callback, callback_query=None)[source]

Start polling for updates.

Parameters
callback: function

The function you want to call when a message is received.

callback_query: function

The function you want to call when a callback query is received.

async unpinChatMessage(chat_id, message_id)[source]

Unpin a message.

Parameters
chat_id: int

The chat id you want to unpin the message.

message_id: int

The message id you want to unpin.

exception EzTg.main.TokenError[source]

Bases: Exception

Module contents

InlineKeyboard Quick Start

Here is a quick example of how to use EzTg.InlineKeyboard:

from EzTg import TelegramClient, InlineKeyboard
import asyncio

bot = TelegramClient("TOKEN")

async def on_message(update):
    message = update.message
    if message.text == "/start":
        keyboard = InlineKeyboard()
        keyboard.url("Google", "https://google.com")
        keyboard.callback("Click me", "click1")
        keyboard.url_new_row("GitHub", "https://github.com")
        keyboard.callback_new_row("Click me", "click2")
        await bot.send_message(message.chat.id, "Hello World!", reply_markup=keyboard)

async def on_callback(update):
    callback = update.callback_query
    if callback.data == "click1":
        await bot.send("answerCallbackQuery", callback_query_id=callback.id, text="You clicked the first button!")
    elif callback.data == "click2":
        await bot.send("answerCallbackQuery", callback_query_id=callback.id, text="You clicked the second button!", show_alert=True)

async def main()
    await bot.start_polling(on_message, on_callback)

asyncio.run(main())

Quick Start

This is a quick start guide to get you started with EzTg.:

from EzTg import TelegramClient
import asyncio

bot = TelegramClient("TOKEN")

async def on_message(update):
   message = update.message
   if message.text == "/start":
      await bot.sendMessage(chat_id=message.chat.id, text="Hello World!")

async def main()
   await bot.start_polling(on_message)

if __name__ == "__main__":
   asyncio.run(main())

How to use the send method

Here is a little example of using the send method.:

from EzTg import TelegramClient
import asyncio

bot = TelegramClient("TOKEN")

async def on_message(update):
   message = update.message
   if message.text == "/start":
      await bot.send("sendMessage", chat_id=message.chat.id, text="Hello World!")

async def main()
   await bot.start_polling(on_message)

if __name__ == "__main__":
   asyncio.run(main())

Here the send method has been used tho send a message. You can use the send method for any method of the telegram api and can be useful for example if such method is not yet implemented in EzTg.

Indices and tables