Closed ekasetiawans closed 6 months ago
It's kinda hard to figure it out since you didn't provide more information about your case.
I just using simpel example whatsmeow in godoc, the conversation message has empty string
IINW, there's 2 type of text message in WhatsApp proto,
Conversation
& ExtendedTextMessage
Conversation
commonly used in regular chat message that doesn't use Disappearing timer and
then ExtendedTextMessage
is a rich text message that can containText
, Link preview, Ads, and other properties like quoting, forwarding, Expiration
(for disappearing timer) .
reff : https://pkg.go.dev/go.mau.fi/whatsmeow@v0.0.0-20240507080416-01b0547014dc/binary/proto#Message
So we need to check which the correct message type right?
So we need to check which the correct message type right?
Right.
You can use this function to check:
func hasTextMessage(msg *proto.Message) bool {
extendedMsg := msg.GetExtendedTextMessage()
return len(msg.GetConversation()) > 0 ||
len(extendedMsg.GetContextInfo().GetQuotedMessage().GetConversation()) > 0 ||
len(extendedMsg.GetText()) > 0
}
So we need to check which the correct message type right?
Right.
You can use this function to check:
func hasTextMessage(msg *proto.Message) bool { extendedMsg := msg.GetExtendedTextMessage() return len(msg.GetConversation()) > 0 || len(extendedMsg.GetContextInfo().GetQuotedMessage().GetConversation()) > 0 || len(extendedMsg.GetText()) > 0 }
Your Answer Worked For me after changing some code could be perfect
func GetMessageFromEvt(msg *waProto.Message) string {
extendedMsg := msg.GetExtendedTextMessage()
if len(msg.GetConversation()) > 0 {
return msg.GetConversation()
}
if len(extendedMsg.GetContextInfo().GetQuotedMessage().GetConversation()) > 0 {
return extendedMsg.GetContextInfo().GetQuotedMessage().GetConversation()
}
if len(extendedMsg.GetText()) > 0 {
return extendedMsg.GetText()
}
return ""
}
I’m facing issue that sometimes received message receiving a empty string. It’s only occured on some whatsapp account. Is there any explanation why this happen?