diff --git a/pkg/whatsapp/whatsapp.go b/pkg/whatsapp/whatsapp.go index 9e3c285..60d0914 100644 --- a/pkg/whatsapp/whatsapp.go +++ b/pkg/whatsapp/whatsapp.go @@ -27,6 +27,12 @@ import ( var WhatsAppDatastore *sqlstore.Container var WhatsAppClient = make(map[string]*whatsmeow.Client) +var ( + WhatsAppClientProxyURL string + WhatsAppUserAgentName string + WhatsAppUserAgentType string +) + func init() { var err error @@ -45,6 +51,18 @@ func init() { log.Print(nil).Fatal("Error Connect WhatsApp Client Datastore") } + WhatsAppClientProxyURL, _ = env.GetEnvString("WHATSAPP_CLIENT_PROXY_URL") + + WhatsAppUserAgentName, err = env.GetEnvString("WHATSAPP_USER_AGENT_NAME") + if err != nil { + log.Print(nil).Fatal("Error Parse Environment Variable for WhatsApp Client User Agent Name") + } + + WhatsAppUserAgentType, err = env.GetEnvString("WHATSAPP_USER_AGENT_TYPE") + if err != nil { + log.Print(nil).Fatal("Error Parse Environment Variable for WhatsApp Client User Agent Type") + } + WhatsAppDatastore = datastore } @@ -58,8 +76,8 @@ func WhatsAppInitClient(device *store.Device, jid string) { } // Set Client Properties - store.DeviceProps.Os = proto.String("Go WhatsApp Multi-Device REST") - store.DeviceProps.PlatformType = waproto.DeviceProps_DESKTOP.Enum() + store.DeviceProps.Os = proto.String(WhatsAppUserAgentName) + store.DeviceProps.PlatformType = WhatsAppGetUserAgent(WhatsAppUserAgentType).Enum() store.DeviceProps.RequireFullSync = proto.Bool(false) // Set Client Versions @@ -88,6 +106,45 @@ func WhatsAppInitClient(device *store.Device, jid string) { } } +func WhatsAppGetUserAgent(agentType string) waproto.DeviceProps_PlatformType { + switch strings.ToLower(agentType) { + case "desktop": + return waproto.DeviceProps_DESKTOP + case "mac": + return waproto.DeviceProps_CATALINA + case "android": + return waproto.DeviceProps_ANDROID_AMBIGUOUS + case "android-phone": + return waproto.DeviceProps_ANDROID_PHONE + case "andorid-tablet": + return waproto.DeviceProps_ANDROID_TABLET + case "ios-phone": + return waproto.DeviceProps_IOS_PHONE + case "ios-catalyst": + return waproto.DeviceProps_IOS_CATALYST + case "ipad": + return waproto.DeviceProps_IPAD + case "wearos": + return waproto.DeviceProps_WEAR_OS + case "ie": + return waproto.DeviceProps_IE + case "edge": + return waproto.DeviceProps_EDGE + case "chrome": + return waproto.DeviceProps_CHROME + case "firefox": + return waproto.DeviceProps_FIREFOX + case "opera": + return waproto.DeviceProps_OPERA + case "aloha": + return waproto.DeviceProps_ALOHA + case "tv-tcl": + return waproto.DeviceProps_TCL_TV + default: + return waproto.DeviceProps_UNKNOWN + } +} + func WhatsAppGenerateQR(qrChan <-chan whatsmeow.QRChannelItem) (string, int) { qrChanCode := make(chan string) qrChanTimeout := make(chan int) @@ -126,12 +183,12 @@ func WhatsAppLogin(jid string) (string, int, error) { return "", 0, err } - // Set WhatsApp Client Presence to Available - _ = WhatsAppClient[jid].SendPresence(types.PresenceAvailable) - // Get Generated QR Code and Timeout Information qrImage, qrTimeout := WhatsAppGenerateQR(qrChanGenerate) + // Set WhatsApp Client Presence to Available + _ = WhatsAppClient[jid].SendPresence(types.PresenceAvailable) + // Return QR Code in Base64 Format and Timeout Information return "data:image/png;base64," + qrImage, qrTimeout, nil } else {