Browse Source

fix: parse lid properly in groups

pull/291/head
almogbaku 9 months ago
parent
commit
32289d878a
No known key found for this signature in database GPG Key ID: 66C92B1C5B475512
  1. 17
      src/infrastructure/whatsapp/webhook.go

17
src/infrastructure/whatsapp/webhook.go

@ -43,15 +43,26 @@ func createPayload(ctx context.Context, evt *events.Message) (map[string]interfa
if from := evt.Info.SourceString(); from != "" {
body["from"] = from
if strings.HasSuffix(body["from"].(string), "@lid") {
body["from_lid"] = body["from"]
jid, _ := types.ParseJID(body["from"].(string))
from_user, from_group := from, ""
if strings.Contains(" in ", from) {
from_user = strings.Split(from, " in ")[0]
from_group = strings.Split(from, " in ")[1]
}
if strings.HasSuffix(from_user, "@lid") {
body["from_lid"] = from_user
jid, _ := types.ParseJID(from_user)
pn, _ := cli.Store.LIDs.GetPNForLID(context.Background(), jid)
if !pn.IsEmpty() {
if from_group != "" {
body["from"] = fmt.Sprintf("%s in %s", pn.String(), from_group)
} else {
body["from"] = pn.String()
}
}
}
}
if message.ID != "" {
body["message"] = message
}

Loading…
Cancel
Save