@@ -24,6 +24,8 @@ import (
24
24
"google.golang.org/protobuf/proto"
25
25
26
26
waBinary "go.mau.fi/whatsmeow/binary"
27
+ armadillo "go.mau.fi/whatsmeow/proto"
28
+ "go.mau.fi/whatsmeow/proto/waArmadilloApplication"
27
29
"go.mau.fi/whatsmeow/proto/waCommon"
28
30
"go.mau.fi/whatsmeow/proto/waConsumerApplication"
29
31
"go.mau.fi/whatsmeow/proto/waMsgApplication"
@@ -35,12 +37,13 @@ import (
35
37
const FBMessageVersion = 3
36
38
const FBMessageApplicationVersion = 2
37
39
const FBConsumerMessageVersion = 1
40
+ const FBArmadilloMessageVersion = 1
38
41
39
42
// SendFBMessage sends the given v3 message to the given JID.
40
43
func (cli * Client ) SendFBMessage (
41
44
ctx context.Context ,
42
45
to types.JID ,
43
- message * waConsumerApplication. ConsumerApplication ,
46
+ message armadillo. RealMessageApplicationSub ,
44
47
metadata * waMsgApplication.MessageApplication_Metadata ,
45
48
extra ... SendRequestExtra ,
46
49
) (resp SendResponse , err error ) {
@@ -51,9 +54,37 @@ func (cli *Client) SendFBMessage(
51
54
} else if len (extra ) == 1 {
52
55
req = extra [0 ]
53
56
}
54
- consumerMessage , err := proto .Marshal (message )
55
- if err != nil {
56
- err = fmt .Errorf ("failed to marshal consumer message: %w" , err )
57
+ var subproto waMsgApplication.MessageApplication_SubProtocolPayload
58
+ subproto .FutureProof = waCommon .FutureProofBehavior_PLACEHOLDER .Enum ()
59
+ switch typedMsg := message .(type ) {
60
+ case * waConsumerApplication.ConsumerApplication :
61
+ var consumerMessage []byte
62
+ consumerMessage , err = proto .Marshal (typedMsg )
63
+ if err != nil {
64
+ err = fmt .Errorf ("failed to marshal consumer message: %w" , err )
65
+ return
66
+ }
67
+ subproto .SubProtocol = & waMsgApplication.MessageApplication_SubProtocolPayload_ConsumerMessage {
68
+ ConsumerMessage : & waCommon.SubProtocol {
69
+ Payload : consumerMessage ,
70
+ Version : proto .Int32 (FBConsumerMessageVersion ),
71
+ },
72
+ }
73
+ case * waArmadilloApplication.Armadillo :
74
+ var armadilloMessage []byte
75
+ armadilloMessage , err = proto .Marshal (typedMsg )
76
+ if err != nil {
77
+ err = fmt .Errorf ("failed to marshal armadillo message: %w" , err )
78
+ return
79
+ }
80
+ subproto .SubProtocol = & waMsgApplication.MessageApplication_SubProtocolPayload_Armadillo {
81
+ Armadillo : & waCommon.SubProtocol {
82
+ Payload : armadilloMessage ,
83
+ Version : proto .Int32 (FBArmadilloMessageVersion ),
84
+ },
85
+ }
86
+ default :
87
+ err = fmt .Errorf ("unsupported message type %T" , message )
57
88
return
58
89
}
59
90
if metadata == nil {
@@ -65,15 +96,7 @@ func (cli *Client) SendFBMessage(
65
96
messageAppProto := & waMsgApplication.MessageApplication {
66
97
Payload : & waMsgApplication.MessageApplication_Payload {
67
98
Content : & waMsgApplication.MessageApplication_Payload_SubProtocol {
68
- SubProtocol : & waMsgApplication.MessageApplication_SubProtocolPayload {
69
- SubProtocol : & waMsgApplication.MessageApplication_SubProtocolPayload_ConsumerMessage {
70
- ConsumerMessage : & waCommon.SubProtocol {
71
- Payload : consumerMessage ,
72
- Version : proto .Int32 (FBConsumerMessageVersion ),
73
- },
74
- },
75
- FutureProof : waCommon .FutureProofBehavior_PLACEHOLDER .Enum (),
76
- },
99
+ SubProtocol : & subproto ,
77
100
},
78
101
},
79
102
Metadata : metadata ,
@@ -310,7 +333,20 @@ type messageAttrs struct {
310
333
PollType string
311
334
}
312
335
313
- func getAttrsFromFBMessage (msg * waConsumerApplication.ConsumerApplication ) (attrs messageAttrs ) {
336
+ func getAttrsFromFBMessage (msg armadillo.MessageApplicationSub ) (attrs messageAttrs ) {
337
+ switch typedMsg := msg .(type ) {
338
+ case * waConsumerApplication.ConsumerApplication :
339
+ return getAttrsFromFBConsumerMessage (typedMsg )
340
+ case * waArmadilloApplication.Armadillo :
341
+ attrs .Type = "media"
342
+ attrs .MediaType = "document"
343
+ default :
344
+ attrs .Type = "text"
345
+ }
346
+ return
347
+ }
348
+
349
+ func getAttrsFromFBConsumerMessage (msg * waConsumerApplication.ConsumerApplication ) (attrs messageAttrs ) {
314
350
switch payload := msg .GetPayload ().GetPayload ().(type ) {
315
351
case * waConsumerApplication.ConsumerApplication_Payload_Content :
316
352
switch content := payload .Content .GetContent ().(type ) {
0 commit comments