Update to work with latest signald client protocol as of https://gitlab.com/thefinn93/signald/-/merge_requests/14

This commit is contained in:
Finn 2020-06-30 03:54:35 -07:00
parent 34a208588b
commit c3bfae8751
4 changed files with 71 additions and 39 deletions

View file

@ -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 {

View file

@ -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"`
}

View file

@ -15,26 +15,9 @@
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<String> attachmentFilenames;
public String uri;
public String groupName;
public List<String> 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 {
@ -42,20 +25,20 @@ type Request struct {
ID string `json:"id,omitempty"`
Username string `json:"username,omitempty"`
MessageBody string `json:"messageBody,omitempty"`
RecipientNumber string `json:"recipientNumber,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 []Attachment `json:"attachments,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"`

View file

@ -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