Browse Source

fix: tags lid mapping

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

26
src/infrastructure/whatsapp/webhook.go

@ -7,6 +7,7 @@ import (
"fmt"
"go.mau.fi/whatsmeow/types"
"net/http"
"regexp"
"strings"
"time"
@ -52,13 +53,13 @@ func createPayload(ctx context.Context, evt *events.Message) (map[string]interfa
if strings.HasSuffix(from_user, "@lid") {
body["from_lid"] = from_user
jid, err := types.ParseJID(from_user)
lid, err := types.ParseJID(from_user)
if err != nil {
logrus.Errorf("Error when parse jid: %v", err)
} else {
pn, err := cli.Store.LIDs.GetPNForLID(ctx, jid)
pn, err := cli.Store.LIDs.GetPNForLID(ctx, lid)
if err != nil {
logrus.Errorf("Error when get pn for lid: %v", err)
logrus.Errorf("Error when get pn for lid %s: %v", lid.String(), err)
}
if !pn.IsEmpty() {
if from_group != "" {
@ -71,6 +72,25 @@ func createPayload(ctx context.Context, evt *events.Message) (map[string]interfa
}
}
if message.ID != "" {
tags := regexp.MustCompile(`\B@\w+`).FindAllString(message.Text, -1)
tagsMap := make(map[string]bool)
for _, tag := range tags {
tagsMap[tag] = true
}
for tag := range tagsMap {
lid, err := types.ParseJID(tag[1:] + "@lid")
if err != nil {
logrus.Errorf("Error when parse jid: %v", err)
} else {
pn, err := cli.Store.LIDs.GetPNForLID(ctx, lid)
if err != nil {
logrus.Errorf("Error when get pn for lid %s: %v", lid.String(), err)
}
if !pn.IsEmpty() {
message.Text = strings.Replace(message.Text, tag, fmt.Sprintf("@%s", pn.User), -1)
}
}
}
body["message"] = message
}
if pushname := evt.Info.PushName; pushname != "" {

Loading…
Cancel
Save