add group message support to message send
This commit is contained in:
parent
64a5ab7999
commit
70c1cb5ea2
1 changed files with 16 additions and 7 deletions
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue