diff --git a/cmd/signald-cli/cmd/send.go b/cmd/signald-cli/cmd/send.go index 3efd4ce..dbba3d7 100644 --- a/cmd/signald-cli/cmd/send.go +++ b/cmd/signald-cli/cmd/send.go @@ -21,6 +21,7 @@ import ( "github.com/spf13/cobra" "git.callpipe.com/finn/signald-go/signald" + "git.callpipe.com/finn/signald-go/signald/client-protocol/v1" ) var ( @@ -43,7 +44,7 @@ var sendCmd = &cobra.Command{ } if toUser != "" { - request.RecipientNumber = toUser + request.RecipientAddress = v1.JsonAddress{Number: toUser} } else if toGroup != "" { request.RecipientGroupID = toGroup } else { diff --git a/signald/client-protocol/v1/types.go b/signald/client-protocol/v1/types.go new file mode 100644 index 0000000..18929c0 --- /dev/null +++ b/signald/client-protocol/v1/types.go @@ -0,0 +1,44 @@ +package v1 + +// JsonAddress is a signal user's contact information. a phone number, UUID or both +type JsonAddress struct { + UUID string `json:"uuid"` + Number string `json:"number"` +} + +type JsonMessageRequestResponseMessage struct { + Person JsonAddress `json:"person"` + GroupID string `json:"groupId"` + Type string `json:"type"` +} + +type JsonReaction struct { + Emoji string `json:"emoji"` + Remove bool `json:"remove"` + TargetAuthor JsonAddress `json:"targetAuthor"` + TargetSentTimestamp uint64 `json:"targetSentTimestamp"` +} + +type JsonReadMessage struct { + Sender JsonAddress `json:"sender"` + Timestamp uint64 `json:"timestamp"` +} + +type JsonSendMessageResult struct { + Address JsonAddress `json:"address"` + Success Success `json:"success"` + NetworkFailure bool `json:"networkFailure"` + UnregisteredFailure bool `json:"unregisteredFailure"` + IdentityFailure string `json:"identityFailure"` +} + +type Success struct { + Unidentified bool `json:"unidentified"` + NeedsSync bool `json:"needsSync"` +} + +type RequestValidationFailure struct { + ValidationResults []string `json:"validationResults"` + Type string `json:"type"` + Message string `json:"message"` +} diff --git a/signald/signaldrequest.go b/signald/signaldrequest.go index fb622bd..b81d474 100644 --- a/signald/signaldrequest.go +++ b/signald/signaldrequest.go @@ -15,47 +15,30 @@ package signald -/* The class in signald: -class JsonRequest { - public String type; - public String id; - public String username; - public String messageBody; - public String recipientNumber; - public String recipientGroupId; - public Boolean voice; - public String code; - public String deviceName; - public List attachmentFilenames; - public String uri; - public String groupName; - public List members; - public String avatar; - - JsonRequest() {} -} -*/ +import ( + "git.callpipe.com/finn/signald-go/signald/client-protocol/v1" +) // Request represents a message sent to signald type Request struct { - Type string `json:"type"` - ID string `json:"id,omitempty"` - Username string `json:"username,omitempty"` - MessageBody string `json:"messageBody,omitempty"` - RecipientNumber string `json:"recipientNumber,omitempty"` - RecipientGroupID string `json:"recipientGroupId,omitempty"` - Voice bool `json:"voice,omitempty"` - Code string `json:"code,omitempty"` - DeviceName string `json:"deviceName,omitempty"` - AttachmentFilenames []string `json:"attachmentFilenames,omitempty"` - URI string `json:"uri,omitempty"` - Attachments []Attachment `json:"attachments,omitempty"` - GroupName string `json:"groupName,omitempty"` - Members []string `json:"members,omitempty"` - Avatar string `json:"avatar,omitempty"` + Type string `json:"type"` + ID string `json:"id,omitempty"` + Username string `json:"username,omitempty"` + MessageBody string `json:"messageBody,omitempty"` + RecipientAddress v1.JsonAddress `json:"recipientAddress,omitempty"` + RecipientGroupID string `json:"recipientGroupId,omitempty"` + Voice bool `json:"voice,omitempty"` + Code string `json:"code,omitempty"` + DeviceName string `json:"deviceName,omitempty"` + AttachmentFilenames []string `json:"attachmentFilenames,omitempty"` + URI string `json:"uri,omitempty"` + Attachments []JsonAttachment `json:"attachments,omitempty"` + GroupName string `json:"groupName,omitempty"` + Members []string `json:"members,omitempty"` + Avatar string `json:"avatar,omitempty"` } -type Attachment struct { +type JsonAttachment struct { Filename string `json:"filename"` Caption string `json:"caption"` Width int `json:"width"` diff --git a/signald/signaldresponse.go b/signald/signaldresponse.go index 22b23e1..064ec6c 100644 --- a/signald/signaldresponse.go +++ b/signald/signaldresponse.go @@ -1,5 +1,9 @@ package signald +import ( + "git.callpipe.com/finn/signald-go/signald/client-protocol/v1" +) + // Response is a response to a request to signald, or a new inbound message type Response struct { ID string @@ -15,9 +19,9 @@ type ResponseData struct { DataMessage DataMessage Message string Username string - Source string + Source v1.JsonAddress SourceDevice int - Type int + Type string IsReceipt bool Timestamp float64 ServerTimestamp float64