From cd1fee807e49770835b7ec93228bee6127480992 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 14 Oct 2024 19:56:40 +0300 Subject: [PATCH] msgconv/from-whatsapp: add support for placeholder messages --- pkg/msgconv/from-whatsapp.go | 2 ++ pkg/msgconv/wa-misc.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/msgconv/from-whatsapp.go b/pkg/msgconv/from-whatsapp.go index 998a3544..af5697f1 100644 --- a/pkg/msgconv/from-whatsapp.go +++ b/pkg/msgconv/from-whatsapp.go @@ -157,6 +157,8 @@ func (mc *MessageConverter) ToMatrix( part, contextInfo = mc.convertContactMessage(ctx, waMsg.ContactMessage) case waMsg.ContactsArrayMessage != nil: part, contextInfo = mc.convertContactsArrayMessage(ctx, waMsg.ContactsArrayMessage) + case waMsg.PlaceholderMessage != nil: + part, contextInfo = mc.convertPlaceholderMessage(ctx, waMsg) case waMsg.GroupInviteMessage != nil: part, contextInfo = mc.convertGroupInviteMessage(ctx, info, waMsg.GroupInviteMessage) case waMsg.ProtocolMessage != nil && waMsg.ProtocolMessage.GetType() == waE2E.ProtocolMessage_EPHEMERAL_SETTING: diff --git a/pkg/msgconv/wa-misc.go b/pkg/msgconv/wa-misc.go index 6d6b2fe3..fad51b92 100644 --- a/pkg/msgconv/wa-misc.go +++ b/pkg/msgconv/wa-misc.go @@ -26,6 +26,7 @@ import ( "github.com/rs/zerolog" "go.mau.fi/util/exerrors" + "go.mau.fi/util/ptr" "go.mau.fi/whatsmeow/proto/waE2E" "go.mau.fi/whatsmeow/types" "google.golang.org/protobuf/proto" @@ -54,6 +55,23 @@ func (mc *MessageConverter) convertUnknownMessage(ctx context.Context, msg *waE2 }, nil } +var otpContent = format.RenderMarkdown("You received a one-time passcode. For added security, you can only see it on your primary device for WhatsApp. [Learn more](https://faq.whatsapp.com/372839278914311)", true, false) + +func init() { + otpContent.MsgType = event.MsgNotice +} + +func (mc *MessageConverter) convertPlaceholderMessage(ctx context.Context, rawMsg *waE2E.Message) (*bridgev2.ConvertedMessagePart, *waE2E.ContextInfo) { + if rawMsg.GetPlaceholderMessage().GetType() == waE2E.PlaceholderMessage_MASK_LINKED_DEVICES { + return &bridgev2.ConvertedMessagePart{ + Type: event.EventMessage, + Content: ptr.Clone(&otpContent), + }, nil + } else { + return mc.convertUnknownMessage(ctx, rawMsg) + } +} + const inviteMsg = `%s
This invitation to join "%s" expires at %s. Reply to this message with %s accept to accept the invite.` const inviteMsgBroken = `%s
This invitation to join "%s" expires at %s. However, the invite message is broken or unsupported and cannot be accepted.` const GroupInviteMetaField = "fi.mau.whatsapp.invite"