CoolFace
Apppublic

sakthivikram/geo-location

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
SmsBroadcastService.java37 linesDownload Raw Back to service
1package com.georeport.service;2 3import org.springframework.beans.factory.annotation.Autowired;4import org.springframework.messaging.simp.SimpMessagingTemplate;5import org.springframework.stereotype.Service;6 7import java.time.LocalDateTime;8import java.time.format.DateTimeFormatter;9import java.util.HashMap;10import java.util.Map;11 12/**13 * Service to broadcast SMS messages to a WebSocket topic for developer testing.14 */15@Service16public class SmsBroadcastService {17 18    @Autowired19    private SimpMessagingTemplate messagingTemplate;20 21    private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");22 23    /**24     * Broadcast an SMS message to the /topic/dev-sms WebSocket topic.25     * @param to The recipient phone number26     * @param content The SMS message content27     */28    public void broadcastSms(String to, String content) {29        Map<String, String> payload = new HashMap<>();30        payload.put("to", to);31        payload.put("content", content);32        payload.put("timestamp", LocalDateTime.now().format(formatter));33        34        messagingTemplate.convertAndSend("/topic/dev-sms", payload);35    }36}37