Configure Evolution webhook for bridge replies
This commit is contained in:
@@ -135,6 +135,36 @@ public final class EvolutionApiClient {
|
||||
return resp;
|
||||
}
|
||||
|
||||
public void configurarWebhookRespostas(String baseUrl, String instanceName, String webhookUrl, String webhookSecret) throws IOException, InterruptedException {
|
||||
if (baseUrl == null || baseUrl.isBlank()) {
|
||||
baseUrl = defaultBaseUrl;
|
||||
}
|
||||
if (mockMode(baseUrl) || webhookUrl == null || webhookUrl.isBlank()) return;
|
||||
Map<String, Object> headers = new LinkedHashMap<>();
|
||||
if (webhookSecret != null && !webhookSecret.isBlank()) headers.put("X-Webhook-Secret", webhookSecret);
|
||||
Map<String, Object> webhook = new LinkedHashMap<>();
|
||||
webhook.put("enabled", true);
|
||||
webhook.put("url", webhookUrl);
|
||||
webhook.put("webhook_by_events", false);
|
||||
webhook.put("webhook_base64", false);
|
||||
webhook.put("byEvents", false);
|
||||
webhook.put("base64", false);
|
||||
webhook.put("events", java.util.List.of("MESSAGES_UPSERT"));
|
||||
if (!headers.isEmpty()) webhook.put("headers", headers);
|
||||
Map<String, Object> payload = new LinkedHashMap<>();
|
||||
payload.put("webhook", webhook);
|
||||
HttpRequest req = HttpRequest.newBuilder(URI.create(clean(baseUrl) + "/webhook/set/" + instanceName))
|
||||
.timeout(Duration.ofSeconds(20))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("apikey", globalApiKey)
|
||||
.POST(HttpRequest.BodyPublishers.ofString(Json.write(payload)))
|
||||
.build();
|
||||
HttpResponse<String> resp = httpClient.send(req, HttpResponse.BodyHandlers.ofString());
|
||||
if (resp.statusCode() < 200 || resp.statusCode() >= 300) {
|
||||
throw new IOException("Evolution API retornou HTTP " + resp.statusCode() + ": " + resp.body());
|
||||
}
|
||||
}
|
||||
|
||||
public String enviarTexto(String baseUrl, String instanceName, String token, String numero, String texto) throws IOException, InterruptedException {
|
||||
if (baseUrl == null || baseUrl.isBlank()) {
|
||||
baseUrl = defaultBaseUrl;
|
||||
|
||||
Reference in New Issue
Block a user