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.2)
Improvements
- Various typo fixes and doc improvements.
- Add simple code style for module. Like
telebot
, discord
, ...
- Add
async
/await
for module.
- Add
websocket
type to listen function.
- Add
run forever
for listen function.
- Add send
gif
, video
, voice
, business card
, multi image
.
- Add
Block/Unblock
members when kicked out of group.
- Add
Pin/Unpin
message in group.
- Add
On Event
function to handle group and user events.
- Add
Parse Mode
for Message.
Bugfixes
-
Fixed bug of the replyMessage
function, only replying to normal messages.
-
Fixed payload in function addUsersToGroup
.
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 click Refresh Page
.
Windows
Android
- Use
kiwibrowser
instead of chrome
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
# 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)
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) with thread=True
.
bot.listen(thread=True)
- You can change the listen mode with
type="<listen type>"
. Current module support websocket
, requests
type (default type is websocket)
bot.listen(type="<listen type>")
- If you don't want to have to rerun the bot script when something goes wrong in the listen function you can use
run_forever=True
.
bot.listen(run_forever=True)
# > 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)
# bot.listen(type="...")
bot.listen()
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.
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()
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()
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
```py
from zlapi import ZaloAPI
from zlapi.models import *
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("", "", 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
```py
from zlapi.Async import ZaloAPI
from zlapi.models import *
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("", "", 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
```py
from zlapi.simple import ZaloAPI
from zlapi.models import *
imei = ""
cookies = {} # Cookies Dict
bot = ZaloAPI(">", ">", imei, cookies, prefix="")
@bot.event
async def on_message(ctx):
if ctx.message == ".hi":
print(f"{ctx.author_id} sent message .hi")
bot.listen()
```
- Method 2
```py
from zlapi.simple import ZaloAPI
from zlapi.models import *
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
```py
bot.fetchAccountInfo()
```
- Inside Module Function
```py
self.fetchAccountInfo()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.fetchAccountInfo())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.fetchAccountInfo()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.fetch_account_info())
```
- Inside Module Function (You can use ``await`` instead.)
```py
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
```py
bot.fetchPhoneNumber("")
```
- Inside Module Function
```py
self.fetchPhoneNumber("")
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.fetchPhoneNumber(""))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.fetchPhoneNumber("")
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.fetch_phone_number(""))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.fetch_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
```py
bot.fetchUserInfo()
```
- Inside Module Function
```py
self.fetchUserInfo()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.fetchUserInfo())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.fetchUserInfo()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.fetch_user_info())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.fetch_user_info()
```
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
```py
bot.fetchGroupInfo()
```
- Inside Module Function
```py
self.fetchGroupInfo()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.fetchGroupInfo())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.fetchGroupInfo()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.fetch_group_info())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.fetch_group_info()
```
Fetch All Friends
This function will get all the friends information of the account currently using the zlapi
.
Normal code style
- Outside Module Function
```py
bot.fetchAllFriends()
```
- Inside Module Function
```py
self.fetchAllFriends()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.fetchAllFriends())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.fetchAllFriends()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.fetch_all_friends())
```
- Inside Module Function (You can use ``await`` instead.)
```py
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
```py
bot.fetchAllGroups()
```
- Inside Module Function
```py
self.fetchAllGroups()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.fetchAllGroups())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.fetchAllGroups()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.fetch_all_groups())
```
- Inside Module Function (You can use ``await`` instead.)
```py
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
```py
bot.changeAccountSetting(, , )
```
- Inside Module Function
```py
self.changeAccountSetting(, , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.changeAccountSetting(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.changeAccountSetting(, , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.change_account_setting(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.change_account_setting(, , )
```
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
```py
bot.changeAccountAvatar()
```
- Inside Module Function
```py
self.changeAccountAvatar()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.changeAccountAvatar())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.changeAccountAvatar()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.change_account_avatar())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.change_account_avatar()
```
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
```py
bot.sendFriendRequest(, )
```
- Inside Module Function
```py
self.sendFriendRequest(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendFriendRequest(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendFriendRequest(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_friend_request(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_friend_request(, )
```
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
```py
bot.acceptFriendRequest()
```
- Inside Module Function
```py
self.acceptFriendRequest()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.acceptFriendRequest())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.acceptFriendRequest()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.accept_friend_request())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.accept_friend_request()
```
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
```py
bot.blockViewFeed(, )
```
- Inside Module Function
```py
self.blockViewFeed(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.blockViewFeed(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.blockViewFeed(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.block_view_feed(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.block_view_feed(, )
```
Block User
This function will block user by ID.
- Args:
- userId (int | str): User ID to block
Normal code style
- Outside Module Function
```py
bot.blockUser()
```
- Inside Module Function
```py
self.blockUser()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.blockUser())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.blockUser()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.block_user())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.block_user()
```
Unblock User
This function will unblock user by ID.
- Args:
- userId (int | str): User ID to unblock
Normal code style
- Outside Module Function
```py
bot.unblockUser()
```
- Inside Module Function
```py
self.unblockUser()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.unblockUser())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.unblockUser()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.unblock_user())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.unblock_user()
```
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
```py
bot.createGroup(, , )
```
- Inside Module Function
```py
self.createGroup(, , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.createGroup(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.createGroup(, , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.create_group(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.create_group(, , )
```
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
```py
bot.changeGroupAvatar(, )
```
- Inside Module Function
```py
self.changeGroupAvatar(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.changeGroupAvatar(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.changeGroupAvatar(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.change_group_avatar(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.change_group_avatar(, )
```
[!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
```py
bot.changeGroupName(, )
```
- Inside Module Function
```py
self.changeGroupName(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.changeGroupName(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.changeGroupName(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.change_group_name(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.change_group_name(, )
```
[!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
```py
bot.changeGroupSetting(, **kwargs)
```
- Inside Module Function
```py
self.changeGroupSetting(, **kwargs)
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.changeGroupSetting(, **kwargs))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.changeGroupSetting(, **kwargs)
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.change_group_setting(, **kwargs))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.change_group_setting(, **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
```py
bot.changeGroupOwner(, )
```
- Inside Module Function
```py
self.changeGroupOwner(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.changeGroupOwner(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.changeGroupOwner(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.change_group_owner(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.change_group_owner(, )
```
[!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
```py
bot.addUsersToGroup(, )
```
- Inside Module Function
```py
self.addUsersToGroup(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.addUsersToGroup(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.addUsersToGroup(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.add_users_to_group(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.add_users_to_group(, )
```
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
```py
bot.kickUsersInGroup(, )
```
- Inside Module Function
```py
self.kickUsersInGroup(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.kickUsersInGroup(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.kickUsersInGroup(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.kick_users_in_group(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.kick_users_in_group(, )
```
[!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
```py
bot.blockUsersInGroup(, )
```
- Inside Module Function
```py
self.blockUsersInGroup(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.blockUsersInGroup(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.blockUsersInGroup(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.block_users_in_group(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.block_users_in_group(, )
```
[!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
```py
bot.unblockUsersInGroup(, )
```
- Inside Module Function
```py
self.unblockUsersInGroup(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.unblockUsersInGroup(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.unblockUsersInGroup(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.unblock_users_in_group(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.unblock_users_in_group(, )
```
[!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
```py
bot.addGroupAdmins(, )
```
- Inside Module Function
```py
self.addGroupAdmins(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.addGroupAdmins(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.addGroupAdmins(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.add_group_admins(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.add_group_admins(, )
```
[!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
```py
bot.removeGroupAdmins(, )
```
- Inside Module Function
```py
self.removeGroupAdmins(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.removeGroupAdmins(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.removeGroupAdmins(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.remove_group_admins(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.remove_group_admins(, )
```
[!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
```py
bot.pinGroupMsg(, )
```
- Inside Module Function
```py
self.pinGroupMsg(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.pinGroupMsg(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.pinGroupMsg(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.pin_group_msg(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.pin_group_msg(, )
```
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
```py
bot.unpinGroupMsg(, , )
```
- Inside Module Function
```py
self.unpinGroupMsg(, , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.unpinGroupMsg(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.unpinGroupMsg(, , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.unpin_group_msg(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.unpin_group_msg(, , )
```
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
```py
bot.deleteGroupMsg(, , , )
```
- Inside Module Function
```py
self.deleteGroupMsg(, , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.deleteGroupMsg(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.deleteGroupMsg(, , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.delete_group_msg(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.delete_group_msg(, , , )
```
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
```py
bot.viewGroupPending()
```
- Inside Module Function
```py
self.viewGroupPending()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.viewGroupPending())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.viewGroupPending()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.view_group_pending())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.view_group_pending()
```
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
```py
bot.handleGroupPending(, )
```
- Inside Module Function
```py
self.handleGroupPending(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.handleGroupPending(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.handleGroupPending(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.handle_group_pending(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.handle_group_pending(, )
```
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
```py
bot.viewPollDetail()
```
- Inside Module Function
```py
self.viewPollDetail()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.viewPollDetail())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.viewPollDetail()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.view_poll_detail())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.view_poll_detail()
```
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
```py
bot.createPoll(, , )
```
- Inside Module Function
```py
self.createPoll(, , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.createPoll(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.createPoll(, , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.create_poll(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.create_poll(, , )
```
Lock Poll
This function will Lock/end poll by ID.
- Args:
- pollId (int | str): Poll ID to lock
Normal code style
- Outside Module Function
```py
bot.lockPoll()
```
- Inside Module Function
```py
self.lockPoll()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.lockPoll())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.lockPoll()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.lock_poll())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.lock_poll()
```
Disperse Group
This function will Disperse group by ID.
- Args:
- groupId (int | str): Group ID to disperse
Normal code style
- Outside Module Function
```py
bot.disperseGroup()
```
- Inside Module Function
```py
self.disperseGroup()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.disperseGroup())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.disperseGroup()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.disperse_group())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.disperse_group()
```
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
or Important
mark
Normal code style
- Outside Module Function
```py
bot.send(, , )
```
or
```py
bot.sendMessage(, , )
```
- Inside Module Function
```py
self.send(, , )
```
or
```py
self.sendMessage(, , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.send(, , ))
```
or
```py
asyncio.run(bot.sendMessage(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.send(, , )
```
or
```py
await self.sendMessage(, , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send(, , ))
```
or
```py
asyncio.run(bot.send_message(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send(, , )
```
or
```py
await bot.send_message(, , )
```
Reply Message
This function will Reply message in thread (user/group).
- Args:
- message (Message):
Message Object
to send
- replyMsg (Message):
Message Object
to reply
- thread_id (int | str): User/Group ID to send to.
- thread_type (ThreadType):
ThreadType.USER
, ThreadType.GROUP
Normal code style
- Outside Module Function
```py
bot.replyMessage(, , , )
```
- Inside Module Function
```py
self.replyMessage(, , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.replyMessage(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.replyMessage(, , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.reply_message(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.reply_message(, , , )
```
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
```py
bot.undoMessage(, , , )
```
- Inside Module Function
```py
self.undoMessage(, , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.undoMessage(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.undoMessage(, , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.undo_message(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.undo_message(, , , )
```
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
```py
bot.sendReaction(, , , )
```
- Inside Module Function
```py
self.sendReaction(, , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendReaction(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendReaction(, , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_reaction(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_reaction(, , , )
```
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
```py
bot.sendMultiReaction(, , , )
```
- Inside Module Function
```py
self.sendMultiReaction(, , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendMultiReaction(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendMultiReaction(, , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_multi_reaction(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_multi_reaction(, , , )
```
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
```py
bot.sendRemoteFile(, , )
```
- Inside Module Function
```py
self.sendRemoteFile(, , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendRemoteFile(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendRemoteFile(, , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_remote_file(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_remote_file(, , )
```
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
```py
bot.sendRemoteVideo(, , , , )
```
- Inside Module Function
```py
self.sendRemoteVideo(, , , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendRemoteVideo(, , , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendRemoteVideo(, , , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_remote_video(, , , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_remote_video(, , , , )
```
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
```py
bot.sendRemoteVoice(, , )
```
- Inside Module Function
```py
self.sendRemoteVoice(, , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendRemoteVoice(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendRemoteVoice(, , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_remote_voice(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_remote_voice(, , )
```
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
```py
bot.sendLocalImage(, , )
```
- Inside Module Function
```py
self.sendLocalImage(, , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendLocalImage(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendLocalImage(, , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_local_image(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_local_image(, , )
```
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
```py
bot.sendMultiLocalImage(, , )
```
- Inside Module Function
```py
self.sendMultiLocalImage(, , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendMultiLocalImage(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendMultiLocalImage(, , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_multi_local_image(, , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_multi_local_image(, , )
```
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
```py
bot.sendLocalGif(, , , )
```
- Inside Module Function
```py
self.sendLocalGif(, , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendLocalGif(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendLocalGif(, , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_local_gif(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_local_gif(, , , )
```
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
```py
bot.sendSticker(, , , , )
```
- Inside Module Function
```py
self.sendSticker(, , , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendSticker(, , , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendSticker(, , , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_sticker(, , , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_sticker(, , , , )
```
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
```py
bot.sendCustomSticker(, , , )
```
- Inside Module Function
```py
self.sendCustomSticker(, , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendCustomSticker(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendCustomSticker(, , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_custom_sticker(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_custom_sticker(, , , )
```
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
```py
bot.sendLink(, , , )
```
- Inside Module Function
```py
self.sendLink(, , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendLink(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendLink(, , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_link(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_link(, , , )
```
Send Report
This function will Send report to Zalo.
-
Args:
-
user_id (int | str): User ID to report
-
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
```py
bot.sendReport()
```
- Inside Module Function
```py
self.sendReport()
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendReport())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendReport()
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_report())
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_report()
```
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
```py
bot.sendBusinessCard(, , , )
```
- Inside Module Function
```py
self.sendBusinessCard(, , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.sendBusinessCard(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.sendBusinessCard(, , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.send_business_card(, , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.send_business_card(, , , )
```
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
```py
bot.setTyping(, )
```
- Inside Module Function
```py
self.setTyping(, )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.setTyping(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.setTyping(, )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.set_typing(, ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.set_typing(, )
```
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
```py
bot.markAsDelivered(, , , , )
```
- Inside Module Function
```py
self.markAsDelivered(, , , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.markAsDelivered(, , , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.markAsDelivered(, , , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.mark_as_delivered(, , , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.mark_as_delivered(, , , , )
```
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
```py
bot.markAsRead(, , , , )
```
- Inside Module Function
```py
self.markAsRead(, , , , )
```
Async code style
- Outside Module Function
```py
asyncio.run(bot.markAsRead(, , , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await self.markAsRead(, , , , )
```
Simple code style
- Outside Module Function
```py
asyncio.run(bot.mark_as_read(, , , , ))
```
- Inside Module Function (You can use ``await`` instead.)
```py
await bot.mark_as_read(, , , , )
```
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
bot.listen()
On Listening
This function is called when the client is listening.
Normal code style
- Inside Module Custom Class
```py
def onListening(self):
....
```
Async code style
- Inside Module Custom Class
```py
async def onListening(self):
....
```
Simple code style
- Outside Module Class
```py
@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
```py
def onMessage(self, mid, author_id, message, message_object, thread_id, thread_type):
....
```
Async code style
- Inside Module Custom Class
```py
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
```py
@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
```py
def onEvent(self, event_data, event_type):
....
```
Async code style
- Inside Module Custom Class
```py
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
```py
@bot.event
async def on_event(ctx):
....
```
Messages
Represents a Zalo message.
- Args:
- text (str): The actual message
- style (MessageStyle/MultiMsgStyle): A
MessageStyle
or MultiMsgStyle
objects
- mention (Mention/MultiMention): A
Mention
or MultiMention
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
Contact For Help