size_t WriteCallback(char* ptr, size_t size, size_t nmemb, std::string* data) {
data->append(ptr, size * nmemb);
return size * nmemb;
}
bool CheckWebhookValidity(const std::string& webhookUrl) {
CURL* curl;
CURLcode res;
std::string response;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, webhookUrl.c_str());
// Configurar para realizar una solicitud POST vacía
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "");
// Configurar el callback para obtener la respuesta
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
if (response.find("\"message\": \"Invalid Webhook Token\"") != std::string::npos || response.find("\"message\": \"Unknown Webhook\"") != std::string::npos) {
return false;
}
else {
return true;
}
}