Files
BFNOC e25e0c8074 feat(notify): name the receiving SIM and device in SMS notifications
- Pass the receiving SIM's ICCID and IMSI from cellular and VoWiFi SMS to the notifier
- Add a local line with the stored number of that SIM, or its last four ICCID digits
- Show the device name next to its ID in SMS, call and IP change notifications
- Expose the local number as local_number in webhook meta and webhook and WeCom templates
- List the new placeholder in the notification settings
- Test the number, the ICCID fallback, device names and the webhook template
2026-10-14 13:25:48 +08:00

43 lines
965 B
Go

package device
import (
"strings"
"time"
"github.com/yibaiba/hideck/pkg/logger"
)
type InboundSMS struct {
DeviceID string
ICCID string
IMSI string
Sender string
Content string
Time time.Time
}
type InboundSMSHandler func(InboundSMS) error
func (p *Pool) OnInboundSMS(handler InboundSMSHandler) {
if p == nil || handler == nil {
return
}
p.inboundSMSHandlersMu.Lock()
p.inboundSMSHandlers = append(p.inboundSMSHandlers, handler)
p.inboundSMSHandlersMu.Unlock()
}
func (p *Pool) notifyInboundSMS(message InboundSMS) {
if p == nil || strings.TrimSpace(message.ICCID) == "" {
return
}
p.inboundSMSHandlersMu.RLock()
handlers := append([]InboundSMSHandler(nil), p.inboundSMSHandlers...)
p.inboundSMSHandlersMu.RUnlock()
for _, handler := range handlers {
if err := handler(message); err != nil {
logger.Warn("入站短信观察器处理失败", "device", message.DeviceID, "sender", message.Sender, "err", err)
}
}
}