msgconv/from-whatsapp: add support for placeholder messages

This commit is contained in:
Tulir Asokan 2024-10-14 19:56:40 +03:00
parent d961ed1de7
commit cd1fee807e
2 changed files with 20 additions and 0 deletions

View file

@ -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:

View file

@ -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<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"