From 8cebec67bc357a89c065a8756fb01dd4f37a5c30 Mon Sep 17 00:00:00 2001 From: almogbaku Date: Wed, 11 Jun 2025 23:51:53 +0300 Subject: [PATCH] fix: reuse ctx and better error handling --- src/infrastructure/whatsapp/webhook.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/infrastructure/whatsapp/webhook.go b/src/infrastructure/whatsapp/webhook.go index 9ae64fa..8244971 100644 --- a/src/infrastructure/whatsapp/webhook.go +++ b/src/infrastructure/whatsapp/webhook.go @@ -52,13 +52,20 @@ func createPayload(ctx context.Context, evt *events.Message) (map[string]interfa 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() + jid, 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) + if err != nil { + logrus.Errorf("Error when get pn for lid: %v", err) + } + if !pn.IsEmpty() { + if from_group != "" { + body["from"] = fmt.Sprintf("%s in %s", pn.String(), from_group) + } else { + body["from"] = pn.String() + } } } }