Auto-commit dev changes before merge via Dashboard

This commit is contained in:
RIT Services
2026-08-29 08:43:39 +00:00
parent 61659aa78d
commit f03a90d9d9

View File

@@ -24,6 +24,9 @@ public class WebhookController {
@Value("${whatsapp.phone-number-id:}") @Value("${whatsapp.phone-number-id:}")
private String configuredPhoneId; private String configuredPhoneId;
@Value("${whatsapp.dev-webhook-forward-url:}")
private String devWebhookUrl;
private final WhatsAppMessageService messageService; private final WhatsAppMessageService messageService;
private final SessionService sessionService; private final SessionService sessionService;
private final StudentMenuHandler studentMenuHandler; private final StudentMenuHandler studentMenuHandler;
@@ -81,12 +84,26 @@ public class WebhookController {
String incomingPhoneId = metadataNode.get("phone_number_id").asText(); String incomingPhoneId = metadataNode.get("phone_number_id").asText();
if (configuredPhoneId != null && !configuredPhoneId.trim().isEmpty() if (configuredPhoneId != null && !configuredPhoneId.trim().isEmpty()
&& !incomingPhoneId.trim().equals(configuredPhoneId.trim())) { && !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."); System.out.println("Incoming phone ID " + incomingPhoneId + " does not match configured ID " + configuredPhoneId + ". Ignoring webhook payload.");
return ResponseEntity.ok("EVENT_IGNORED"); return ResponseEntity.ok("EVENT_IGNORED");
} }
} }
} }
} }
}
if (valueNode != null && valueNode.has("messages") && valueNode.get("messages").isArray()) { if (valueNode != null && valueNode.has("messages") && valueNode.get("messages").isArray()) {
JsonNode messageNode = valueNode.get("messages").get(0); JsonNode messageNode = valueNode.get("messages").get(0);