zlapi: Zalo API for Python
Project description
zlapi
- Zalo API (Unofficial) for Python
Language
- Sẽ hỗ trợ tài liệu Tiếng Việt sớm nhất có thể. Sài tạm google dịch nhé :)
What is zlapi
?
A powerful and efficient library to interact with Zalo Website. This is not an official API, Zalo has that over here for chat bots. This library differs by using a normal Zalo account instead (More flexible).
zlapi
currently support:
- Custom style for message.
- Sending many types of messages, with files, stickers, mentions, etc.
- Fetching messages, threads and users info.
- Creating groups, setting the group, creating polls, etc.
- Listening for, an reacting to messages and other events in real-time.
- And there are many other things.
async
/await
(Updated).
Essentially, everything you need to make an amazing Zalo Bot!
Caveats
zlapi
works by imitating what the browser does, and thereby tricking Zalo into thinking it's accessing the website normally.
However, there's a catch! Using this library may not comply with Zalo's Terms Of Service, so be! We are not responsible if your account gets banned or disabled!
What's New?
This is an updated version for zlapi
to improve features and fix bugs (v1.0.3)
Improvements
- Change function replyMessage
Bugfixes
-
Fixed not getting response from server when listening.
-
Fixed the error of login function, not requiring account & password when using cookies.
Deprecations
- The old login server has been removed due to lack of funds to maintain the server.
Installation
pip install zlapi
If you don't have pip, this guide can guide you through the process.
You can also install directly from source, provided you have pip>=19.0
:
pip install git+https://github.com/Its-VrxxDev/zlapi.git
How to get IMEI and Cookies?
Download Extension
- Click Here to download the extension support getting IMEI & Cookies more conveniently.
Extension Usage Tutorial
- Enable the extension downloaded above.
- Go to https://chat.zalo.me, Sign in to your account.
- After successfully logging in, go back to extension and get IMEI, Cookies.
[!TIP] If you have opened the website
chat.zalo.me
but the extension does not have IMEI & Cookies, please clickRefresh Page
.
Windows
Android
- Use
kiwibrowser
instead ofchrome
to be able to use the extension.- If you are redirect when accessing
https://chat.zalo.me
. Watch this video
Basic Usage
Login Account Using Cookies
Normal
/Async
code style
# > Normal
# from zlapi import ZaloAPI
# > Async
# from zlapi.Async import ZaloAPI
from zlapi import ZaloAPI
from zlapi.models import *
imei = "<imei>"
cookies = {} # Cookies Dict
bot = ZaloAPI("<phone>", "<password>", imei=imei, session_cookies=cookies)
Simple
code style
from zlapi.simple import ZaloAPI
from zlapi.models import *
imei = "<imei>"
cookies = {} # Cookies Dict
bot = ZaloAPI("</>", "</>", imei, cookies, prefix="<your bot prefix>")
Listen Message, Event, ...
- You can enable thread mode for On Message function (work with
requests
type) withthread=True
.
bot.listen(thread=True)
- You can customize the reconnect time when listening is interrupted using
reconnect=...
.
bot.listen(reconnect=5)
Normal
/Async
code style
# > Normal
# from zlapi import ZaloAPI
# > Async
# from zlapi.Async import ZaloAPI
from zlapi import ZaloAPI
from zlapi.models import *
imei = "<imei>"
cookies = {} # Cookies Dict
bot = ZaloAPI("<phone>", "<password>", imei=imei, session_cookies=cookies)
# client.listen(type="...")
bot.listen()
Simple
code style
from zlapi.simple import ZaloAPI
from zlapi.models import *
imei = "<imei>"
cookies = {} # Cookies Dict
bot = ZaloAPI("</>", "</>", imei, cookies, prefix="<your bot prefix>")
bot.listen()
Custom On Message Function
onMessage
function will be called when receiving a message from listen
function. So we can handle that message here.
Normal
code style
from zlapi import ZaloAPI
from zlapi.models import *
imei = "<imei>"
cookies = {} # Cookies Dict
class CustomBot(ZaloAPI):
def onMessage(self, mid, author_id, message, message_object, thread_id, thread_type):
# Handle Message Here
pass
bot = CustomBot("<phone>", "<password>", imei=imei, session_cookies=cookies)
bot.listen()
Async
code style
from zlapi.Async import ZaloAPI
from zlapi.models import *
imei = "<imei>"
cookies = {} # Cookies Dict
class CustomBot(ZaloAPI):
async def onMessage(self, mid, author_id, message, message_object, thread_id, thread_type):
# Handle Message Here
pass
bot = CustomBot("<phone>", "<password>", imei=imei, session_cookies=cookies)
bot.listen()
Simple
code style
from zlapi.simple import ZaloAPI
from zlapi.models import *
imei = "<imei>"
cookies = {} # Cookies Dict
bot = ZaloAPI("</>", "</>", imei, cookies, prefix="<bot prefix>")
@bot.event
async def on_message(ctx):
# Handle Message Here
pass
bot.listen()
Example Handle Message
Normal code style
from zlapi import ZaloAPI
from zlapi.models import *
imei = "<imei>"
cookies = {} # Cookies Dict
class CustomBot(ZaloAPI):
def onMessage(self, mid, author_id, message, message_object, thread_id, thread_type):
if not isinstance(message, str):
return
if message == ".hi":
print(f"{author_id} sent message .hi")
bot = CustomBot("<phone>", "<password>", imei=imei, session_cookies=cookies)
bot.listen()
- If the message is not
string
do not process this message.- If the message is
.hi
will print author id of message to terminal.
Async code style
from zlapi.Async import ZaloAPI
from zlapi.models import *
imei = "<imei>"
cookies = {} # Cookies Dict
class CustomBot(ZaloAPI):
async def onMessage(self, mid, author_id, message, message_object, thread_id, thread_type):
if not isinstance(message, str):
return
if message == ".hi":
print(f"{author_id} sent message .hi")
bot = CustomBot("<phone>", "<password>", imei=imei, session_cookies=cookies)
bot.listen()
- If the message is not
string
do not process this message.- If the message is
.hi
will print author id of message to terminal.
Simple code style
-
Method 1
from zlapi.simple import ZaloAPI from zlapi.models import * imei = "<imei>" cookies = {} # Cookies Dict bot = ZaloAPI("</>", "</>", imei, cookies, prefix="<bot prefix>") @bot.event async def on_message(ctx): if ctx.message == ".hi": print(f"{ctx.author_id} sent message .hi") bot.listen()
-
Method 2
from zlapi.simple import ZaloAPI from zlapi.models import * imei = "<imei>" cookies = {} # Cookies Dict bot = ZaloAPI("</>", "</>", imei, cookies, prefix=".") @bot.register_handler(commands=["hi"]) async def handle_hi(ctx): print(f"{ctx.author_id} sent message .hi") bot.listen()
@bot.register_handler(commands=["hi"])
is a decoration class used to register a command. When an incoming message matches the bot prefix + registered commands, the message will be processed.
Fetch Account Information
This function will get the account information you are using in zlapi
.
Normal code style
-
Outside Module Function
bot.fetchAccountInfo()
-
Inside Module Function
self.fetchAccountInfo()
Async code style
-
Outside Module Function
asyncio.run(bot.fetchAccountInfo())
-
Inside Module Function (You can use
await
instead.)await self.fetchAccountInfo()
Simple code style
-
Outside Module Function
asyncio.run(bot.fetch_account_info())
-
Inside Module Function (You can use
await
instead.)await bot.fetch_account_info()
Fetch Phone Number
This function will get user information using that user phone number.
[!NOTE] Can't get information of hidden phone number or locked account
Normal code style
-
Outside Module Function
bot.fetchPhoneNumber("<phone number>")
-
Inside Module Function
self.fetchPhoneNumber("<phone number>")
Async code style
-
Outside Module Function
asyncio.run(bot.fetchPhoneNumber("<phone number>"))
-
Inside Module Function (You can use
await
instead.)await self.fetchPhoneNumber("<phone number>")
Simple code style
-
Outside Module Function
asyncio.run(bot.fetch_phone_number("<phone number>"))
-
Inside Module Function (You can use
await
instead.)await bot.fetch_phone_number("<phone number>")
Fetch User Info
This function will get user information using that user ID.
- In
Normal
/Async
code style you can get user id with author_id argument- In
Simple
code style you can get user id with ctx.author_id argument- Or you can use user id if you already have one
Normal code style
-
Outside Module Function
bot.fetchUserInfo(<user id>)
-
Inside Module Function
self.fetchUserInfo(<user id>)
Async code style
-
Outside Module Function
asyncio.run(bot.fetchUserInfo(<user id>))
-
Inside Module Function (You can use
await
instead.)await self.fetchUserInfo(<user id>)
Simple code style
-
Outside Module Function
asyncio.run(bot.fetch_user_info(<user id>))
-
Inside Module Function (You can use
await
instead.)await bot.fetch_user_info(<user id>)
Fetch Group Info
This function will get group information using that group ID.
- In
Normal
/Async
code style you can get user id with thread_id argument- In
Simple
code style you can get user id with ctx.thread_id argument- Or you can use group id if you already have one
Normal code style
-
Outside Module Function
bot.fetchGroupInfo(<group id>)
-
Inside Module Function
self.fetchGroupInfo(<group id>)
Async code style
-
Outside Module Function
asyncio.run(bot.fetchGroupInfo(<group id>))
-
Inside Module Function (You can use
await
instead.)await self.fetchGroupInfo(<group id>)
Simple code style
-
Outside Module Function
asyncio.run(bot.fetch_group_info(<group id>))
-
Inside Module Function (You can use
await
instead.)await bot.fetch_group_info(<user id>)
Fetch All Friends
This function will get all the friends information of the account currently using the zlapi
.
Normal code style
-
Outside Module Function
bot.fetchAllFriends()
-
Inside Module Function
self.fetchAllFriends()
Async code style
-
Outside Module Function
asyncio.run(bot.fetchAllFriends())
-
Inside Module Function (You can use
await
instead.)await self.fetchAllFriends()
Simple code style
-
Outside Module Function
asyncio.run(bot.fetch_all_friends())
-
Inside Module Function (You can use
await
instead.)await bot.fetch_all_friends()
Fetch All Groups
This function will get all the groups id of the account currently using the zlapi
.
Normal code style
-
Outside Module Function
bot.fetchAllGroups()
-
Inside Module Function
self.fetchAllGroups()
Async code style
-
Outside Module Function
asyncio.run(bot.fetchAllGroups())
-
Inside Module Function (You can use
await
instead.)await self.fetchAllGroups()
Simple code style
-
Outside Module Function
asyncio.run(bot.fetch_all_groups())
-
Inside Module Function (You can use
await
instead.)await bot.fetch_all_groups()
Change Account Setting
This function will change setting of the account currently using the zlapi
.
- Args:
- name (str): The new account name
- dob (str): Date of birth wants to change (format: year-month-day)
- gender (int | str): Gender wants to change (0 = Male, 1 = Female)
Normal code style
-
Outside Module Function
bot.changeAccountSetting(<name>, <dob>, <gender>)
-
Inside Module Function
self.changeAccountSetting(<name>, <dob>, <gender>)
Async code style
-
Outside Module Function
asyncio.run(bot.changeAccountSetting(<name>, <dob>, <gender>))
-
Inside Module Function (You can use
await
instead.)await self.changeAccountSetting(<name>, <dob>, <gender>)
Simple code style
-
Outside Module Function
asyncio.run(bot.change_account_setting(<name>, <dob>, <gender>))
-
Inside Module Function (You can use
await
instead.)await bot.change_account_setting(<name>, <dob>, <gender>)
Change Account Avatar
This function will upload/change avatar of the account currently using the zlapi
.
- Args:
- filePath (str): A path to the image to upload/change avatar
- size (int): Avatar image size (default = auto)
- width (int): Width of avatar image
- height (int): height of avatar image
- language (int | str): Zalo Website language ? (idk)
Normal code style
-
Outside Module Function
bot.changeAccountAvatar(<filePath>)
-
Inside Module Function
self.changeAccountAvatar(<filePath>)
Async code style
-
Outside Module Function
asyncio.run(bot.changeAccountAvatar(<filePath>))
-
Inside Module Function (You can use
await
instead.)await self.changeAccountAvatar(<filePath>)
Simple code style
-
Outside Module Function
asyncio.run(bot.change_account_avatar(<filePath>))
-
Inside Module Function (You can use
await
instead.)await bot.change_account_avatar(<filePath>)
Send Friend Request
This function will send friend request to a user by ID.
- Args:
- userId (int | str): User ID to send friend request
- msg (str): Friend request message
- language (str): Response language or Zalo interface language
Normal code style
-
Outside Module Function
bot.sendFriendRequest(<userId>, <msg>)
-
Inside Module Function
self.sendFriendRequest(<userId>, <msg>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendFriendRequest(<userId>, <msg>))
-
Inside Module Function (You can use
await
instead.)await self.sendFriendRequest(<userId>, <msg>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_friend_request(<userId>, <msg>))
-
Inside Module Function (You can use
await
instead.)await bot.send_friend_request(<userId>, <msg>)
Accept Friend Request
This function will accept friend request from user by ID.
- Args:
- userId (int | str): User ID to accept friend request
- language (str): Response language or Zalo interface language
Normal code style
-
Outside Module Function
bot.acceptFriendRequest(<userId>)
-
Inside Module Function
self.acceptFriendRequest(<userId>)
Async code style
-
Outside Module Function
asyncio.run(bot.acceptFriendRequest(<userId>))
-
Inside Module Function (You can use
await
instead.)await self.acceptFriendRequest(<userId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.accept_friend_request(<userId>))
-
Inside Module Function (You can use
await
instead.)await bot.accept_friend_request(<userId>)
Block View Feed
This function will Block/Unblock friend view feed by ID.
- Args:
- userId (int | str): User ID to block/unblock view feed
- isBlockFeed (int): Block/Unblock friend view feed (1 = True | 0 = False)
Normal code style
-
Outside Module Function
bot.blockViewFeed(<userId>, <isBlockFeed>)
-
Inside Module Function
self.blockViewFeed(<userId>, <isBlockFeed>)
Async code style
-
Outside Module Function
asyncio.run(bot.blockViewFeed(<userId>, <isBlockFeed>))
-
Inside Module Function (You can use
await
instead.)await self.blockViewFeed(<userId>, <isBlockFeed>)
Simple code style
-
Outside Module Function
asyncio.run(bot.block_view_feed(<userId>, <isBlockFeed>))
-
Inside Module Function (You can use
await
instead.)await bot.block_view_feed(<userId>, <isBlockFeed>)
Block User
This function will block user by ID.
- Args:
- userId (int | str): User ID to block
Normal code style
-
Outside Module Function
bot.blockUser(<userId>)
-
Inside Module Function
self.blockUser(<userId>)
Async code style
-
Outside Module Function
asyncio.run(bot.blockUser(<userId>))
-
Inside Module Function (You can use
await
instead.)await self.blockUser(<userId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.block_user(<userId>))
-
Inside Module Function (You can use
await
instead.)await bot.block_user(<userId>)
Unblock User
This function will unblock user by ID.
- Args:
- userId (int | str): User ID to unblock
Normal code style
-
Outside Module Function
bot.unblockUser(<userId>)
-
Inside Module Function
self.unblockUser(<userId>)
Async code style
-
Outside Module Function
asyncio.run(bot.unblockUser(<userId>))
-
Inside Module Function (You can use
await
instead.)await self.unblockUser(<userId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.unblock_user(<userId>))
-
Inside Module Function (You can use
await
instead.)await bot.unblock_user(<userId>)
Create Group
This function will Create a new group.
- Args:
- name (str): The new group name
- description (str): Description of the new group
- members (str | list): List/String member IDs add to new group
- nameChanged (int - auto): Will use default name if disabled (0), else (1)
- createLink (int - default): Create a group link? Default = 1 (True)
Normal code style
-
Outside Module Function
bot.createGroup(<name>, <description>, <members>)
-
Inside Module Function
self.createGroup(<name>, <description>, <members>)
Async code style
-
Outside Module Function
asyncio.run(bot.createGroup(<name>, <description>, <members>))
-
Inside Module Function (You can use
await
instead.)await self.createGroup(<name>, <description>, <members>)
Simple code style
-
Outside Module Function
asyncio.run(bot.create_group(<name>, <description>, <members>))
-
Inside Module Function (You can use
await
instead.)await bot.create_group(<name>, <description>, <members>)
Change Group Avatar
This function will Upload/Change group avatar by ID.
- Args:
- filePath (str): A path to the image to upload/change avatar
- groupId (int | str): Group ID to upload/change avatar
Normal code style
-
Outside Module Function
bot.changeGroupAvatar(<filePath>, <groupId>)
-
Inside Module Function
self.changeGroupAvatar(<filePath>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.changeGroupAvatar(<filePath>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.changeGroupAvatar(<filePath>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.change_group_avatar(<filePath>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.change_group_avatar(<filePath>, <groupId>)
[!NOTE] Client must be the Owner of the group (If the group does not allow members to upload/change)
Change Group Name
This function will Set/Change group name by ID.
- Args:
- groupName (str): Group name to change
- groupId (int | str): Group ID to change name
Normal code style
-
Outside Module Function
bot.changeGroupName(<groupName>, <groupId>)
-
Inside Module Function
self.changeGroupName(<groupName>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.changeGroupName(<groupName>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.changeGroupName(<groupName>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.change_group_name(<groupName>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.change_group_name(<groupName>, <groupId>)
[!NOTE] Client must be the Owner of the group (If the group does not allow members to upload/change)
Change Group Setting
This function will Update group settings by ID.
- Args:
groupId (int | str): Group ID to update settings
defaultMode (str): Default mode of settings
- default: Group default settings
- anti-raid: Group default settings for anti-raid
**kwargs: Group settings kwargs, Value: (1 = True, 0 = False)
- blockName: Không cho phép user đổi tên & ảnh đại diện nhóm
- signAdminMsg: Đánh dấu tin nhắn từ chủ/phó nhóm
- addMemberOnly: Chỉ thêm members (Khi tắt link tham gia nhóm)
- setTopicOnly: Cho phép members ghim (tin nhắn, ghi chú, bình chọn)
- enableMsgHistory: Cho phép new members đọc tin nhắn gần nhất
- lockCreatePost: Không cho phép members tạo ghi chú, nhắc hẹn
- lockCreatePoll: Không cho phép members tạo bình chọn
- joinAppr: Chế độ phê duyệt thành viên
- bannFeature: Default (No description)
- dirtyMedia: Default (No description)
- banDuration: Default (No description)
- lockSendMsg: Không cho phép members gửi tin nhắn
- lockViewMember: Không cho phép members xem thành viên nhóm
- blocked_members: Danh sách members bị chặn
Normal code style
-
Outside Module Function
bot.changeGroupSetting(<groupId>, **kwargs)
-
Inside Module Function
self.changeGroupSetting(<groupId>, **kwargs)
Async code style
-
Outside Module Function
asyncio.run(bot.changeGroupSetting(<groupId>, **kwargs))
-
Inside Module Function (You can use
await
instead.)await self.changeGroupSetting(<groupId>, **kwargs)
Simple code style
-
Outside Module Function
asyncio.run(bot.change_group_setting(<groupId>, **kwargs))
-
Inside Module Function (You can use
await
instead.)await bot.change_group_setting(<groupId>, **kwargs)
[!WARNING] Other settings will default value if not set. See
defaultMode
Change Group Owner
This function will Change group owner by ID.
- Args:
- newAdminId (int | str): members ID to changer owner
- groupId (int | str): ID of the group to changer owner
Normal code style
-
Outside Module Function
bot.changeGroupOwner(<newAdminId>, <groupId>)
-
Inside Module Function
self.changeGroupOwner(<newAdminId>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.changeGroupOwner(<newAdminId>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.changeGroupOwner(<newAdminId>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.change_group_owner(<newAdminId>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.change_group_owner(<newAdminId>, <groupId>)
[!NOTE] Client must be the Owner of the group.
Add Users To Group
This function will Add friends/users to a group.
- Args:
- user_ids (str | list): One or more friend/user IDs to add
- groupId (int | str): Group ID to add friend/user to
Normal code style
-
Outside Module Function
bot.addUsersToGroup(<user_ids>, <groupId>)
-
Inside Module Function
self.addUsersToGroup(<user_ids>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.addUsersToGroup(<user_ids>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.addUsersToGroup(<user_ids>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.add_users_to_group(<user_ids>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.add_users_to_group(<user_ids>, <groupId>)
Kick Users In Group
This function will Kickout members in group by ID.
- Args:
- members (str | list): One or More member IDs to kickout
- groupId (int | str): Group ID to kick member from
Normal code style
-
Outside Module Function
bot.kickUsersInGroup(<members>, <groupId>)
-
Inside Module Function
self.kickUsersInGroup(<members>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.kickUsersInGroup(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.kickUsersInGroup(<members>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.kick_users_in_group(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.kick_users_in_group(<members>, <groupId>)
[!NOTE] Client must be the Owner of the group.
Block Users In Group
This function will Blocked members in group by ID.
- Args:
- members (str | list): One or More member IDs to block
- groupId (int | str): Group ID to block member from
Normal code style
-
Outside Module Function
bot.blockUsersInGroup(<members>, <groupId>)
-
Inside Module Function
self.blockUsersInGroup(<members>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.blockUsersInGroup(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.blockUsersInGroup(<members>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.block_users_in_group(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.block_users_in_group(<members>, <groupId>)
[!NOTE] Client must be the Owner of the group.
Unblock Users In Group
This function will Unblock members in group by ID.
- Args:
- members (str | list): One or More member IDs to unblock
- groupId (int | str): Group ID to unblock member from
Normal code style
-
Outside Module Function
bot.unblockUsersInGroup(<members>, <groupId>)
-
Inside Module Function
self.unblockUsersInGroup(<members>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.unblockUsersInGroup(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.unblockUsersInGroup(<members>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.unblock_users_in_group(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.unblock_users_in_group(<members>, <groupId>)
[!NOTE] Client must be the Owner of the group.
Add Group Admins
This function will Add admins to the group by ID.
- Args:
- members (str | list): One or More member IDs to add
- groupId (int | str): Group ID to add admins
Normal code style
-
Outside Module Function
bot.addGroupAdmins(<members>, <groupId>)
-
Inside Module Function
self.addGroupAdmins(<members>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.addGroupAdmins(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.addGroupAdmins(<members>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.add_group_admins(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.add_group_admins(<members>, <groupId>)
[!NOTE] Client must be the Owner of the group.
Remove Group Admins
This function will Remove admins in the group by ID.
- Args:
- members (str | list): One or More admin IDs to remove
- groupId (int | str): Group ID to remove admins
Normal code style
-
Outside Module Function
bot.removeGroupAdmins(<members>, <groupId>)
-
Inside Module Function
self.removeGroupAdmins(<members>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.removeGroupAdmins(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.removeGroupAdmins(<members>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.remove_group_admins(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.remove_group_admins(<members>, <groupId>)
[!NOTE] Client must be the Owner of the group.
Pin Group Message
This function will Pin message in group by ID.
- Args:
- pinMsg (Message): Message Object to pin
- groupId (int | str): Group ID to pin message
Normal code style
-
Outside Module Function
bot.pinGroupMsg(<pinMsg>, <groupId>)
-
Inside Module Function
self.pinGroupMsg(<pinMsg>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.pinGroupMsg(<pinMsg>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.pinGroupMsg(<pinMsg>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.pin_group_msg(<pinMsg>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.pin_group_msg(<pinMsg>, <groupId>)
Unpin Group Message
This function will Unpin message in group by ID.
- Args:
- pinId (int | str): Pin ID to unpin
- pinTime (int): Pin start time
- groupId (int | str): Group ID to unpin message
Normal code style
-
Outside Module Function
bot.unpinGroupMsg(<pinId>, <pinTime>, <groupId>)
-
Inside Module Function
self.unpinGroupMsg(<pinId>, <pinTime>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.unpinGroupMsg(<pinId>, <pinTime>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.unpinGroupMsg(<pinId>, <pinTime>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.unpin_group_msg(<pinId>, <pinTime>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.unpin_group_msg(<pinId>, <pinTime>, <groupId>)
Delete Group Message
This function will Delete message in group by ID.
- Args:
- msgId (int | str): Message ID to delete
- ownerId (int | str): Owner ID of the message to delete
- clientMsgId (int | str): Client message ID to delete message
- groupId (int | str): Group ID to delete message
Normal code style
-
Outside Module Function
bot.deleteGroupMsg(<msgId>, <onwerId>, <clientMsgId>, <groupId>)
-
Inside Module Function
self.deleteGroupMsg(<msgId>, <onwerId>, <clientMsgId>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.deleteGroupMsg(<msgId>, <onwerId>, <clientMsgId>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.deleteGroupMsg(<msgId>, <onwerId>, <clientMsgId>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.delete_group_msg(<msgId>, <onwerId>, <clientMsgId>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.delete_group_msg(<msgId>, <onwerId>, <clientMsgId>, <groupId>)
View Group Pending
This function will Give list of people pending approval in group by ID.
- Args:
- groupId (int | str): Group ID to view pending members
Normal code style
-
Outside Module Function
bot.viewGroupPending(<groupId>)
-
Inside Module Function
self.viewGroupPending(<groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.viewGroupPending(<groupId>))
-
Inside Module Function (You can use
await
instead.)await self.viewGroupPending(<groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.view_group_pending(<groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.view_group_pending(<groupId>)
Handle Group Pending
This function will Approve/Deny pending users to the group from the group's approval.
- Args:
- members (str | list): One or More member IDs to handle
- groupId (int | str): ID of the group to handle pending members
- isApprove (bool): Approve/Reject pending members (True | False)
Normal code style
-
Outside Module Function
bot.handleGroupPending(<members>, <groupId>)
-
Inside Module Function
self.handleGroupPending(<members>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.handleGroupPending(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.handleGroupPending(<members>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.handle_group_pending(<members>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.handle_group_pending(<members>, <groupId>)
View Poll Detail
This function will Give poll data by ID.
- Args:
- pollId (int | str): Poll ID to view detail
Normal code style
-
Outside Module Function
bot.viewPollDetail(<pollId>)
-
Inside Module Function
self.viewPollDetail(<pollId>)
Async code style
-
Outside Module Function
asyncio.run(bot.viewPollDetail(<pollId>))
-
Inside Module Function (You can use
await
instead.)await self.viewPollDetail(<pollId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.view_poll_detail(<pollId>))
-
Inside Module Function (You can use
await
instead.)await bot.view_poll_detail(<pollId>)
Create Poll
This function will Create poll in group by ID.
- Args:
- question (str): Question for poll
- options (str | list): List options for poll
- groupId (int | str): Group ID to create poll from
- expiredTime (int): Poll expiration time (0 = no expiration)
- pinAct (bool): Pin action (pin poll)
- multiChoices (bool): Allows multiple poll choices
- allowAddNewOption (bool): Allow members to add new options
- hideVotePreview (bool): Hide voting results when haven't voted
- isAnonymous (bool): Hide poll voters
Normal code style
-
Outside Module Function
bot.createPoll(<question>, <options>, <groupId>)
-
Inside Module Function
self.createPoll(<question>, <options>, <groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.createPoll(<question>, <options>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await self.createPoll(<question>, <options>, <groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.create_poll(<question>, <options>, <groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.create_poll(<question>, <options>, <groupId>)
Lock Poll
This function will Lock/end poll by ID.
- Args:
- pollId (int | str): Poll ID to lock
Normal code style
-
Outside Module Function
bot.lockPoll(<pollId>)
-
Inside Module Function
self.lockPoll(<pollId>)
Async code style
-
Outside Module Function
asyncio.run(bot.lockPoll(<pollId>))
-
Inside Module Function (You can use
await
instead.)await self.lockPoll(<pollId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.lock_poll(<pollId>))
-
Inside Module Function (You can use
await
instead.)await bot.lock_poll(<pollId>)
Disperse Group
This function will Disperse group by ID.
- Args:
- groupId (int | str): Group ID to disperse
Normal code style
-
Outside Module Function
bot.disperseGroup(<groupId>)
-
Inside Module Function
self.disperseGroup(<groupId>)
Async code style
-
Outside Module Function
asyncio.run(bot.disperseGroup(<groupId>))
-
Inside Module Function (You can use
await
instead.)await self.disperseGroup(<groupId>)
Simple code style
-
Outside Module Function
asyncio.run(bot.disperse_group(<groupId>))
-
Inside Module Function (You can use
await
instead.)await bot.disperse_group(<groupId>)
Send Message
This function will Send message to a thread (user/group).
- Args:
- message (Message):
Message
Object to send- thread_id (int | str): User/Group ID to send to
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
- mark_message (str): Send messages as
Urgent
orImportant
mark
Normal code style
-
Outside Module Function
bot.send(<message>, <thread_id>, <thread_type>)
or
bot.sendMessage(<message>, <thread_id>, <thread_type>)
-
Inside Module Function
self.send(<message>, <thread_id>, <thread_type>)
or
self.sendMessage(<message>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.send(<message>, <thread_id>, <thread_type>))
or
asyncio.run(bot.sendMessage(<message>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.send(<message>, <thread_id>, <thread_type>)
or
await self.sendMessage(<message>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send(<message>, <thread_id>, <thread_type>))
or
asyncio.run(bot.send_message(<message>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send(<message>, <thread_id>, <thread_type>)
or
await bot.send_message(<message>, <thread_id>, <thread_type>)
Reply Message
This function will Reply message in thread (user/group).
- Args:
- replyMsg (Message):
Message Object
to reply- message (Message):
Message Object
to send- thread_id (int | str): User/Group ID to send to.
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
Normal code style
-
Outside Module Function
bot.replyTo(<replyMsg>, <message>, <thread_id>, <thread_type>)
-
Inside Module Function
self.replyTo(<replyMsg>, <message>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.replyTo(<replyMsg>, <message>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.replyTo(<replyMsg>, <message>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.reply_to(<replyMsg>, <message>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.reply_to(<replyMsg>, <message>, <thread_id>, <thread_type>)
Undo Message
This function will Undo message from the client (self) by ID.
- Args:
- msgId (int | str): Message ID to undo
- cliMsgId (int | str): Client Msg ID to undo
- thread_id (int | str): User/Group ID to undo message
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
Normal code style
-
Outside Module Function
bot.undoMessage(<msgId>, <cliMsgId>, <thread_id>, <thread_type>)
-
Inside Module Function
self.undoMessage(<msgId>, <cliMsgId>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.undoMessage(<msgId>, <cliMsgId>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.undoMessage(<msgId>, <cliMsgId>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.undo_message(<msgId>, <cliMsgId>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.undo_message(<msgId>, <cliMsgId>, <thread_id>, <thread_type>)
Send Reaction
This function will Reaction message in thread (user/group) by ID.
- Args:
- messageObject (Message):
Message Object
to reaction- reactionIcon (str): Icon/Text to reaction
- thread_id (int | str): Group/User ID contain message to reaction
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
Normal code style
-
Outside Module Function
bot.sendReaction(<messageObject>, <reactionIcon>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendReaction(<messageObject>, <reactionIcon>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendReaction(<messageObject>, <reactionIcon>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendReaction(<messageObject>, <reactionIcon>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_reaction(<messageObject>, <reactionIcon>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_reaction(<messageObject>, <reactionIcon>, <thread_id>, <thread_type>)
Send Multiple Reactions
This function will Reaction multi message in thread (user/group) by ID.
- Args:
- reactionObj (MessageReaction): Message(s) data to reaction
- reactionIcon (str): Icon/Text to reaction
- thread_id (int | str): Group/User ID contain message to reaction
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
Normal code style
-
Outside Module Function
bot.sendMultiReaction(<reactionObj>, <reactionIcon>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendMultiReaction(<reactionObj>, <reactionIcon>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendMultiReaction(<reactionObj>, <reactionIcon>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendMultiReaction(<reactionObj>, <reactionIcon>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_multi_reaction(<reactionObj>, <reactionIcon>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_multi_reaction(<reactionObj>, <reactionIcon>, <thread_id>, <thread_type>)
Send Remote File
This function will Send File to a User/Group with url.
- Args:
- fileUrl (str): File url to send
- thread_id (int | str): User/Group ID to send to.
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
- fileName (str): File name to send
- fileSize (int): File size to send
- extension (str): type of file to send (py, txt, mp4, ...)
Normal code style
-
Outside Module Function
bot.sendRemoteFile(<fileUrl>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendRemoteFile(<fileUrl>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendRemoteFile(<fileUrl>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendRemoteFile(<fileUrl>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_remote_file(<fileUrl>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_remote_file(<fileUrl>, <thread_id>, <thread_type>)
Send Remote Video
This function will Send video to a User/Group with url.
- Args:
- videoUrl (str): Video link to send
- thumbnailUrl (str): Thumbnail link for video
- duration (int | str): Time for video (ms)
- thread_id (int | str): User/Group ID to send to.
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
- width (int): Width of the video
- height (int): Height of the video
- message (Message):
Message Object
to send with video
Normal code style
-
Outside Module Function
bot.sendRemoteVideo(<videoUrl>, <thumbnailUrl>, <duration>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendRemoteVideo(<videoUrl>, <thumbnailUrl>, <duration>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendRemoteVideo(<videoUrl>, <thumbnailUrl>, <duration>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendRemoteVideo(<videoUrl>, <thumbnailUrl>, <duration>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_remote_video(<videoUrl>, <thumbnailUrl>, <duration>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_remote_video(<videoUrl>, <thumbnailUrl>, <duration>, <thread_id>, <thread_type>)
Send Remote Voice
This function will Send voice to a User/Group with url.
- Args:
- voiceUrl (str): Voice link to send
- thread_id (int | str): User/Group ID to change status in
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
- fileSize (int | str): Voice content length (size) to send
Normal code style
-
Outside Module Function
bot.sendRemoteVoice(<voiceUrl>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendRemoteVoice(<voiceUrl>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendRemoteVoice(<voiceUrl>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendRemoteVoice(<voiceUrl>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_remote_voice(<voiceUrl>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_remote_voice(<voiceUrl>, <thread_id>, <thread_type>)
Send Local Image
This function will Send Image to a User/Group with local file.
- Args:
- imagePath (str): Image directory to send
- thread_id (int | str): User/Group ID to send to.
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
- width (int): Image width to send
- height (int): Image height to send
- message (Message):
Message Object
to send with image
Normal code style
-
Outside Module Function
bot.sendLocalImage(<imagePath>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendLocalImage(<imagePath>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendLocalImage(<imagePath>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendLocalImage(<imagePath>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_local_image(<imagePath>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_local_image(<imagePath>, <thread_id>, <thread_type>)
Send Multiple Local Image
This function will Send Multiple Image to a User/Group with local file.
- Args:
- imagePathList (list): List image directory to send
- thread_id (int | str): User/Group ID to send to.
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
- width (int): Image width to send
- height (int): Image height to send
- message (Message):
Message Object
to send with image
Normal code style
-
Outside Module Function
bot.sendMultiLocalImage(<imagePathList>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendMultiLocalImage(<imagePathList>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendMultiLocalImage(<imagePathList>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendMultiLocalImage(<imagePathList>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_multi_local_image(<imagePathList>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_multi_local_image(<imagePathList>, <thread_id>, <thread_type>)
Send Local Gif
This function will Send Gif to a User/Group with local file.
- Args:
- gifPath (str): Gif path to send
- thumbnailUrl (str): Thumbnail of gif to send
- thread_id (int | str): User/Group ID to send to.
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
- gifName (str): Gif name to send
- width (int): Gif width to send
- height (int): Gif height to send
Normal code style
-
Outside Module Function
bot.sendLocalGif(<gifPath>, <thumbnailUrl>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendLocalGif(<gifPath>, <thumbnailUrl>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendLocalGif(<gifPath>, <thumbnailUrl>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendLocalGif(<gifPath>, <thumbnailUrl>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_local_gif(<gifPath>, <thumbnailUrl>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_local_gif(<gifPath>, <thumbnailUrl>, <thread_id>, <thread_type>)
Send Sticker
This function will Send Sticker to a User/Group.
- Args:
- stickerType (int | str): Sticker type to send
- stickerId (int | str): Sticker id to send
- cateId (int | str): Sticker category id to send
- thread_id (int | str): User/Group ID to send to.
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
Normal code style
-
Outside Module Function
bot.sendSticker(<stickerType>, <stickerId>, <cateId>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendSticker(<stickerType>, <stickerId>, <cateId>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendSticker(<stickerType>, <stickerId>, <cateId>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendSticker(<stickerType>, <stickerId>, <cateId>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_sticker(<stickerType>, <stickerId>, <cateId>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_sticker(<stickerType>, <stickerId>, <cateId>, <thread_id>, <thread_type>)
Send Custom Sticker
This function will Send custom (static/animation) sticker to a User/Group with url.
- Args:
- staticImgUrl (str): Image url (png, jpg, jpeg) format to create sticker
- animationImgUrl (str): Static/Animation image url (webp) format to create sticker
- thread_id (int | str): User/Group ID to send sticker to.
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
- reply (int | str): Message ID to send stickers with quote
- width (int | str): Width of photo/sticker
- height (int | str): Height of photo/sticker
Normal code style
-
Outside Module Function
bot.sendCustomSticker(<staticImgUrl>, <animationImgUrl>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendCustomSticker(<staticImgUrl>, <animationImgUrl>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendCustomSticker(<staticImgUrl>, <animationImgUrl>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendCustomSticker(<staticImgUrl>, <animationImgUrl>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_custom_sticker(<staticImgUrl>, <animationImgUrl>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_custom_sticker(<staticImgUrl>, <animationImgUrl>, <thread_id>, <thread_type>)
Send Link
This function will Send link to a User/Group with url.
- Args:
- linkUrl (str): Link url to send
- title (str): Title for card to send
- thread_id (int | str): User/Group ID to send link to
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
- thumbnailUrl (str): Thumbnail link url for card to send
- domainUrl (str): Main domain of Link to send (eg: github.com)
- desc (str): Description for card to send
- message (Message):
Message Object
to send with the link
Normal code style
-
Outside Module Function
bot.sendLink(<linkUrl>, <title>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendLink(<linkUrl>, <title>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendLink(<linkUrl>, <title>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendLink(<linkUrl>, <title>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_link(<linkUrl>, <title>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_link(<linkUrl>, <title>, <thread_id>, <thread_type>)
Send Report
This function will Send report to Zalo.
- Args:
thread_id (int | str): User/Group ID to report
thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
reason (int): Reason for reporting
- 1 = Nội dung nhạy cảm
- 2 = Làm phiền
- 3 = Lừa đảo
- 0 = custom
content (str): Report content (work if reason = custom)
Normal code style
-
Outside Module Function
bot.sendReport(<thread_id>, <thread_type>)
-
Inside Module Function
self.sendReport(<thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendReport(<thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendReport(<thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_report(<thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_report(<thread_id>, <thread_type>)
Send Business Card
This function will Send business card to thread (user/group) by user ID.
- Args:
- userId (int | str): Business card user ID
- qrCodeUrl (str): QR Code link with business card profile information
- thread_id (int | str): User/Group ID to change status in
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
- phone (int | str): Send business card with phone number
Normal code style
-
Outside Module Function
bot.sendBusinessCard(<userId>, <qrCodeUrl>, <thread_id>, <thread_type>)
-
Inside Module Function
self.sendBusinessCard(<userId>, <qrCodeUrl>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.sendBusinessCard(<userId>, <qrCodeUrl>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.sendBusinessCard(<userId>, <qrCodeUrl>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.send_business_card(<userId>, <qrCodeUrl>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.send_business_card(<userId>, <qrCodeUrl>, <thread_id>, <thread_type>)
Set Typing Status
This function will Set users typing status.
- Args:
- thread_id: User/Group ID to change status in.
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
Normal code style
-
Outside Module Function
bot.setTyping(<thread_id>, <thread_type>)
-
Inside Module Function
self.setTyping(<thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.setTyping(<thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.setTyping(<thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.set_typing(<thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.set_typing(<thread_id>, <thread_type>)
Mark Message As Delivered
This function will Mark a message as delivered.
- Args:
- msgId (int | str): Message ID to set as delivered
- cliMsgId (int | str): Client message ID
- senderId (int | str): Message sender Id
- thread_id (int | str): User/Group ID to mark as delivered
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
Normal code style
-
Outside Module Function
bot.markAsDelivered(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>)
-
Inside Module Function
self.markAsDelivered(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.markAsDelivered(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.markAsDelivered(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.mark_as_delivered(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.mark_as_delivered(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>)
Mark Message As Read
This function will Mark a message as read.
- Args:
- msgId (int | str): Message ID to set as delivered
- cliMsgId (int | str): Client message ID
- senderId (int | str): Message sender Id
- thread_id (int | str): User/Group ID to mark as read
- thread_type (ThreadType):
ThreadType.USER
,ThreadType.GROUP
Normal code style
-
Outside Module Function
bot.markAsRead(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>)
-
Inside Module Function
self.markAsRead(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>)
Async code style
-
Outside Module Function
asyncio.run(bot.markAsRead(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await self.markAsRead(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>)
Simple code style
-
Outside Module Function
asyncio.run(bot.mark_as_read(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>))
-
Inside Module Function (You can use
await
instead.)await bot.mark_as_read(<msgId>, <cliMsgId>, <senderId>, <thread_id>, <thread_type>)
Listen
This function will Initialize and runs the listening loop continually.
- Args:
- delay (int): Delay time for each message fetch for
requests
type (Default: 1)- thread (bool): Handle messages within the thread for
requests
type (Default: False)- type (str): Type of listening (Default: websocket)
- reconnect (int): Delay interval when reconnecting
- Use Outside Of Function
bot.listen()
On Listening
This function is called when the client is listening.
Normal code style
-
Inside Module Custom Class
def onListening(self): ....
Async code style
-
Inside Module Custom Class
async def onListening(self): ....
Simple code style
-
Outside Module Class
@bot.event async def on_listening(): ....
On Message
This function is called when the client is listening, and somebody sends a message.
- Args:
- mid: The message ID
- author_id: The ID of the author
- message: The message content of the author
- message_object: The message (As a
Message
object)- thread_id: Thread ID that the message was sent to.
- thread_type (ThreadType): Type of thread that the message was sent to.
Normal code style
-
Inside Module Custom Class
def onMessage(self, mid, author_id, message, message_object, thread_id, thread_type): ....
Async code style
-
Inside Module Custom Class
async def onMessage(self, mid, author_id, message, message_object, thread_id, thread_type): ....
Simple code style
In simple type, all event or register_handler functions use args with context.
Args Context Example:
- ctx.message_id
- ctx.author_id
- ctx.message
- ctx.message_object
- ctx.thread_id
- ctx.thread_type
-
Outside Module Class
@bot.event async def on_message(ctx): ....
On Event
This function is called when the client listening, and some events occurred.
- Args:
- event_data (EventObject): Event data (As a
EventObject
object)- event_type (EventType/GroupEventType): Event Type
Normal code style
-
Inside Module Custom Class
def onEvent(self, event_data, event_type): ....
Async code style
-
Inside Module Custom Class
async def onEvent(self, event_data, event_type): ....
Simple code style
In simple type, all event or register_handler functions use args with context.
Args Context Example:
- ctx.event_data
- ctx.event_type
-
Outside Module Class
@bot.event async def on_event(ctx): ....
Messages
Represents a Zalo message.
- Args:
- text (str): The actual message
- style (MessageStyle/MultiMsgStyle): A
MessageStyle
orMultiMsgStyle
objects- mention (Mention/MultiMention): A
Mention
orMultiMention
objects- parse_mode (str): Format messages in
Markdown
,HTML
style
Message(text=<text>, mention=<mention>, style=<style>)
Message Style
Style for message.
- Args:
- offset (int): The starting position of the style. Defaults to 0.
- length (int): The length of the style. Defaults to 1.
- style (str): The type of style. Can be "font", "bold", "italic", "underline", "strike", or "color". Defaults to "font".
- color (str): The color of the style in hexadecimal format (e.g. "ffffff"). Only applicable when style is "color". Defaults to "ffffff".
- size (int | str): The font size of the style. Only applicable when style is "font". Defaults to "18".
- auto_format (bool): If there are multiple styles (used in
MultiMsgStyle
) then set it to False. Default is True (1 style)
-
Example
- bold style with offset is 5, length is 10.
style = MessageStyle(offset=5, length=10, style="bold") ...
- color style with offset is 10, length is 5 and color="
#ff0000
"
style = MessageStyle(offset=10, ``length=5``, style="color", color="ff0000") ...
- font style with offset is 15, length is 8 and size="24" (Customize font size to 24)
style = MessageStyle(offset=15, length=8, style="font", size="24") ...
Multiple Message Style
Multiple style for message.
- Args:
- listStyle (MessageStyle): A list of
MessageStyle
objects to be combined into a single style format.
style = MultiMsgStyle([
MessageStyle(offset=<text>, length=<mention>, style=<style>, color=<color>, size=<size>, auto_format=False),
MessageStyle(offset=<text>, length=<mention>, style=<style>, color=<color>, size=<size>, auto_format=False),
...
])
Mention
Represents a @mention.
- Args:
- uid (str): The user ID to be mentioned.
- length (int): The length of the mention. Defaults to 1.
- offset (int): The starting position of the mention. Defaults to 0.
- auto_format (bool): If there are multiple mention (used in
MultiMention
) then set it to False. Default is True (1 mention).
mention = Mention(uid=<uid>, length=<length>, offset=<offset>)
...
- Mention user id 1234567890 with offset is 10 and length is 5.
mention = Mention("1234567890", length=5, offset=10)
...
Multiple Mention
Represents multiple @mentions.
- Args:
- listMention (Mention): A list of
Mention
objects to be combined into a single mention format.
mention = MultiMention([
Mention(uid=<uid>, length=<length>, offset=<offset>, auto_format=False),
Mention(uid=<uid>, length=<length>, offset=<offset>, auto_format=False),
...
])
- Mention user id 1234567890 with offset is 10 and length is 5.
- Mention user id 9876543210 with offset is 20 and length is 3.
mention1 = Mention("1234567890", length=5, offset=10)
mention2 = Mention("9876543210", length=3, offset=20)
mention = MultiMention([mention1, mention2])
Example
See examples folder to learn more about zlapi
.
Acknowledgments
-
This project was originally inspired by fbchat.
-
listen
websocket
type taken from zca-js. -
Thanks for support:
- Crow for Hosting.
- Duy Hoang for the Video Tutorial.
- Nguyen Hong Anh Duc for the Example.
- Khang Phan for help fix the
listen
function error.
Contact For Help
- Telegram: Vexx
- Facebook: Lê Quốc Việt
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file zlapi-1.0.3.tar.gz
.
File metadata
- Download URL: zlapi-1.0.3.tar.gz
- Upload date:
- Size: 95.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81ece21d411701a9a88272636785affb9bba2ef3f84d221e38295679116df815 |
|
MD5 | 313244b7557f05c49132ae532af79b28 |
|
BLAKE2b-256 | f58983db0ffe3ac004aa54b50439b9f5bfb2f06e19b61977189fdc5819981b9a |
File details
Details for the file zlapi-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: zlapi-1.0.3-py3-none-any.whl
- Upload date:
- Size: 77.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 888226c199cb3298116ad8ee4c15659cf52cd46c8fcf41a709f43420159fa888 |
|
MD5 | cdb3ac270deafa4548342bdc01b0905c |
|
BLAKE2b-256 | 0b3e4994b4a517dc1bcd4c9e81942f23c6d1abbfe6649ceedbc2848cf894fabb |