Skip to content

Commit

Permalink
msgconv/from-whatsapp: add support for placeholder messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Oct 14, 2024
1 parent d961ed1 commit cd1fee8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/msgconv/from-whatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions pkg/msgconv/wa-misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<hr/>This invitation to join "%s" expires at %s. Reply to this message with <code>%s accept</code> to accept the invite.`
const inviteMsgBroken = `%s<hr/>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"
Expand Down

0 comments on commit cd1fee8

Please sign in to comment.