Actually handle incoming text messages from Voip.ms

This commit is contained in:
Eli Ribble 2026-01-29 22:27:51 +00:00
parent 6a434c458d
commit ef5d8168f0
No known key found for this signature in database
2 changed files with 17 additions and 8 deletions

View file

@ -7,7 +7,7 @@ import (
"net/http"
//"github.com/Gleipnir-Technology/nidus-sync/config"
//"github.com/Gleipnir-Technology/nidus-sync/platform/text"
"github.com/Gleipnir-Technology/nidus-sync/platform/text"
"github.com/rs/zerolog/log"
)
@ -21,13 +21,13 @@ import (
"id": 101252305,
"record_type": "message",
"from": {
"phone_number": "+18016984649"
"phone_number": "+18016984649"
},
"to": [
{
"phone_number": "+15593720139",
"status": "webhook_delivered"
}
{
"phone_number": "+15593720139",
"status": "webhook_delivered"
}
],
"text": "test3",
"received_at": "2026-01-29T20:16:23.000000+00:00",
@ -91,6 +91,9 @@ func voipmsTextPost(w http.ResponseWriter, r *http.Request) {
if len(b.Data.Payload.To) > 0 {
to = b.Data.Payload.To[0].PhoneNumber
}
log.Info().Int("ID", b.Data.ID).Str("event_type", b.Data.EventType).Str("record_type", b.Data.RecordType).Str("from", b.Data.Payload.From.PhoneNumber).Str("to", to).Msg("Text status")
log.Info().Int("ID", b.Data.ID).Str("event_type", b.Data.EventType).Str("record_type", b.Data.RecordType).Str("from", b.Data.Payload.From.PhoneNumber).Str("to", to).Str("content", b.Data.Payload.Text).Msg("Text status")
// Convert phone numbers from Voip.ms into E164 format for consistency
go text.HandleTextMessage(b.Data.Payload.From.PhoneNumber, to, b.Data.Payload.Text)
fmt.Fprintf(w, "ok")
}

View file

@ -98,7 +98,13 @@ func ParsePhoneNumber(input string) (*E164, error) {
func StoreSources() error {
ctx := context.TODO()
for _, n := range []string{config.PhoneNumberReportStr, config.PhoneNumberSupportStr, config.VoipMSNumber} {
err := ensureInDB(ctx, n)
var err error
// Deal with Voip.ms not expecting API calls with the prefixed +1
if !strings.HasPrefix(n, "+1") {
err = ensureInDB(ctx, "+1"+n)
} else {
err = ensureInDB(ctx, n)
}
if err != nil {
return fmt.Errorf("Failed to add number '%s' to DB: %w", n, err)
}