From ff597f2ab98fc408b475867f8c8b5e8328c03750 Mon Sep 17 00:00:00 2001 From: Dimas Restu H Date: Wed, 25 Oct 2023 09:38:53 +0700 Subject: [PATCH] update fix pair agent name mus be in format Browser (OS) as stated in https://pkg.go.dev/go.mau.fi/whatsmeow#Client.PairPhone thanks to @aryo-sr and @ibnux --- pkg/whatsapp/whatsapp.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pkg/whatsapp/whatsapp.go b/pkg/whatsapp/whatsapp.go index 1e6092b..b2c78fa 100644 --- a/pkg/whatsapp/whatsapp.go +++ b/pkg/whatsapp/whatsapp.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "net/http" + "runtime" "strings" "github.com/PuerkitoBio/goquery" @@ -177,6 +178,29 @@ func WhatsAppGetPairAgent(agentType string) whatsmeow.PairClientType { } } +func WhatsAppGetPairName(agentType string) string { + var prefix string + switch agentType { + case "ie": + prefix = "Internet Explorer" + case "uwp": + prefix = "UWP" + default: + prefix = strings.Title(agentType) + } + + switch runtime.GOOS { + case "windows": + return prefix + "(Windows)" + case "darwin": + return prefix + "(macOS)" + case "linux": + return prefix + "(Linux)" + default: + return prefix + "(" + WhatsAppUserAgentName + ")" + } +} + func WhatsAppGenerateQR(qrChan <-chan whatsmeow.QRChannelItem) (string, int) { qrChanCode := make(chan string) qrChanTimeout := make(chan int) @@ -252,7 +276,7 @@ func WhatsAppLoginPair(jid string) (string, int, error) { } // Request Pairing Code - code, err := WhatsAppClient[jid].PairPhone(jid, true, WhatsAppGetPairAgent(WhatsAppUserAgentType), WhatsAppUserAgentName) + code, err := WhatsAppClient[jid].PairPhone(jid, true, WhatsAppGetPairAgent(WhatsAppUserAgentType), WhatsAppGetPairName(WhatsAppUserAgentType)) if err != nil { return "", 0, err }