|
|
@ -33,6 +33,7 @@ var ( |
|
|
WhatsAppClientProxyURL string |
|
|
WhatsAppClientProxyURL string |
|
|
WhatsAppUserAgentName string |
|
|
WhatsAppUserAgentName string |
|
|
WhatsAppUserAgentType string |
|
|
WhatsAppUserAgentType string |
|
|
|
|
|
WhatsAppPairAgentType whatsmeow.PairClientType |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func init() { |
|
|
func init() { |
|
|
@ -65,6 +66,8 @@ func init() { |
|
|
log.Print(nil).Fatal("Error Parse Environment Variable for WhatsApp Client User Agent Type") |
|
|
log.Print(nil).Fatal("Error Parse Environment Variable for WhatsApp Client User Agent Type") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
WhatsAppPairAgentType = WhatsAppGetPairAgent(WhatsAppUserAgentType) |
|
|
|
|
|
|
|
|
WhatsAppDatastore = datastore |
|
|
WhatsAppDatastore = datastore |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -139,10 +142,14 @@ func WhatsAppGetUserAgent(agentType string) waproto.DeviceProps_PlatformType { |
|
|
return waproto.DeviceProps_EDGE |
|
|
return waproto.DeviceProps_EDGE |
|
|
case "chrome": |
|
|
case "chrome": |
|
|
return waproto.DeviceProps_CHROME |
|
|
return waproto.DeviceProps_CHROME |
|
|
|
|
|
case "safari": |
|
|
|
|
|
return waproto.DeviceProps_SAFARI |
|
|
case "firefox": |
|
|
case "firefox": |
|
|
return waproto.DeviceProps_FIREFOX |
|
|
return waproto.DeviceProps_FIREFOX |
|
|
case "opera": |
|
|
case "opera": |
|
|
return waproto.DeviceProps_OPERA |
|
|
return waproto.DeviceProps_OPERA |
|
|
|
|
|
case "uwp": |
|
|
|
|
|
return waproto.DeviceProps_UWP |
|
|
case "aloha": |
|
|
case "aloha": |
|
|
return waproto.DeviceProps_ALOHA |
|
|
return waproto.DeviceProps_ALOHA |
|
|
case "tv-tcl": |
|
|
case "tv-tcl": |
|
|
@ -152,6 +159,27 @@ func WhatsAppGetUserAgent(agentType string) waproto.DeviceProps_PlatformType { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func WhatsAppGetPairAgent(agentType string) whatsmeow.PairClientType { |
|
|
|
|
|
switch strings.ToLower(agentType) { |
|
|
|
|
|
case "ie": |
|
|
|
|
|
return whatsmeow.PairClientIE |
|
|
|
|
|
case "edge": |
|
|
|
|
|
return whatsmeow.PairClientEdge |
|
|
|
|
|
case "chrome": |
|
|
|
|
|
return whatsmeow.PairClientChrome |
|
|
|
|
|
case "safari": |
|
|
|
|
|
return whatsmeow.PairClientSafari |
|
|
|
|
|
case "firefox": |
|
|
|
|
|
return whatsmeow.PairClientFirefox |
|
|
|
|
|
case "opera": |
|
|
|
|
|
return whatsmeow.PairClientOpera |
|
|
|
|
|
case "uwp": |
|
|
|
|
|
return whatsmeow.PairClientUWP |
|
|
|
|
|
default: |
|
|
|
|
|
return whatsmeow.PairClientOtherWebClient |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func WhatsAppGenerateQR(qrChan <-chan whatsmeow.QRChannelItem) (string, int) { |
|
|
func WhatsAppGenerateQR(qrChan <-chan whatsmeow.QRChannelItem) (string, int) { |
|
|
qrChanCode := make(chan string) |
|
|
qrChanCode := make(chan string) |
|
|
qrChanTimeout := make(chan int) |
|
|
qrChanTimeout := make(chan int) |
|
|
@ -216,19 +244,22 @@ func WhatsAppLogin(jid string) (string, int, error) { |
|
|
|
|
|
|
|
|
func WhatsAppPairPhone(jid string) (string, int, error) { |
|
|
func WhatsAppPairPhone(jid string) (string, int, error) { |
|
|
if WhatsAppClient[jid] != nil { |
|
|
if WhatsAppClient[jid] != nil { |
|
|
|
|
|
// Make Sure WebSocket Connection is Disconnected
|
|
|
WhatsAppClient[jid].Disconnect() |
|
|
WhatsAppClient[jid].Disconnect() |
|
|
|
|
|
|
|
|
if WhatsAppClient[jid].Store.ID == nil { |
|
|
if WhatsAppClient[jid].Store.ID == nil { |
|
|
// Connect WebSocket while also Initialize QR Code Data
|
|
|
|
|
|
|
|
|
// Connect WebSocket while also Requesting Pairing Code
|
|
|
err := WhatsAppClient[jid].Connect() |
|
|
err := WhatsAppClient[jid].Connect() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return "", 0, err |
|
|
return "", 0, err |
|
|
} |
|
|
} |
|
|
// Request pairing code
|
|
|
|
|
|
code, errp := WhatsAppClient[jid].PairPhone(jid, true, whatsmeow.PairClientChrome, "Chrome ("+WhatsAppUserAgentName+")") |
|
|
|
|
|
if errp != nil { |
|
|
|
|
|
return "", 0, errp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Request Pairing Code
|
|
|
|
|
|
code, err := WhatsAppClient[jid].PairPhone(jid, true, WhatsAppPairAgentType, WhatsAppUserAgentName) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", 0, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Set WhatsApp Client Presence to Available
|
|
|
// Set WhatsApp Client Presence to Available
|
|
|
_ = WhatsAppClient[jid].SendPresence(types.PresenceAvailable) |
|
|
_ = WhatsAppClient[jid].SendPresence(types.PresenceAvailable) |
|
|
|
|
|
|
|
|
|