Actually handle incoming text messages from Voip.ms
This commit is contained in:
parent
6a434c458d
commit
ef5d8168f0
2 changed files with 17 additions and 8 deletions
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
//"github.com/Gleipnir-Technology/nidus-sync/config"
|
//"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"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -91,6 +91,9 @@ func voipmsTextPost(w http.ResponseWriter, r *http.Request) {
|
||||||
if len(b.Data.Payload.To) > 0 {
|
if len(b.Data.Payload.To) > 0 {
|
||||||
to = b.Data.Payload.To[0].PhoneNumber
|
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")
|
fmt.Fprintf(w, "ok")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,13 @@ func ParsePhoneNumber(input string) (*E164, error) {
|
||||||
func StoreSources() error {
|
func StoreSources() error {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
for _, n := range []string{config.PhoneNumberReportStr, config.PhoneNumberSupportStr, config.VoipMSNumber} {
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to add number '%s' to DB: %w", n, err)
|
return fmt.Errorf("Failed to add number '%s' to DB: %w", n, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue