Documentation
¶
Overview ¶
Package smsmap provides pure functions that map raw SMS and call-log fields to model.Document. It is shared by SMSCollector (XML backup parser) and the POST /api/v1/ingest/messages HTTP handler so that both sources produce structurally identical documents from the same input.
All functions are stateless and safe for concurrent use.
Index ¶
- Constants
- func BodyShortHash(body string) string
- func MapCall(number string, dateMs int64, durationSec int, typ int, contactName string) model.Document
- func MapSMS(addr, body string, dateMs int64, typ int, contactName string) model.Document
- func RedactPII(s string) string
- func ShortHash(s string) string
Constants ¶
const PIIRedactionToken = "[REDACTED]"
PIIRedactionToken is the placeholder inserted in place of detected structured PII. It matches the existing SMS OTP-redaction convention (see otpDigitsRe usage in MapSMS) so every source (SMS, call transcripts) surfaces the same redaction marker downstream.
Variables ¶
This section is empty.
Functions ¶
func BodyShortHash ¶
BodyShortHash returns an 8-character hex string of SHA-256(body) used to disambiguate SourceIDs when two messages share the same address and millisecond timestamp. Exported for use in tests that need to compute expected SourceIDs.
func MapCall ¶
func MapCall(number string, dateMs int64, durationSec int, typ int, contactName string) model.Document
MapCall maps raw call-log fields to a model.Document.
SourceID format: call-log:{dateMs}:{sha256(number)[:16]}:{sha256(durationStr)[:8]} Phone numbers (number) are hashed so raw PII is not stored in the SourceID. OccurredAt is time.UnixMilli(dateMs).UTC().
Parameters mirror the SMS Backup & Restore XML <call> element attributes and the POST /api/v1/ingest/messages JSON schema:
- number: phone number (will be hashed in SourceID)
- dateMs: Unix millisecond timestamp of the call
- durationSec: call duration in seconds
- typ: SMS Backup & Restore call type code (1=incoming, 2=outgoing, 3=missed, 4=voicemail, 5=rejected, 6=blocked)
- contactName: display name of the contact (may be empty; falls back to number)
func MapSMS ¶
MapSMS maps raw SMS fields to a model.Document.
SourceID format: sms:{dateMs}:{sha256(addr)[:16]}:{direction} Phone numbers (addr) are hashed so raw PII is not stored in the SourceID. direction (received/sent/draft/…) replaces the old bodyHash discriminator so that the SourceID is stable across body edits — enabling ON CONFLICT UPDATE (upsert) to overwrite content rather than inserting a duplicate document. Two messages from the same address at the same millisecond with different directions (e.g. a simultaneous inbound + outbound) are still uniquely identified because the direction segment differs. Auth-like bodies have their OTP digit runs replaced with [REDACTED]. OccurredAt is time.UnixMilli(dateMs).UTC().
Parameters mirror the SMS Backup & Restore XML <sms> element attributes and the POST /api/v1/ingest/messages JSON schema:
- addr: phone number / address (will be hashed in SourceID)
- body: message body (auth OTPs are redacted)
- dateMs: Unix millisecond timestamp of the message
- typ: SMS Backup & Restore type code (1=received, 2=sent, 3=draft, 4=outbox, 5=failed, 6=queued)
- contactName: display name of the contact (may be empty; falls back to addr)
func RedactPII ¶ added in v0.21.2
RedactPII replaces structured, regex-detectable PII in s with PIIRedactionToken:
- Korean resident registration numbers (RRN): \d{6}-\d{7}, plausibility- checked (see redactRRNIfPlausible).
- Korean phone numbers, domestic trunk-prefix form (see koreanPhoneRe) and international country-code form — with/without "+"/"0082", and with hyphen/space/dot separators (see koreanPhoneIntlPlusRe, koreanPhoneIntl00Re, koreanPhoneIntlBareRe).
- Bank-account-like hyphenated digit runs (see bankAccountRe).
- OTP/auth codes: 4-8 digit runs (the same pattern MapSMS uses) that appear near an authentication keyword (see redactAuthContextDigits).
Scope (issue #163, this release): regex-based structured PII only. Spoken-form phone numbers (e.g. "공일공에…") and NER-based name redaction are explicitly OUT of scope and deferred to a follow-up — both would require either a large hand-written grammar or a model/NER dependency, neither of which this pass introduces.
Scope (issue #167): only Korean (+82) country-code digit-form numbers are covered. Other countries' international numbers (e.g. "+1-...") are out of scope and are left untouched by these patterns — they simply don't match the literal "82"/"+82"/"0082" markers required here.
Order matters: RRN and phone patterns run before the bank-account pattern so that, e.g., a phone number's "010-1234-5678" hyphenated groups are already replaced with PIIRedactionToken (no longer digits) by the time the (structurally similar, 3-hyphenated-group) bank-account pattern runs, avoiding a confusing double-match. The OTP/auth pass runs last since it operates on whatever raw digit runs remain.
Types ¶
This section is empty.