Skip to content

Commit

Permalink
listMessage: included sendlist test command at main.go;
Browse files Browse the repository at this point in the history
- send.go: changed at getButtonAttributes function the type forcing to use product_list instead of single_select for ListMessages.
  • Loading branch information
emacielxp committed Sep 8, 2023
1 parent 9278fde commit 0855777
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
37 changes: 37 additions & 0 deletions mdtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,43 @@ func handleCmd(cmd string, args []string) {
if err != nil {
log.Errorf("Error changing chat's pin state: %v", err)
}
case "sendlist":
if len(args) < 1 {
log.Errorf("Usage: sendlist <jid>")
return
}
recipient, ok := parseJID(args[0])
if !ok {
return
}
msg := &waProto.Message{
ListMessage: &waProto.ListMessage{
Description: proto.String("Description"),
ButtonText: proto.String("ButtonText"),
ListType: waProto.ListMessage_SINGLE_SELECT.Enum(),
Sections: []*waProto.ListMessage_Section{
{
Title: proto.String(""),
Rows: []*waProto.ListMessage_Row{
{
Title: proto.String("Row 1 title"),
RowId: proto.String("Row1"),
},
{
Title: proto.String("Row 2 title"),
RowId: proto.String("Row2"),
},
},
},
},
},
}
resp, err := cli.SendMessage(context.Background(), recipient, msg)
if err != nil {
log.Errorf("Error sending message: %v", err)
} else {
log.Infof("Message sent (server timestamp: %s)", resp.Timestamp)
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions send.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,9 @@ func getButtonAttributes(msg *waProto.Message) waBinary.Attrs {
return waBinary.Attrs{}
case msg.ListMessage != nil:
return waBinary.Attrs{
"v": "2",
"type": strings.ToLower(waProto.ListMessage_ListType_name[int32(msg.ListMessage.GetListType())]),
"v": "2",
// Force list message sent as product_list instead of single_select
"type": strings.ToLower(waProto.ListMessage_ListType_name[int32(*waProto.ListMessage_PRODUCT_LIST.Enum())]),
}
default:
return waBinary.Attrs{}
Expand Down

0 comments on commit 0855777

Please sign in to comment.