Get text messages for a contact and the phone status
Some checks failed
/ golint (push) Failing after 10s

This commit is contained in:
Eli Ribble 2026-05-23 00:47:37 +00:00
parent 5d03ab0844
commit 5b0d009353
No known key found for this signature in database
6 changed files with 86 additions and 5 deletions

View file

@ -58,9 +58,16 @@ func ContactsForOrganization(ctx context.Context, org_id int32) (results []types
phones := make([]types.Phone, len(contact_phones))
for i, p := range contact_phones {
phone := phones_by_e164[p.E164]
status := "unconfirmed"
if phone.StopMessageID != nil {
status = "stopped"
} else if phone.ConfirmedMessageID != nil {
status = "confirmed"
}
phones[i] = types.Phone{
E164: phone.E164,
CanSMS: phone.CanSms,
E164: phone.E164,
Status: status,
}
}
if row.Name != "" || len(contact_phones) > 0 || len(contact_emails) > 0 {

38
platform/message.go Normal file
View file

@ -0,0 +1,38 @@
package platform
import (
"context"
"errors"
"fmt"
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
querycomms "source.gleipnir.technology/Gleipnir/nidus-sync/db/query/comms"
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/types"
)
func MessagesForContact(ctx context.Context, contact_id int64) ([]types.Message, error) {
//emails, err := querycomms.EmailsFromContactID
txn := db.PGInstance.PGXPool
contact_phone, err := querycomms.ContactPhoneFromContactID(ctx, txn, contact_id)
if err != nil {
if errors.Is(err, db.ErrNoRows) {
return []types.Message{}, nil
}
return nil, fmt.Errorf("contact_phone from contact id %d: %w", contact_id, err)
}
texts, err := querycomms.TextLogsFromPhoneNumber(ctx, txn, contact_phone.E164)
if err != nil {
return nil, fmt.Errorf("text log from contact id %d: %w", contact_id, err)
}
results := make([]types.Message, len(texts))
for i, text := range texts {
results[i] = types.Message{
Content: text.Content,
Created: text.Created,
Destination: text.Destination,
Source: text.Source,
Type: types.MessageTypeText,
}
}
return results, err
}

22
platform/types/message.go Normal file
View file

@ -0,0 +1,22 @@
package types
import (
"time"
)
type MessageType int
const (
MessageTypeUnknown MessageType = iota
MessageTypeEmail
MessageTypeMailer
MessageTypeText
)
type Message struct {
Content string `json:"content"`
Created time.Time `json:"created"`
Destination string `json:"destination"`
Source string `json:"source"`
Type MessageType `json:"type"`
}