forked from jshiffer/matterbridge
Check for Conversation on receiving messages (whatsapp)
This commit is contained in:
parent
21c4e56d16
commit
4da1444ffc
@ -46,44 +46,52 @@ func (b *Bwhatsapp) handleMessage(message *events.Message) {
|
|||||||
|
|
||||||
func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.Message) {
|
func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.Message) {
|
||||||
senderJID := messageInfo.Sender
|
senderJID := messageInfo.Sender
|
||||||
|
channel := messageInfo.Chat
|
||||||
|
|
||||||
senderName := b.getSenderName(messageInfo.Sender)
|
senderName := b.getSenderName(messageInfo.Sender)
|
||||||
if senderName == "" {
|
if senderName == "" {
|
||||||
senderName = "Someone" // don't expose telephone number
|
senderName = "Someone" // don't expose telephone number
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.GetExtendedTextMessage() == nil {
|
if msg.GetExtendedTextMessage() == nil && msg.GetConversation() == "" {
|
||||||
|
b.Log.Debugf("message without text content? %#v", msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
text := msg.GetExtendedTextMessage().GetText()
|
var text string
|
||||||
ci := msg.GetExtendedTextMessage().GetContextInfo()
|
|
||||||
|
|
||||||
if senderJID == (types.JID{}) && ci.Participant != nil {
|
if msg.GetExtendedTextMessage() == nil {
|
||||||
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
|
text = msg.GetConversation()
|
||||||
}
|
} else {
|
||||||
|
text = msg.GetExtendedTextMessage().GetText()
|
||||||
|
ci := msg.GetExtendedTextMessage().GetContextInfo()
|
||||||
|
|
||||||
if ci.MentionedJid != nil {
|
if senderJID == (types.JID{}) && ci.Participant != nil {
|
||||||
// handle user mentions
|
senderJID = types.NewJID(ci.GetParticipant(), types.DefaultUserServer)
|
||||||
for _, mentionedJID := range ci.MentionedJid {
|
}
|
||||||
numberAndSuffix := strings.SplitN(mentionedJID, "@", 2)
|
|
||||||
|
|
||||||
// mentions comes as telephone numbers and we don't want to expose it to other bridges
|
if ci.MentionedJid != nil {
|
||||||
// replace it with something more meaninful to others
|
// handle user mentions
|
||||||
mention := b.getSenderNotify(types.NewJID(numberAndSuffix[0], types.DefaultUserServer))
|
for _, mentionedJID := range ci.MentionedJid {
|
||||||
if mention == "" {
|
numberAndSuffix := strings.SplitN(mentionedJID, "@", 2)
|
||||||
mention = "someone"
|
|
||||||
|
// mentions comes as telephone numbers and we don't want to expose it to other bridges
|
||||||
|
// replace it with something more meaninful to others
|
||||||
|
mention := b.getSenderNotify(types.NewJID(numberAndSuffix[0], types.DefaultUserServer))
|
||||||
|
if mention == "" {
|
||||||
|
mention = "someone"
|
||||||
|
}
|
||||||
|
|
||||||
|
text = strings.Replace(text, "@"+numberAndSuffix[0], "@"+mention, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
text = strings.Replace(text, "@"+numberAndSuffix[0], "@"+mention, 1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rmsg := config.Message{
|
rmsg := config.Message{
|
||||||
UserID: senderJID.String(),
|
UserID: senderJID.String(),
|
||||||
Username: senderName,
|
Username: senderName,
|
||||||
Text: msg.GetExtendedTextMessage().GetText(),
|
Text: text,
|
||||||
Channel: ci.GetRemoteJid(),
|
Channel: channel.String(),
|
||||||
Account: b.Account,
|
Account: b.Account,
|
||||||
Protocol: b.Protocol,
|
Protocol: b.Protocol,
|
||||||
Extra: make(map[string][]interface{}),
|
Extra: make(map[string][]interface{}),
|
||||||
|
@ -324,14 +324,9 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
|
|||||||
|
|
||||||
message.Conversation = &text
|
message.Conversation = &text
|
||||||
|
|
||||||
/*
|
|
||||||
message.ExtendedTextMessage = &proto.ExtendedTextMessage{
|
|
||||||
Text: &text,
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
ID := whatsmeow.GenerateMessageID()
|
ID := whatsmeow.GenerateMessageID()
|
||||||
b.Log.Debugf("=> Sending %#v to %#v with ID %s", message, groupJID, ID)
|
|
||||||
|
b.Log.Debugf("=> Sending %#v", message)
|
||||||
|
|
||||||
_, err := b.wc.SendMessage(groupJID, ID, &message)
|
_, err := b.wc.SendMessage(groupJID, ID, &message)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user