From 70c1cb5ea27749c95c9c35bf4f1fd1028605a808 Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 1 Feb 2021 16:05:00 -0800 Subject: [PATCH] add group message support to message send --- .../cmd/message/send/send-message.go | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) 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") }