add flag to attach files to outbound messages
This commit is contained in:
parent
7ed5558491
commit
033bb59c76
1 changed files with 15 additions and 1 deletions
|
@ -20,6 +20,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
|
@ -28,11 +29,13 @@ import (
|
|||
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/config"
|
||||
v0 "gitlab.com/signald/signald-go/signald/client-protocol/v0"
|
||||
"gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||
)
|
||||
|
||||
var (
|
||||
account string
|
||||
account string
|
||||
attachments []string
|
||||
|
||||
SendMessageCmd = &cobra.Command{
|
||||
Use: "send <group id | phone number> <message>",
|
||||
|
@ -56,6 +59,7 @@ var (
|
|||
req := v1.SendRequest{
|
||||
Username: account,
|
||||
MessageBody: strings.Join(args[1:], " "),
|
||||
Attachments: []*v0.JsonAttachment{},
|
||||
}
|
||||
|
||||
if strings.HasPrefix(args[0], "+") {
|
||||
|
@ -64,6 +68,15 @@ var (
|
|||
req.RecipientGroupID = args[0]
|
||||
}
|
||||
|
||||
for _, attachment := range attachments {
|
||||
path, err := filepath.Abs(attachment)
|
||||
if err != nil {
|
||||
log.Fatal("error resolving attachment", err)
|
||||
}
|
||||
log.Println(path)
|
||||
req.Attachments = append(req.Attachments, &v0.JsonAttachment{Filename: path})
|
||||
}
|
||||
|
||||
resp, err := req.Submit(common.Signald)
|
||||
if err != nil {
|
||||
log.Fatal("error sending request to signald: ", err)
|
||||
|
@ -121,4 +134,5 @@ var (
|
|||
|
||||
func init() {
|
||||
SendMessageCmd.Flags().StringVarP(&account, "account", "a", "", "local account to use")
|
||||
SendMessageCmd.Flags().StringSliceVarP(&attachments, "attachment", "A", []string{}, "attach a file to your outbound message. may be specified multiple times.")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue