feat: webhook option added for incoming messages

This commit is contained in:
iamatulsingh
2026-03-24 21:23:41 +01:00
parent 84a31a8ae8
commit b136334953
5 changed files with 55 additions and 15 deletions
+48
View File
@@ -555,6 +555,54 @@ func extractMediaInfo(msg *waE2E.Message) (mediaType string, filename string, ur
// Handle regular incoming messages with media support
func handleMessage(client *whatsmeow.Client, messageStore *MessageStore, msg *events.Message, logger waLog.Logger) {
go func() {
cfg, err := config.LoadConfig()
if err != nil {
return
}
defer func() {
if r := recover(); r != nil {
log.Println("Recovered in webhook goroutine:", r)
}
}()
if cfg.WebhookUrl == "" {
return
}
content := extractTextContent(msg.Message)
if content == "" {
return
}
payload := map[string]interface{}{
"chat_jid": msg.Info.Chat.String(),
"sender": msg.Info.Sender.User,
"content": extractTextContent(msg.Message),
"is_from_me": msg.Info.IsFromMe,
"timestamp": msg.Info.Timestamp.String(),
"push_name": msg.Info.PushName,
"is_group": strings.Contains(msg.Info.Chat.String(), "@g.us"),
"message_id": msg.Info.ID,
}
jsonData, err := json.Marshal(payload)
if err != nil {
log.Println("Webhook marshal error:", err)
return
}
resp, err := http.Post(
cfg.WebhookUrl,
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
log.Println("Webhook POST error:", err)
return
}
defer resp.Body.Close()
}()
chatJID := msg.Info.Chat.String()
sender := msg.Info.Sender.User