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
updater (Optional[
bale.Updater
]) –
- 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
APIError – Get bot Failed.
- await delete_webhook()¶
This service is used to remove the webhook set for the bot.
- 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
- Returns
The Message
- Return type
- Raises
- 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
- Returns
The Message.
- Return type
- Raises
- 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
- Returns
The Message.
- Return type
- Raises
- 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 an 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
- Raises
- 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
- 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
- Raises
- 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=None, user_id=None)¶
- Parameters
- Returns
The chat member or
None
if not found.- Return type
Optional[
bale.ChatMember
]- Raises
- 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- Returns
list of chat member or
None
if chat not found.- Return type
Optional[List[
bale.ChatMember
]]- Raises
- 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_document
- asyncsend_invoice
- asyncsend_photo
- class bale.Chat¶
This object indicates a chat.
- _type¶
Chat Type.
- Type
- 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
- Raises
- await send_document(document, *, caption=None)¶
For the documentation of the arguments, please see
bale.Bot.send_photo()
.- Parameters
document (
bytes
|str
|bale.Document
) – Documentcaption (str) – Message caption.
- Returns
On success, the sent Message is returned.
- Return type
Optional[
bale.Message
]- Raises
- 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 (Optional[
str
]) – Message caption
- Returns
On success, the sent Message is returned.
- Return type
Optional[
bale.Message
]- Raises
- await send_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
- Raises
- await leave()¶
For the documentation of the arguments, please see
bale.Bot.leave_chat()
.
- 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
The chat member or
None
if not found.- Return type
Optional[
bale.ChatMember
]- Raises
- await get_chat_members_count()¶
For the documentation of the arguments, please see
bale.Bot.get_chat_members_count()
.
- await get_chat_administrators()¶
For the documentation of the arguments, please see
bale.Bot.get_chat_administrators()
.- Raises
- Returns
On success, The chat members is returned.
- Return type
Optional[List[
bale.ChatMember
]]
Chat Type¶
User¶
- asyncsend
- asyncsend_document
- asyncsend_invoice
- 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
- Raises
- 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
- Returns
On success, the sent Message is returned.
- Return type
- Raises
- 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 (Optional[
str
]) – Message caption
- Returns
On success, the sent Message is returned.
- Return type
- Raises
- await send_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
- Raises
ChatMember¶
MemberRole¶
Message¶
- asyncdelete
- asyncedit
- asyncreply
- asyncreply_document
- 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[
bale.Components
|bale.RemoveComponents
]) – Message Components.
- Returns
On success, the sent Message is returned.
- Return type
- Raises
- await reply_document(document, *, caption=None)¶
For the documentation of the arguments, please see
bale.Bot.send_document()
.- Parameters
document (
bytes
|str
|bale.Document
) – Documentcaption (Optional[
str
]) – Message caption
- Returns
The Message.
- Return type
- Raises
- await reply_photo(photo, *, caption=None)¶
For the documentation of the arguments, please see
bale.Bot.send_photo()
.- Parameters
photo (
bytes
|str
|bale.Photo
) – Photocaption (Optional[
str
]) – Message caption
- Returns
On success, the sent Message is returned.
- Return type
- Raises
- 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 an 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
- Raises
- await edit(text, *, 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
- await delete()¶
For the documentation of the arguments, please see
bale.Bot.delete_message()
.
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
]
Update Type¶
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(s).
Attachment Models¶
Audio¶
Contact Message¶
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
Exceptions¶
The following exceptions are thrown by the library.
- exception bale.BaleError(message)¶
Base exception class for python-bale-bot
- exception bale.InvalidToken(message)¶
An exception where the server says the Token is Invalid
- exception bale.APIError(error_code, message)¶
Exception that’s raised for when status code 400 occurs and Error is Unknown. Subclass of
BaleError
- exception bale.NetworkError(message)¶
Exception that’s raised when the connection is closed for reasons that could not be handled internally.
- exception bale.TimeOut¶
- exception bale.NotFound(message=None)¶
Exception that’s raised for when status code 404 occurs. Subclass of
BaleError
- exception bale.Forbidden¶
Exception that’s raised for when status code 403 occurs. Subclass of
BaleError
- exception bale.HTTPException(error)¶
Exception that’s raised when an HTTP request operation fails.