From d5e22b63f49284b765b5e7836fb43457d97546af Mon Sep 17 00:00:00 2001 From: Hariprasath S <113695067+Hariprasath4022@users.noreply.github.com> Date: Tue, 25 Aug 2026 18:51:44 +0530 Subject: [PATCH] Integrated Whatsapp message for volunteer registration --- .../controller/ApiController.java | 20 +- .../controller/VolunteerController.java | 30 +- .../service/VolunteerRegistrationService.java | 93 + src/main/resources/templates/index.html | 345 +++- src/main/resources/templates/index_tamil.html | 1808 +++++++++++++++++ src/main/resources/templates/webindex.html | 1788 ++++++++++++++++ .../resources/templates/webindex_tamil.html | 1787 ++++++++++++++++ 7 files changed, 5761 insertions(+), 110 deletions(-) create mode 100644 src/main/resources/templates/index_tamil.html create mode 100644 src/main/resources/templates/webindex.html create mode 100644 src/main/resources/templates/webindex_tamil.html diff --git a/src/main/java/com/volunteersregistration/controller/ApiController.java b/src/main/java/com/volunteersregistration/controller/ApiController.java index ad49f07..158ba34 100644 --- a/src/main/java/com/volunteersregistration/controller/ApiController.java +++ b/src/main/java/com/volunteersregistration/controller/ApiController.java @@ -86,11 +86,25 @@ public class ApiController { LocalDateTime now = LocalDateTime.now(); System.out.println(dtf.format(now)); - String generatedToken = "Welcome to GCC "+otp+" is your OTP for gcc QR System"; +// String generatedToken = "OTP for Volunteer "; // String key="qxg4mklD"; - String key="pfTEYN6H"; - String urlString= appConfig.getGetOtpUrl()+"from=GCCCRP&key="+key+"&sender=GCCCRP&to="+MobileNo+"&body="+generatedToken+"&entityid=1401572690000011081&templateid=1407168250479102852"; +// String key="pfTEYN6H"; + //String urlString= appConfig.getGetOtpUrl()+"from=GCCCRP&key="+key+"&sender=GCCCRP&to="+MobileNo+"&body="+generatedToken+"&entityid=1401572690000011081&templateid=1407168250479102852"; +// String urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + MobileNo +// + "&from=GCCCRP&body=OTP for Volunteer Registration " + otp +// + "\r\n- GCC&entityid=1401572690000011081&templateid=1407176491887361640"; // String urlString=appConfig.getGetOtpUrl()+"user=GCCtrans&authkey=92kOC1RBGBIws&sender=GCCCRP&mobile="+MobileNo+"&text="+generatedToken+"&rpt=1&summary=1&output=json&entityid=1401572690000011081&templateid=1407168250479102852"; + + String key = "pfTEYN6H"; + String entityId = "1401572690000011081"; + String templateId = "1407175765770900925"; + String appName = "Volunteer Registration"; + + String generatedMessage = "Welcome to GCC! Your OTP for " + appName + " is " + otp + "."; + String urlString = appConfig.getGetOtpUrl() + "from=GCCCRP" + "&key=" + key + "&sender=GCCCRP" + "&to=" + + MobileNo + "&body=" + + generatedMessage + "&entityid=" + entityId + "&templateid=" + templateId; + System.out.print("\n urlString---: "+urlString); String bodyMessage = ""; try { diff --git a/src/main/java/com/volunteersregistration/controller/VolunteerController.java b/src/main/java/com/volunteersregistration/controller/VolunteerController.java index b29b021..38cfc53 100644 --- a/src/main/java/com/volunteersregistration/controller/VolunteerController.java +++ b/src/main/java/com/volunteersregistration/controller/VolunteerController.java @@ -38,14 +38,42 @@ public class VolunteerController { @Autowired public VolunteerRegistrationService volunteerRegistrationService; + @GetMapping("/web") + public String registerweb(@RequestParam(required = false) String ref, Model model) { + System.out.println("indesx page....." + ref); + model.addAttribute("ref", ref); + + + return "webindex"; + } + + @GetMapping("/webtamil") + public String registerwebtamil(@RequestParam(required = false) String ref, Model model) { + System.out.println("indesx page....." + ref); + model.addAttribute("ref", ref); + + + return "webindex_tamil"; + } + @GetMapping(value = { "/", "", "/index" }) - public String register(@RequestParam(required = false) String ref, Model model) { + public String MobileViewregister(@RequestParam(required = false) String ref, Model model) { System.out.println("indesx page....." + ref); model.addAttribute("ref", ref); return "index"; } + + @GetMapping(value = {"/index_tamil" }) + public String MobileViewtamilregister(@RequestParam(required = false) String ref, Model model) { + System.out.println("indesx page....." + ref); + model.addAttribute("ref", ref); + + + return "index_tamil"; + } + // Check session and redirect to login if user is not logged in diff --git a/src/main/java/com/volunteersregistration/service/VolunteerRegistrationService.java b/src/main/java/com/volunteersregistration/service/VolunteerRegistrationService.java index 47201da..46fb243 100644 --- a/src/main/java/com/volunteersregistration/service/VolunteerRegistrationService.java +++ b/src/main/java/com/volunteersregistration/service/VolunteerRegistrationService.java @@ -9,6 +9,10 @@ import com.volunteersregistration.repository.VolunteerRegistrationRepo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; @@ -53,6 +57,10 @@ public class VolunteerRegistrationService { volun.setPreferred_zones(zones.toString()); } volun= volunteerRegistrationRepo.save(volun); + + sendWhatsappMsgENG(volun.getVolunteer_id(),volun.getMobile_no(),"GCC-VOL-"); + sendWhatsappMsgTam(volun.getVolunteer_id(),volun.getMobile_no(),"GCC-VOL-"); + return "VOL-"+String.format("%05d",volun.getVolunteer_id()); } else { return "Not Saved"; @@ -63,6 +71,83 @@ public class VolunteerRegistrationService { } return "error"; } + + private String sendWhatsappMsgTam(int id, Long mob_no,String prefix) { + String urlString = ""; + + + try { + + String placeholders = + URLEncoder.encode( + String.valueOf(prefix+id), + StandardCharsets.UTF_8.toString()); + + String mobile = + URLEncoder.encode( + String.valueOf(mob_no), + StandardCharsets.UTF_8.toString()); + + urlString="https://sendapiv1.pinbot.ai/pinwa/sendMessage?apikey=5c995535-6244-11f0-98fc-02c8a5e042bd&from=919445061913&to="+mobile+"&templateid=3688889&type=template&placeholders="+placeholders; + + + String res = hitURL(urlString); + return res; + + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + + } + + private String sendWhatsappMsgENG(int id, Long mob_no,String prefix) { + String urlString = ""; + + + try { + + String placeholders = + URLEncoder.encode( + String.valueOf(prefix+id), + StandardCharsets.UTF_8.toString()); + + String mobile = + URLEncoder.encode( + String.valueOf(mob_no), + StandardCharsets.UTF_8.toString()); + + urlString="https://sendapiv1.pinbot.ai/pinwa/sendMessage?apikey=5c995535-6244-11f0-98fc-02c8a5e042bd&from=919445061913&to="+mobile+"&templateid=3688885&type=template&placeholders="+placeholders; + + + String res = hitURL(urlString); + return res; + + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + + } + + private String hitURL(String urlString) { + String response = ""; + try { + URL url = new URL(urlString); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + + int responseCode = connection.getResponseCode(); + response = String.valueOf(responseCode); + System.out.println("Response Code for URL: " + urlString + " is " + responseCode); + + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("response=" + response); + return response; + } + public String registerAsNgo(NgoInformation ngo) { @@ -87,6 +172,10 @@ public class VolunteerRegistrationService { ngo.setPreferred_zones(zones.toString()); } ngo= ngoInfoRepo.save(ngo); + + sendWhatsappMsgENG(ngo.getNgo_id(),ngo.getMobileNo(),"GCC-NGO_VOL-"); + sendWhatsappMsgTam(ngo.getNgo_id(),ngo.getMobileNo(),"GCC-NGO_VOL-"); + return "NGO_VOL-"+String.format("%05d",ngo.getNgo_id()); } else { return "Not Saved"; @@ -120,6 +209,10 @@ public class VolunteerRegistrationService { cop.setPreferred_zones(zones.toString()); } cop= companyInfoRepo.save(cop); + + sendWhatsappMsgENG(cop.getCop_id(),cop.getContactPerMobile(),"GCC-COR_VOL-"); + sendWhatsappMsgTam(cop.getCop_id(),cop.getContactPerMobile(),"GCC-COR_VOL-"); + return "COR_VOL-"+String.format("%05d",cop.getCop_id()); } else { return "Not Saved"; diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index cbccc3e..a4786c7 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -20,6 +20,7 @@ + @@ -180,15 +232,15 @@
GREATER CHENNAI CORPORATION