Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

feat: auto detect whatsapp account before send

Aldino Kemalcf3f59a53b62
diff --git a/src/pkg/whatsapp/whatsapp.go b/src/pkg/whatsapp/whatsapp.go
index 20eb02a6..b0043db7 100644
--- a/src/pkg/whatsapp/whatsapp.go
+++ b/src/pkg/whatsapp/whatsapp.go
@@ -116,8 +116,31 @@ func ParseJID(arg string) (types.JID, error) {
}
}
+func isOnWhatsapp(waCli *whatsmeow.Client, jid string) bool {
+ // only check if the jid a user with @s.whatsapp.net
+ if strings.Contains(jid, "@s.whatsapp.net") {
+ data, err := waCli.IsOnWhatsApp([]string{jid})
+ if err != nil {
+ panic(pkgError.InvalidJID(err.Error()))
+ }
+
+ for _, v := range data {
+ if !v.IsIn {
+ return false
+ }
+ }
+ }
+
+ return true
+}
+
func ValidateJidWithLogin(waCli *whatsmeow.Client, jid string) (types.JID, error) {
MustLogin(waCli)
+
+ if !isOnWhatsapp(waCli, jid) {
+ return types.JID{}, pkgError.InvalidJID(fmt.Sprintf("Phone %s is not on whatsapp", jid))
+ }
+
return ParseJID(jid)
}