Green-API로 MAX 자동화: 방법, 제한, 유저봇 코드
MAX의 유저봇은 인증된 전화번호가 있는 클라이언트 계정으로, 공식 API 없이 스크립트로 제어합니다. Green-API는 메시지 전송, 채팅 기록 분석, 그룹 관리 등을 위한 HTTP 인터페이스를 제공합니다. 주요 제한: 초당 50개 메시지, 기록 및 그룹은 초당 1회 요청. 속도 제한을 지키지 않으면 차단될 수 있습니다.
메시지 처리 핵심 메서드
전송은 4000자 텍스트, URL 또는 업로드 파일, 위치, vCard 연락처를 지원합니다.
- SendMessage: 이모지 포함 기본 텍스트 전송.
- SendFileByUrl: 외부 링크 미디어.
- SendFileByUpload: multipart/form-data로 로컬 파일.
- SendLocation: 위도, 경도, 장소명.
- SendContact: 연락처 카드.
채팅 파일 다운로드: 이미지, 문서, 오디오, 비디오에 DownloadFile 사용.
채팅 기록 분석: GetChatHistory로 3개월 내 최대 5000개 메시지 가져오기(날짜 필터 가능).
POST {{apiUrl}}/waInstance{{idInstance}}/getChatHistory/{{apiTokenInstance}}
파라미터:
url = "https://3100.api.green-api.com/waInstance{id}/getChatHistory/{token}"
payload = {
"chatId": "-730*******5943",
"count": 500
}
headers = {
'Content-Type': 'application/json'
}
응답에는 메시지 유형(수신/발신), idMessage, 타임스탬프, textMessage, extendedTextMessage 상세 정보가 포함됩니다.
[
{
"type": "outgoing",
"idMessage": "1763115112345",
"timestamp": 1754999812,
"typeMessage": "extendedTextMessage",
"chatId": "10000000",
"textMessage": "이 메시지는 GREEN-API로 보냈어요!",
"extendedTextMessage": {
"text": "이 메시지는 GREEN-API로 보냈어요!",
"description": "",
"title": "",
"jpegThumbnail": "",
"forwardingScore": 0,
"isForwarded": false
},
"statusMessage": "",
"sendByApi": true
}
]
추가: ID로 GetMessage, LastIncomingMessages, LastOutgoingMessages.
메시지 제한:
- 메시지/파일/위치/연락처 전송: 초당 ≤50개.
- 파일 다운로드, 채팅 기록, 그룹: 초당 ≤1회.
- 편집: 초당 ≤50회.
그룹 관리
생성: CreateGroup으로 즉시 참가자 추가(AddGroupParticipant)와 아바타 설정(SetGroupPicture).
업데이트: UpdateGroupName, UpdateGroupSettings로 권한 설정.
{
"chatId": "-10000000000000",
"allowParticipantsAddMembers": true,
"allowParticipantsEditGroupSettings": false,
"allowParticipantsPinMessages": true
}
GetGroupData 응답:
- chatId, owner, subject, description.
- creation(Unix 타임스탬프).
- groupInviteLink(가능 시).
- 권한: addMembers, editSettings, pinMessages.
- size(참가자 수).
- participants(관리자; 100명 미만 시 전체 목록).
{
"chatId": "-10000000000000",
"owner": "79001234567",
"subject": "그룹 이름",
"description": "그룹 설명",
"creation": 1764637936,
"groupInviteLink": "https://invite.link/abc123",
"allowParticipantsAddMembers": true,
"allowParticipantsEditGroupSettings": false,
"allowParticipantsPinMessages": true,
"size": 150,
"participants": [
{
"chatId": "79001234567",
"isAdmin": true,
"isSuperAdmin": true
}
]
}
참가자 관리: AddGroupParticipant, RemoveGroupParticipant, SetGroupAdmin, RemoveAdmin.
유틸리티 메서드
- GetChats: 채팅 목록(그룹은 chatId <0, phoneNumber=0).
[
{
"chatId": "-10000000000000",
"phoneNumber": 0
},
{
"chatId": "79001234567",
"phoneNumber": 79001234567
}
]
- CheckAccount: 등록 상태(존재 여부, chatId). 엄격한 제한—차단 위험 높음.
- GetContacts: 전화번호부 연락처.
[
{
"chatId": "79001234567",
"name": "홍길동",
"contactName": "홍길동",
"type": "user",
"phoneNumber": 79001234567
}
]
실전 구현 예시
그룹 관리 봇: 알림 분석, 금지어 확인, 삭제 및 응답.
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,
"⚠️ 채팅 규칙 위반"
)
자동 초대 봇: 부서별 배분.
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
)
리포트 생성기: CRM에서 가져와 채팅으로 전송.
def send_daily_report():
stats = get_daily_statistics()
report = f"📊 {date.today()} 일일 보고서:\n"
report += f"신규 주문: {stats['orders']}건\n"
report += f"매출: {stats['revenue']}원\n"
client.send_message(report_target_chat, report)
주요 요약
- 제한 준수: 전송 초당 50개, 그룹/기록 초당 1회—초과 시 차단.
- GetChatHistory: 최대 5000개/3개월, 대형 채팅은 날짜 필터 사용.
- 100명 초과 그룹: API는 봇 역할만 표시, 전체 참가자 분석 불가.
- CheckAccount는 절제—2주 차단 위험.
- 대안 PyMax: 오픈소스, SLA 없음, 자체 호스팅.
— Editorial Team
아직 댓글이 없습니다.