|
| 1 | +from typing import Optional |
| 2 | +from telegrambots.wrapper.client import TelegramBotsClient |
| 3 | +from telegrambots.wrapper.types.methods import SendMessage |
| 4 | +from telegrambots.wrapper.types.objects import ( |
| 5 | + MessageEntity, |
| 6 | + InlineKeyboardMarkup, |
| 7 | + ReplyKeyboardMarkup, |
| 8 | + ReplyKeyboardRemove, |
| 9 | + ForceReply, |
| 10 | +) |
| 11 | + |
| 12 | + |
| 13 | +class CustomTelegramBotsClient(TelegramBotsClient): |
| 14 | + def __init__(self, token: str): |
| 15 | + super().__init__(token) |
| 16 | + |
| 17 | + async def send_message( |
| 18 | + self, |
| 19 | + chat_id: int, |
| 20 | + text: str, |
| 21 | + parse_mode: Optional[str] = None, |
| 22 | + entities: Optional[list[MessageEntity]] = None, |
| 23 | + disable_web_page_preview: Optional[bool] = None, |
| 24 | + disable_notification: Optional[bool] = None, |
| 25 | + protect_content: Optional[bool] = None, |
| 26 | + reply_to_message_id: Optional[int] = None, |
| 27 | + allow_sending_without_reply: Optional[bool] = None, |
| 28 | + reply_markup: Optional[ |
| 29 | + InlineKeyboardMarkup |
| 30 | + | ReplyKeyboardMarkup |
| 31 | + | ReplyKeyboardRemove |
| 32 | + | ForceReply |
| 33 | + ] = None, |
| 34 | + ): |
| 35 | + """Send text message to chat. |
| 36 | +
|
| 37 | + Args: |
| 38 | + chat_id (`int`): Unique identifier for the target chat or username of the target channel |
| 39 | + text (`str`): Text of the message to be sent |
| 40 | + parse_mode (`Optional[str]`, optional): Send Markdown or HTML, if you want Telegram apps to show bold, |
| 41 | + italic, fixed-width text or inline URLs in your bot's message. |
| 42 | + entities (`Optional[list[MessageEntity]`], optional): List of special entities that appear in message text, |
| 43 | + which can be specified instead of parse_mode. |
| 44 | + disable_web_page_preview (`Optional[bool]`, optional): Disables link previews for links in this message. |
| 45 | + disable_notification (`Optional[bool]`, optional): Sends the message silently. |
| 46 | + protect_content (`Optional[bool]`, optional): If True, the message content will be protected. |
| 47 | + reply_to_message_id (`Optional[int]`, optional): reply to message id. |
| 48 | + allow_sending_without_reply (`Optional[bool]`, optional): If True, the message will be sent anyway. |
| 49 | + reply_markup (`Optional[ InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply ]`, optional): |
| 50 | + Additional interface options. An object for an inline keyboard, custom reply keyboard, ... |
| 51 | +
|
| 52 | + Returns: |
| 53 | + `Message`: On success, the sent message is returned. |
| 54 | + """ |
| 55 | + |
| 56 | + return await self( |
| 57 | + SendMessage( |
| 58 | + chat_id=chat_id, |
| 59 | + text=text, |
| 60 | + parse_mode=parse_mode, |
| 61 | + entities=entities, |
| 62 | + disable_web_page_preview=disable_web_page_preview, |
| 63 | + disable_notification=disable_notification, |
| 64 | + protect_content=protect_content, |
| 65 | + reply_to_message_id=reply_to_message_id, |
| 66 | + allow_sending_without_reply=allow_sending_without_reply, |
| 67 | + reply_markup=reply_markup, |
| 68 | + ) |
| 69 | + ) |
0 commit comments