@@ -216,7 +216,6 @@ func (cli *Client) handlePlaintextMessage(info *types.MessageInfo, node *waBinar
216
216
}
217
217
}
218
218
cli .dispatchEvent (evt .UnwrapRaw ())
219
- return
220
219
}
221
220
222
221
func (cli * Client ) decryptMessages (info * types.MessageInfo , node * waBinary.Node ) {
@@ -250,41 +249,33 @@ func (cli *Client) decryptMessages(info *types.MessageInfo, node *waBinary.Node)
250
249
} else if info .IsGroup && encType == "skmsg" {
251
250
decrypted , err = cli .decryptGroupMsg (& child , info .Sender , info .Chat )
252
251
} else if encType == "msmsg" && info .Sender .IsBot () {
253
- // Meta AI / other bots (biz?):
254
-
255
- // step 1: get message secret
256
252
targetSenderJID := info .MsgMetaInfo .TargetSender
253
+ messageSecretSenderJID := targetSenderJID
257
254
if targetSenderJID .User == "" {
258
- // if no targetSenderJID in <meta> this must be ourselves (one-one-one mode)
259
- targetSenderJID = cli .getOwnID ()
255
+ if info .Sender .Server == types .BotServer {
256
+ targetSenderJID = cli .Store .LID
257
+ } else {
258
+ targetSenderJID = cli .getOwnID ()
259
+ }
260
+ messageSecretSenderJID = cli .getOwnID ()
260
261
}
261
-
262
- messageSecret , err := cli . Store . MsgSecrets . GetMessageSecret ( info . Chat , targetSenderJID , info .MsgMetaInfo . TargetID )
263
- if err != nil || messageSecret == nil {
264
- cli . Log . Warnf ( "Error getting message secret for bot msg with id %s" , node . AttrGetter (). String ( "id" ))
265
- continue
262
+ var decryptMessageID string
263
+ if info . MsgBotInfo . EditType == types . EditTypeInner || info .MsgBotInfo . EditType == types . EditTypeLast {
264
+ decryptMessageID = info . MsgBotInfo . EditTargetID
265
+ } else {
266
+ decryptMessageID = info . ID
266
267
}
267
-
268
- // step 2: get MessageSecretMessage
269
- byteContents := child .Content .([]byte ) // <enc> contents
270
268
var msMsg waE2E.MessageSecretMessage
271
-
272
- err = proto .Unmarshal (byteContents , & msMsg )
273
- if err != nil {
274
- cli .Log .Warnf ("Error decoding MessageSecretMesage protobuf %v" , err )
275
- continue
276
- }
277
-
278
- // step 3: determine best message id for decryption
279
- var messageID string
280
- if info .MsgBotInfo .EditType == types .EditTypeInner || info .MsgBotInfo .EditType == types .EditTypeLast {
281
- messageID = info .MsgBotInfo .EditTargetID
269
+ var messageSecret []byte
270
+ if messageSecret , err = cli .Store .MsgSecrets .GetMessageSecret (info .Chat , messageSecretSenderJID , info .MsgMetaInfo .TargetID ); err != nil {
271
+ err = fmt .Errorf ("failed to get message secret for %s: %v" , info .MsgMetaInfo .TargetID , err )
272
+ } else if messageSecret == nil {
273
+ err = fmt .Errorf ("message secret for %s not found" , info .MsgMetaInfo .TargetID )
274
+ } else if err = proto .Unmarshal (child .Content .([]byte ), & msMsg ); err != nil {
275
+ err = fmt .Errorf ("failed to unmarshal MessageSecretMessage protobuf: %v" , err )
282
276
} else {
283
- messageID = info . ID
277
+ decrypted , err = cli . decryptBotMessage ( messageSecret , & msMsg , decryptMessageID , targetSenderJID , info )
284
278
}
285
-
286
- // step 4: decrypt and voila
287
- decrypted , err = cli .decryptBotMessage (messageSecret , & msMsg , messageID , targetSenderJID , info )
288
279
} else {
289
280
cli .Log .Warnf ("Unhandled encrypted message (type %s) from %s" , encType , info .SourceString ())
290
281
continue
@@ -294,7 +285,7 @@ func (cli *Client) decryptMessages(info *types.MessageInfo, node *waBinary.Node)
294
285
cli .Log .Warnf ("Error decrypting message from %s: %v" , info .SourceString (), err )
295
286
isUnavailable := encType == "skmsg" && ! containsDirectMsg && errors .Is (err , signalerror .ErrNoSenderKeyForUser )
296
287
// TODO figure out why @bot messages fail to decrypt
297
- if info .Chat .Server != types .BotServer {
288
+ if info .Chat .Server != types .BotServer && encType != "msmsg" {
298
289
go cli .sendRetryReceipt (node , info , isUnavailable )
299
290
}
300
291
cli .dispatchEvent (& events.UndecryptableMessage {
0 commit comments