Automating MAX with Green-API: Methods, Limits, and Userbot Code
A userbot in MAX is a client account with a verified phone number, controlled by scripts without an official API. Green-API offers an HTTP interface for sending messages, parsing chat history, and managing groups. Key limits: 50 messages/sec, 1 request/sec for history and groups. Rate limiting is crucial to avoid bans.
Core Methods for Message Handling
Sending supports text up to 4000 characters, files via URL or upload, locations, and vCard contacts.
- SendMessage: Basic text sending with emojis.
- SendFileByUrl: Media from external links.
- SendFileByUpload: Local files via multipart/form-data.
- SendLocation: Latitude, longitude, and place name.
- SendContact: Contact card.
Downloading files from chats: DownloadFile for images, documents, audio, and video.
Chat history parsing: GetChatHistory pulls up to 5000 messages over 3 months with date filters.
POST {{apiUrl}}/waInstance{{idInstance}}/getChatHistory/{{apiTokenInstance}}
Parameters:
url = "https://3100.api.green-api.com/waInstance{id}/getChatHistory/{token}"
payload = {
"chatId": "-730*******5943",
"count": 500
}
headers = {
'Content-Type': 'application/json'
}
Response includes message type (incoming/outgoing), idMessage, timestamp, textMessage, and extendedTextMessage details.
[
{
"type": "outgoing",
"idMessage": "1763115112345",
"timestamp": 1754999812,
"typeMessage": "extendedTextMessage",
"chatId": "10000000",
"textMessage": "I'm using GREEN-API to send this message!",
"extendedTextMessage": {
"text": "I'm using GREEN-API to send this message!",
"description": "",
"title": "",
"jpegThumbnail": "",
"forwardingScore": 0,
"isForwarded": false
},
"statusMessage": "",
"sendByApi": true
}
]
Additional: GetMessage by ID, LastIncomingMessages, LastOutgoingMessages.
Message Limits:
- Sending messages/files/locations/contacts: ≤50/sec.
- File downloads, chat history, groups: ≤1/sec.
- Editing: ≤50/sec.
Group Administration
Creation: CreateGroup with immediate participant addition (AddGroupParticipant) and avatar setup (SetGroupPicture).
Updates: UpdateGroupName, UpdateGroupSettings for permissions.
{
"chatId": "-10000000000000",
"allowParticipantsAddMembers": true,
"allowParticipantsEditGroupSettings": false,
"allowParticipantsPinMessages": true
}
GetGroupData returns:
- chatId, owner, subject, description.
- creation (Unix timestamp).
- groupInviteLink (if available).
- Permissions: addMembers, editSettings, pinMessages.
- size (participant count).
- participants (admins; full list if <100 members).
{
"chatId": "-10000000000000",
"owner": "79001234567",
"subject": "Group Name",
"description": "Group Description",
"creation": 1764637936,
"groupInviteLink": "https://invite.link/abc123",
"allowParticipantsAddMembers": true,
"allowParticipantsEditGroupSettings": false,
"allowParticipantsPinMessages": true,
"size": 150,
"participants": [
{
"chatId": "79001234567",
"isAdmin": true,
"isSuperAdmin": true
}
]
}
Participant management: AddGroupParticipant, RemoveGroupParticipant, SetGroupAdmin, RemoveAdmin.
Utility Methods
- GetChats: List of chats (groups have chatId <0, phoneNumber=0).
[
{
"chatId": "-10000000000000",
"phoneNumber": 0
},
{
"chatId": "79001234567",
"phoneNumber": 79001234567
}
]
- CheckAccount: Registration status (exist, chatId). Strict limit—high ban risk.
- GetContacts: Phonebook contacts.
[
{
"chatId": "79001234567",
"name": "John Doe",
"contactName": "John",
"type": "user",
"phoneNumber": 79001234567
}
]
Practical Implementations
Group Moderation: Parse notifications, check for banned words, delete and reply.
def moderate_group_messages():
notifications = client.receive_notification()
for notification in notifications:
if notification['type'] == 'incomingMessageReceived':
message = notification['messageData']['textMessage']
chat_id = notification['senderData']['chatId']
if is_spam(message):
client.delete_message(chat_id, message_id)
client.send_message(
chat_id,
"⚠️ Chat rules violation"
)
Auto-Inviter: Distribute by departments.
def add_employee_to_groups(phone, department):
groups = get_groups_by_department(department)
for group in groups:
client.add_group_participant(
chat_id=group['chatId'],
participant_chat_id=phone
)
Report Generator: Pull from CRM, push to chat.
def send_daily_report():
stats = get_daily_statistics()
report = f"📊 Daily Report for {date.today()}:\n"
report += f"New Orders: {stats['orders']}\n"
report += f"Revenue: ${stats['revenue']}\n"
client.send_message(report_target_chat, report)
Key Takeaways
- Stick to limits: 50/sec for sending, 1/sec for groups/history—exceeding leads to bans.
- GetChatHistory: max 5000 messages/3 months, use date filters for large chats.
- Groups >100 members: API shows only bot roles, no full participant parse.
- Use CheckAccount sparingly—risks 2-week ban.
- PyMax as alternative: open-source, no SLA, self-hosted.
— Editorial Team
No comments yet.