Merge development branch via Dashboard
This commit is contained in:
@@ -24,6 +24,9 @@ public class WebhookController {
|
||||
@Value("${whatsapp.phone-number-id:}")
|
||||
private String configuredPhoneId;
|
||||
|
||||
@Value("${whatsapp.dev-webhook-forward-url:}")
|
||||
private String devWebhookUrl;
|
||||
|
||||
private final WhatsAppMessageService messageService;
|
||||
private final SessionService sessionService;
|
||||
private final StudentMenuHandler studentMenuHandler;
|
||||
@@ -81,12 +84,26 @@ public class WebhookController {
|
||||
String incomingPhoneId = metadataNode.get("phone_number_id").asText();
|
||||
if (configuredPhoneId != null && !configuredPhoneId.trim().isEmpty()
|
||||
&& !incomingPhoneId.trim().equals(configuredPhoneId.trim())) {
|
||||
if (devWebhookUrl != null && !devWebhookUrl.trim().isEmpty()) {
|
||||
System.out.println("Incoming phone ID " + incomingPhoneId + " does not match configured ID " + configuredPhoneId + ". Forwarding to " + devWebhookUrl);
|
||||
try {
|
||||
org.springframework.web.client.RestTemplate tempTemplate = new org.springframework.web.client.RestTemplate();
|
||||
org.springframework.http.HttpHeaders headers = new org.springframework.http.HttpHeaders();
|
||||
headers.setContentType(org.springframework.http.MediaType.APPLICATION_JSON);
|
||||
org.springframework.http.HttpEntity<String> entity = new org.springframework.http.HttpEntity<>(payload, headers);
|
||||
tempTemplate.postForEntity(devWebhookUrl, entity, String.class);
|
||||
} catch (Exception forwardEx) {
|
||||
System.err.println("Failed to forward webhook to dev bot: " + forwardEx.getMessage());
|
||||
}
|
||||
return ResponseEntity.ok("EVENT_FORWARDED");
|
||||
} else {
|
||||
System.out.println("Incoming phone ID " + incomingPhoneId + " does not match configured ID " + configuredPhoneId + ". Ignoring webhook payload.");
|
||||
return ResponseEntity.ok("EVENT_IGNORED");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (valueNode != null && valueNode.has("messages") && valueNode.get("messages").isArray()) {
|
||||
JsonNode messageNode = valueNode.get("messages").get(0);
|
||||
|
||||
Reference in New Issue
Block a user