API Reference¶
Version Info¶
Bot¶
- defadd_event
- asyncclose
- asyncdelete_message
- asyncdelete_webhook
- asyncedit_message
- asyncget_bot
- asyncget_chat
- asyncget_chat_administrators
- asyncget_chat_member
- asyncget_chat_members_count
- asyncget_user
- asyncinvite_to_chat
- defis_closed
- asyncleave_chat
- deflisten
- asyncon_error
- defremove_event
- defrun
- asyncsend_document
- asyncsend_invoice
- asyncsend_message
- asyncsend_photo
- defwait_for
- class bale.Bot¶
This object represents a Bale Bot.
- Parameters
token (str) – Bot Token
- listen(event_name)¶
Register a Event
- add_event(event, function)¶
Register an Event with event name
- remove_event(event, function=None)¶
Register an Event with event name
- wait_for(event_name, *, check=None, timeout=None)¶
Wait for an event
- property user¶
Represents the connected client.
None
if not logged in
- await close()¶
Close http Events and bot
- await on_error(event_name, error)¶
a Event for get errors when exceptions
- await get_bot()¶
Get bot information
- Returns
Bot User information.
- Return type
Bale.User
- Raises
Bale.Error –
- await delete_webhook()¶
This service is used to remove the webhook set for the bot.
- Returns
True
elseFalse
if not done- Return type
- await send_message(chat, text, *, components=None, reply_to_message=None)¶
This service is used to send text messages.
- Parameters
text (
str
) – Message Textcomponents (Optional[
bale.Components
|bale.RemoveComponents
]) – Message Componentsreply_to_message (Optional[
bale.Message
]) – Reply to a Message
- Raises
bale.Error –
- Returns
The Message
- Return type
- await send_document(chat, document, *, caption=None, reply_to_message=None)¶
This service is used to send document.
- Parameters
document (
bytes
|str
|bale.Document
) – Documentcaption (Optional[
str
]) – Message captionreply_to_message (Optional[
bale.Message
]) – Reply to a Message
- Raises
bale.Error –
- Returns
The Message.
- Return type
- await send_photo(chat, photo, *, caption=None, reply_to_message=None)¶
This service is used to send photo.
- Parameters
photo (
bytes
|str
|bale.Photo
) – Photocaption (Optional[
str
]) – Message captionreply_to_message (Optional[
bale.Message
]) – Reply to a Message
- Raises
bale.Error –
- Returns
The Message.
- Return type
- await send_invoice(chat, title, description, provider_token, prices, *, photo_url=None, need_name=False, need_phone_number=False, need_email=False, need_shipping_address=False, is_flexible=True)¶
You can use this service to send money request messages.
- Parameters
title (str) – Invoice Title
description (str) – Invoice Description
provider_token (str) – You can use 3 methods to receive money: 1.Card number 2. Port number and acceptor number 3. Wallet number “Bale”
prices (List[
bale.Price
]) – A list of prices.photo_url (str) – Photo URL of Invoice. Defaults to None.
need_name (bool) – Get a name from “User”?. Defaults to False.
need_phone_number (bool) – Get a Phone number from “User”?. Defaults to False.
need_email (bool) – Get a Email from “User”?. Defaults to False.
need_shipping_address (bool) – Get a Shipping Address from “User”?. Defaults to False.
is_flexible (bool) – Is the Invoice Photo Flexible to the Payment button?. Defaults to True.
- Return type
- await edit_message(chat, message, text, *, components=None)¶
You can use this service to edit text messages that you have already sent through the arm.
- Parameters
chat (
bale.Chat
) – chatmessage (
bale.Message
) – messagetext (str) – new content for message.
components (Optional[
bale.Components
|bale.RemoveComponents
]) – message components
- Raises
bale.Error –
- Return type
- await delete_message(chat, message)¶
You can use this service to delete a message that you have already sent through the arm.
Warning
- In Channel or Group:
If it is a group or channel Manager, it can delete a message from (group or channel).
- In private message (PV):
If the message was sent by a bot, it can be deleted with this method
- Parameters
chat (
bale.Chat
) – chatmessage (
bale.Message
) – message
- Returns
True
if done elseFalse
- Return type
- await get_chat(chat_id)¶
This service can be used to receive personal information that has previously interacted with the arm.
- await get_user(user_id)¶
This Method almost like
bale.Bot.get_chat
, but this a filter that only get user.
- await get_chat_member(chat, user_id)¶
- Parameters
- Raises
bale.Error –
- Returns
The chat member or
None
if not found.- Return type
Optional[
bale.ChatMember
]
- await invite_to_chat(chat, user)¶
Invite user to the chat
- await leave_chat(chat)¶
Leave bot from a Chat
- await get_chat_members_count(chat)¶
- await get_chat_administrators(chat)¶
This service can be used to display admins of a group or channel.
- Parameters
chat (
bale.Chat
) – Group id- Raises
bale.Error –
- Returns
list of chat member or
None
if chat not found.- Return type
Optional[List[
bale.ChatMember
]]
- run(sleep_after_every_get_updates=None)¶
Run bot and https
Models¶
CallbackQuery¶
Chat¶
- asyncadd_user
- asyncget_chat_administrators
- asyncget_chat_member
- asyncget_chat_members_count
- asyncleave
- asyncsend
- asyncsend_photo
- class bale.Chat¶
This object indicates a chat.
- type¶
Chat Type.
- Type
bale.ChatType
- pinned_message¶
Pinned messages in chat. Defaults to None.
- Type
- all_members_are_administrators¶
Does everyone have admin access?. Defaults to True. (for Group)
- Type
- property type¶
Get chat type
- await send(text, components=None)¶
For the documentation of the arguments, please see
bale.Bot.send_message()
.- Parameters
text (str) – Message content
components (Optional[
bale.Components
|bale.RemoveComponents
]) – Message components
- Return type
- await send_photo(photo, caption=None)¶
For the documentation of the arguments, please see
bale.Bot.send_photo()
.- Parameters
photo (
bytes
|str
|bale.Photo
) – Photocaption (str) – Message caption.
- Raises
bale.Error –
- Returns
On success, the sent Message is returned.
- Return type
Optional[
bale.Message
]
- await leave()¶
For the documentation of the arguments, please see
bale.Bot.leave_chat()
.- Returns
- bool:
On success,
True
.
- await add_user(user)¶
For the documentation of the arguments, please see
bale.Bot.invite_to_chat()
.
- await get_chat_member(user)¶
For the documentation of the arguments, please see
bale.Bot.get_chat_member()
.- Parameters
user (
bale.User
) – User- Returns
On success, The chat member is retuened.
- Return type
Optional[
bale.ChatMember
]
- await get_chat_members_count()¶
For the documentation of the arguments, please see
bale.Bot.get_chat_members_count()
.- Returns
On success, The count of chat members is returned.
- Return type
Optional[
int
]
- await get_chat_administrators()¶
For the documentation of the arguments, please see
bale.Bot.get_chat_administrators()
.- Raises
bale.Error –
- Returns
On success, The chat members is returned.
- Return type
Optional[List[
bale.ChatMember
]]
User¶
- asyncsend
- asyncsend_document
- asyncsend_photo
- class bale.User¶
This object shows a user.
- await send(text, components=None)¶
For the documentation of the arguments, please see
bale.Bot.send_message()
.- Parameters
text (str) – Message Content
components (
bale.Components
|bale.RemoveComponents
) – Message Components
- Returns
On success, the sent Message is returned.
- Return type
- await send_document(document, caption=None)¶
For the documentation of the arguments, please see
bale.Bot.send_document()
.- Parameters
document (
bytes
|str
|bale.Document
) – Photocaption (
str
) – Message caption
- Raises
bale.Error –
- Returns
On success, the sent Message is returned.
- Return type
- await send_photo(photo, caption=None)¶
For the documentation of the arguments, please see
bale.Bot.send_photo()
.- Parameters
photo (
bytes
|str
|bale.Photo
) – Photocaption (
str
) – Message caption
- Raises
bale.Error –
- Returns
On success, the sent Message is returned.
- Return type
ChatMember¶
Message¶
- asyncdelete
- asyncedit
- asyncreply
- asyncreply_invoice
- asyncreply_photo
- class bale.Message¶
This object shows a message.
- date¶
When the message has been sent.
- Type
Message caption.
- Type
Optional[
str
]
- contact¶
Contact
- Type
Optional[
bale.ContactMessage
]
- reply_to_message¶
The message Replayed to who message.
- Type
Optional[
bale.Message
]
- invoice¶
Message invoice.
- Type
Optional[
bale.Invoice
]
- await reply(text, *, components=None)¶
For the documentation of the arguments, please see
bale.Bot.send_message()
.- Parameters
text (str) – Message Content.
components (Optional[
bot.Components
|bale.RemoveComponents
]) – Message Components.
- Raises
bale.Error –
- Returns
On success, the sent Message is returned.
- Return type
- await reply_photo(photo, caption=None)¶
For the documentation of the arguments, please see
bale.Bot.send_photo()
.- Parameters
- Raises
bale.Error –
- Returns
On success, the sent Message is returned.
- Return type
- await reply_invoice(title, description, provider_token, prices, photo_url=None, need_name=False, need_phone_number=False, need_email=False, need_shipping_address=False, is_flexible=True)¶
For the documentation of the arguments, please see
bale.Bot.send_invoice()
- Parameters
title (str) – Invoice Title
description (str) – Invoice Description
provider_token (str) –
Note
- You can use 3 methods to receive money:
Card number
Port number and acceptor number
Wallet number “Bale”
prices (List[
bale.Price
]) – A list of prices.photo_url (Optional[
str
]) – Photo URL of Invoice.need_name (Optional[
bool
]) – Get a name from “User”?need_phone_number (Optional[
bool
]) – Get a Phone number from “User”?.need_email (Optional[bool]) – Get a Email from “User”?.
need_shipping_address (Optional[bool]) – Get a Shipping Address from “User”?.
is_flexible (Optional[bool]) – Is the Invoice Photo Flexible to the Payment button?
- Returns
On success, the message sent returned.
- Return type
Bale.Message
- await edit(text=None, components=None)¶
For the documentation of the arguments, please see
bale.Bot.edit_message()
- Parameters
text (str) – New Content for message.
components (Optional[
bale.Components
|bale.RemoveComponents
]) – New Message Components for message.
- Raises
bale.Error –
- Return type
- await delete()¶
For the documentation of the arguments, please see
bale.Bot.delete_message()
.- Returns
True
when user added to chat elseFalse
- Return type
Update¶
- class bale.Update¶
This object shows an update.
- callback_query¶
Callback Query
- Type
Optional[
bale.CallbackQuery
]
- message¶
Message
- Type
Optional[
bale.Message
]
- edited_message¶
Edited Message
- Type
Optional[
bale.Message
]
Components¶
- class bale.Components¶
- Parameters
keyboards (List[
bale.Keyboard
]) – keyboardsinline_keyboards (List[
bale.InlineKeyboard
]) – inline keyboards
Inline Keyboard¶
- class bale.InlineKeyboard¶
This object shows an inline keyboard (within the message).
- callback_data¶
If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot’s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted. Defaults to None.
- Type
- switch_inline_query¶
If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot’s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted. Defaults to None.
- Type
Keyboard¶
Remove Components¶
- class bale.RemoveComponents¶
This object shows a remove keyboard.
Attachment Models¶
Audio¶
Contact Message¶
Document¶
- class bale.Document¶
This object shows a Document.
Photo¶
Location¶
Payment Models¶
Invoice¶
Price¶
Event Reference¶
Event Types¶
Note
You can use bale.EventType for Events.
from bale import Bale, EventType
bot = bale.Bot(token="Your Token")
@bot.listen(EventType.Update)
async def when_receive_update(update):
...
Update¶
- bale.on_update(update)¶
Called when a Update Sent.
- Parameters
update (
bale.Update
) – The update
Message¶
- bale.on_message(message)¶
Called when a Message Sent.
- Parameters
message (
bale.Message
) – The message
Callback¶
- bale.on_callback(callback)¶
Called when a Callback Sent.
- Parameters
callback (
bale.CallbackQuery
) – The callback