소스 정보
- 저장소
- green-api/whatsapp-api-client-cpp
- 최근 소스 활동
- 2026년 7월 22일 04:45
- 감지된 SKILL.md 언어
- 영어
- 스타
- 4
- 포크
- 2
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/green-api/whatsapp-api-client-cpp --skill green-api-c-sdk명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SOC 직업 분류 기준
SKILL.md 표시 중
| name | GREEN-API C++ SDK |
| version | 1.0.0 |
| description | AI Skill for writing correct code with GREEN-API WhatsApp API SDK (C++) |
| tags | ["whatsapp","api","green-api","c++","messaging"] |
| status | stable |
| author | GREEN-API |
| documentation | https://green-api.com/en/docs/api/ |
| sdk_repository | https://github.com/green-api/whatsapp-api-client-cpp |
This skill teaches AI agents to write correct and production-ready code using the GREEN-API WhatsApp SDK for C++. All method names, classes, and parameters are verified against the official SDK source code.
Use this skill when:
71234567890@c.us (country code + number + @c.us)79876543210-1581234048@g.us (creator number - timestamp + @g.us)@c.us or @g.us)account.qr(), account.scanqrcode(), or account.getAuthorizationCode()account.getStateInstance() → state must be authorizeddelaySendMessagesMilliseconds setting)account.setSettings() or through consoleAll methods return Response object:
struct Response {
bool success; // true if request succeeded
int statusCode; // HTTP status code
nlohmann::json body; // Response JSON body
};
response.success before accessing response.bodynlohmann::json objects as parametersnlohmann::json msg = {{"chatId", "79876543210@c.us"}, {"message", "Hello"}}#include "greenapi.hpp"
using namespace greenapi;
int main() {
// Initialize with API credentials from https://console.green-api.com
GreenApi client(
"https://api.green-api.com", // apiUrl
"https://media.green-api.com", // mediaUrl
"1101000001", // idInstance (your instance number)
"aabbccddeeff00112233445566778899" // apiTokenInstance (your token)
);
// Use client.sending, client.receiving, client.account, etc.
return 0;
}
idInstance and apiTokenInstance from: https://console.green-api.com#include <cstdlib>
std::string idInstance = std::getenv("GREEN_API_ID") ?: "1101000001";
std::string apiToken = std::getenv("GREEN_API_TOKEN") ?: "";
GreenApi client("https://api.green-api.com", "https://media.green-api.com", idInstance, apiToken);
When: You need to send a WhatsApp message to a contact or group.
Method: client.sending.sendMessage(message)
Code:
#include "greenapi.hpp"
#include <nlohmann/json.hpp>
using namespace greenapi;
int main() {
GreenApi client("https://api.green-api.com", "https://media.green-api.com",
"1101000001", "your_api_token");
// Verify authorization first
Response auth = client.account.getStateInstance();
if (!auth.success || auth.body["stateInstance"] != "authorized") {
std::cerr << "Instance not authorized!" << std::endl;
return 1;
}
// Send message to personal chat
nlohmann::json message = {
{"chatId", "79876543210@c.us"},
{"message", "Hello from GREEN-API!"}
};
Response resp = client.sending.sendMessage(message);
if (resp.success) {
std::cout << "Message sent! ID: " << resp.body["idMessage"] << std::endl;
} else {
std::cerr << "Error: " << resp.statusCode << " - " << resp.body << std::endl;
}
return 0;
}
Error Handling:
401 Unauthorized: Check idInstance and apiTokenInstance400 Bad Request: Verify chatId format (must end with @c.us or @g.us)429 Too Many Requests: Respect send delay (900ms minimum)When: You need to listen for incoming messages in a loop.
Methods: client.receiving.receiveNotification(), client.receiving.deleteNotification()
Code:
#include "greenapi.hpp"
#include <chrono>
#include <thread>
using namespace greenapi;
int main() {
GreenApi client("https://api.green-api.com", "https://media.green-api.com",
"1101000001", "your_api_token");
std::cout << "Polling for notifications (Ctrl+C to stop)..." << std::endl;
while (true) {
// Receive one notification (waits up to 5 seconds)
Response notif = client.receiving.receiveNotification(5);
if (notif.success && notif.body.contains("receiptId")) {
int receiptId = notif.body["receiptId"];
nlohmann::json body = notif.body.value("body", nlohmann::json::object());
// Check notification type
std::string type = body.value("typeWebhook", "");
if (type == "incomingMessageReceived") {
std::string chatId = body.value("senderData", nlohmann::json::object())
.value("chatId", );
std::string text = body.(, nlohmann::json::())
.(, nlohmann::json::())
.(, );
std::cout << << chatId << << text << std::endl;
client.receiving.(receiptId);
}
}
std::this_thread::(std::chrono::());
}
;
}
Key Points:
receiveTimeout (default 5s): how long to wait for a notificationdeleteNotification() after processing to remove from queueWhen: You need to send an image, PDF, or other file from a URL.
Method: client.sending.sendFileByUrl(message)
Code:
#include "greenapi.hpp"
using namespace greenapi;
int main() {
GreenApi client("https://api.green-api.com", "https://media.green-api.com",
"1101000001", "your_api_token");
nlohmann::json message = {
{"chatId", "79876543210@c.us"},
{"urlFile", "https://example.com/image.jpg"},
{"fileName", "photo.jpg"},
{"caption", "Check this image!"} // optional
};
Response resp = client.sending.sendFileByUrl(message);
if (resp.success) {
std::cout << "File sent! Message ID: " << resp.body["idMessage"] << std::endl;
} else {
std::cerr << "Error: " << resp.statusCode << std::endl;
}
return 0;
}
Supported File Types:
.jpg, .png, .gif, .webp.pdf, .doc, .xls, .ppt, etc..mp3, .mp4, .wav, etc.When: You need to create groups, add members, or manage settings.
Methods: client.groups.createGroup(), client.groups.addGroupParticipant(), etc.
Code:
#include "greenapi.hpp"
using namespace greenapi;
int main() {
GreenApi client("https://api.green-api.com", "https://media.green-api.com",
"1101000001", "your_api_token");
// Create group (max 1 group per 5 minutes)
nlohmann::json groupData = {
{"groupName", "My awesome group"},
{"participants", nlohmann::json::array({
"79876543210@c.us",
"79876543211@c.us"
})}
};
Response createResp = client.groups.createGroup(groupData);
if (!createResp.success) {
std::cerr << "Failed to create group!" << std::endl;
return 1;
}
std::string groupId = createResp.body["chatId"];
std::cout << "Group created: " << groupId << std::endl;
// Add another participant
nlohmann::json addMember = {
{"groupId", groupId},
{"participantChatId", "79876543212@c.us"}
};
client.groups.addGroupParticipant(addMember);
// Send message to group
nlohmann::json groupMsg = {
{"chatId", groupId},
{"message", "Welcome to the group!"}
};
client.sending.sendMessage(groupMsg);
return 0;
}
Constraints:
<creator_number>-<timestamp>@g.us@c.us suffixWhen: You want asynchronous notifications via HTTP callback (instead of polling).
Setup Steps:
nlohmann::json settings = {
{"webhookUrl", "https://your-server.com/webhook"},
{"webhookUrlToken", "your-secret-token"} // optional, for authorization header
};
Response resp = client.account.setSettings(settings);
// Example using a simple HTTP library (e.g., crow, pistache, etc.)
// POST /webhook
void handleWebhook(const nlohmann::json& payload) {
std::string type = payload.value("typeWebhook", "");
if (type == "incomingMessageReceived") {
nlohmann::json data = payload["body"]["messageData"];
std::string text = data["textMessageData"]["textMessage"];
std::string from = payload["body"]["senderData"]["chatId"];
std::cout << "Message from " << from << ": " << text << std::endl;
}
}
All methods are organized into groups via GreenApi class members:
| Class | Purpose | See |
|---|---|---|
client.account | Account state, auth, settings | references/account.md |
client.sending | Send messages, files, media | references/sending.md |
client.receiving | Receive messages, download files | references/receiving.md |
client.groups | Create/manage groups | references/groups.md |
client.journals | Chat history, call logs | references/journals.md |
client.statuses | Send/view WhatsApp stories | references/statuses.md |
client.queues | Manage send queue | references/queues.md |
client.readMark | Mark messages as read | references/readMark.md |
client.serviceMethods | Avatar, contacts, chat list | references/serviceMethods.md |
Account: getSettings, setSettings, getStateInstance, getStatusInstance, reboot, logout, qr, scanqrcode, getAuthorizationCode, getWaSettings, getStateInstanceHistory
Sending: sendMessage, sendPoll, sendFileByUpload, sendFileByUrl, uploadFile, getFileSaveTime, sendLocation, sendContact, forwardMessages, sendInteractiveButtons, sendInteractiveButtonsReply
Receiving: receiveNotification, deleteNotification, downloadFile
Groups: createGroup, updateGroupName, getGroupData, addGroupParticipant, removeGroupParticipant, setGroupAdmin, removeAdmin, leaveGroup, updateGroupSettings
Journals: getChatHistory, getMessage, lastIncomingMessages, lastOutgoingMessages, lastIncomingCalls, lastOutgoingCalls
Statuses: sendTextStatus, sendVoiceStatus, sendMediaStatus, deleteStatus, getStatusStatistic, getIncomingStatuses, getOutgoingStatuses
Queues: showMessagesQueue, clearMessagesQueue
ReadMark: readChat
ServiceMethods: checkWhatsapp, getAvatar, getContacts, getContactInfo, editMessage, deleteMessage, archiveChat, unarchiveChat, setDisappearingChat, getChats, sendTyping
// WRONG - missing suffix
client.sending.sendMessage({
{"chatId", "79876543210"},
{"message", "Hi"}
});
✅ Fix:
client.sending.sendMessage({
{"chatId", "79876543210@c.us"}, // personal chat
{"message", "Hi"}
});
// OR for group:
client.sending.sendMessage({
{"chatId", "79876543210-1581234048@g.us"}, // group chat
{"message", "Hi"}
});
// WRONG - assuming instance is already authorized
Response resp = client.sending.sendMessage({
{"chatId", "79876543210@c.us"},
{"message", "Hi"}
});
// Message fails or sits in queue for 24 hours
✅ Fix:
// Always check auth first
Response authCheck = client.account.getStateInstance();
if (!authCheck.success) {
std::cerr << "API error: " << authCheck.statusCode << std::endl;
return 1;
}
std::string state = authCheck.body["stateInstance"];
if (state != "authorized") {
// Trigger QR code flow
Response qrResp = client.account.qr();
std::cout << "Scan QR: " << qrResp.body["qr"] << std::endl;
return 1;
}
// Now safe to send
client.sending.sendMessage({
{"chatId", "79876543210@c.us"},
{"message", "Hi"}
});
// WRONG
Response resp = client.sending.sendMessage(msg);
std::cout << "Sent: " << resp.body["idMessage"] << std::endl;
// Crashes if send failed
✅ Fix:
Response resp = client.sending.sendMessage(msg);
if (resp.success) {
std::cout << "Sent: " << resp.body["idMessage"] << std::endl;
} else {
std::cerr << "Send failed (HTTP " << resp.statusCode << "): "
<< resp.body.dump() << std::endl;
}
// WRONG - tries to create multiple groups immediately
for (int i = 0; i < 10; i++) {
client.groups.createGroup(groupData); // Rate-limited to 1 per 5 min
}
✅ Fix:
#include <thread>
#include <chrono>
// Create with 5-minute gap
for (int i = 0; i < 10; i++) {
client.groups.createGroup(groupData);
std::this_thread::sleep_for(std::chrono::minutes(5));
}
// WRONG - busy-waits, uses 100% CPU
while (true) {
Response notif = client.receiving.receiveNotification(5);
if (notif.body.contains("receiptId")) {
processNotification(notif);
}
// No delay!
}
✅ Fix:
while (true) {
Response notif = client.receiving.receiveNotification(5);
if (notif.body.contains("receiptId")) {
processNotification(notif);
client.receiving.deleteNotification(notif.body["receiptId"]);
}
// Add small delay even if no notification
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
| Code | Meaning | Solution |
|---|---|---|
401 Unauthorized | Bad API credentials | Check idInstance and apiTokenInstance |
403 Forbidden | Invalid instance state | Authorize instance with QR or phone |
400 Bad Request | Missing/invalid field | Check required fields for method |
404 Not Found | Invalid chat/group ID | Verify phone format: <number>@c.us or <number>-<ts>@g.us |
429 Too Many Requests | Rate limit exceeded | Increase delay between sends |
500 Server Error | API server issue | Retry after delay |
response.success and status codes@c.us, Groups=@g.usexamples/ directory in SDK repository# Clone and build SDK
git clone https://github.com/green-api/whatsapp-api-client-cpp.git
cd whatsapp-api-client-cpp
mkdir build && cd build
cmake ..
make
# Build example with your credentials
export GREEN_API_ID="your_id"
export GREEN_API_TOKEN="your_token"
g++ -std=c++17 -o sendMessage examples/sendMessage.cpp -L./build -lgreenapi -I./include
./sendMessage
Detailed method documentation:
Official Documentation: https://green-api.com/en/docs/api/
SDK Repository: https://github.com/green-api/whatsapp-api-client-cpp
Last Updated: 2024 SDK Version: Compatible with latest from https://github.com/green-api/whatsapp-api-client-cpp Verification: All methods and class names verified against official SDK source code