add group message support to message send

This commit is contained in:
Finn 2021-02-01 16:05:00 -08:00
parent 64a5ab7999
commit 70c1cb5ea2

View file

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