diff --git a/cmd/signaldctl/cmd/message/send/send-message.go b/cmd/signaldctl/cmd/message/send/send-message.go index 8fac4b4..cd95cca 100644 --- a/cmd/signaldctl/cmd/message/send/send-message.go +++ b/cmd/signaldctl/cmd/message/send/send-message.go @@ -20,6 +20,7 @@ import ( "fmt" "log" "os" + "strings" "github.com/jedib0t/go-pretty/v6/table" "github.com/spf13/cobra" @@ -49,11 +50,19 @@ var ( } }, Run: func(_ *cobra.Command, _ []string) { + go common.Signald.Listen(nil) + req := v1.SendRequest{ - Username: account, - MessageBody: message, - RecipientAddress: &v1.JsonAddress{Number: to}, + Username: account, + MessageBody: message, } + + if strings.HasPrefix(to, "+") { + req.RecipientAddress = &v1.JsonAddress{Number: to} + } else { + req.RecipientGroupID = to + } + resp, err := req.Submit(common.Signald) if err != nil { log.Fatal("error sending request to signald: ", err) @@ -78,8 +87,8 @@ var ( t.AppendRow(table.Row{ result.Address.Number, result.Address.UUID, - result.Success.Duration, - nil, + fmt.Sprintf("%dms", result.Success.Duration), + "", }) } else { var sendError string @@ -92,7 +101,7 @@ var ( if result.UnregisteredFailure { sendError = "not on" } - t.AppendRow(table.Row{result.Address.Number, result.Address.UUID, nil, sendError}) + t.AppendRow(table.Row{result.Address.Number, result.Address.UUID, "", sendError}) } } @@ -110,6 +119,6 @@ var ( func init() { SendMessageCmd.Flags().StringVarP(&account, "account", "a", "", "local account to use") - SendMessageCmd.Flags().StringVarP(&to, "to", "t", "", "account to send the message to") + SendMessageCmd.Flags().StringVarP(&to, "to", "t", "", "phone number or group ID to send the message to") SendMessageCmd.Flags().StringVarP(&message, "message", "m", "", "the body of the message to send") }