diff --git a/main.go b/main.go index 0d6d7238..a1a6ebe6 100755 --- a/main.go +++ b/main.go @@ -51,6 +51,7 @@ var ( logType = flag.String("logtype", "console", "Type of log output (console or json)") skipMedia = flag.Bool("skipmedia", false, "Do not attempt to download media in messages") osName = flag.String("osname", "Mac OS 10", "Connection OSName in Whatsapp") + platformType = flag.String("platformtype", "DESKTOP", "Device platform type (DESKTOP, IPAD, ANDROID_TABLET, IOS_PHONE, ANDROID_PHONE, etc.)") colorOutput = flag.Bool("color", false, "Enable colored output for console logs") sslcert = flag.String("sslcertificate", "", "SSL Certificate File") sslprivkey = flag.String("sslprivatekey", "", "SSL Certificate Private Key File") @@ -225,6 +226,11 @@ func main() { *osName = v } + // Override platformType from environment variable if set + if v := os.Getenv("SESSION_PLATFORM_TYPE"); v != "" { + *platformType = v + } + if *versionFlag { fmt.Printf("WuzAPI version %s\n", version) os.Exit(0) diff --git a/wmiau.go b/wmiau.go index f34012ac..d04136ec 100644 --- a/wmiau.go +++ b/wmiau.go @@ -366,6 +366,64 @@ func parseJID(arg string) (types.JID, bool) { } } +// getPlatformTypeEnum converts a platform type string to the corresponding DeviceProps enum +// Returns DESKTOP as default if the string doesn't match any known type +func getPlatformTypeEnum(platformType string) *waCompanionReg.DeviceProps_PlatformType { + platformType = strings.ToUpper(strings.TrimSpace(platformType)) + + switch platformType { + case "UNKNOWN": + return waCompanionReg.DeviceProps_UNKNOWN.Enum() + case "CHROME": + return waCompanionReg.DeviceProps_CHROME.Enum() + case "FIREFOX": + return waCompanionReg.DeviceProps_FIREFOX.Enum() + case "IE": + return waCompanionReg.DeviceProps_IE.Enum() + case "OPERA": + return waCompanionReg.DeviceProps_OPERA.Enum() + case "SAFARI": + return waCompanionReg.DeviceProps_SAFARI.Enum() + case "EDGE": + return waCompanionReg.DeviceProps_EDGE.Enum() + case "DESKTOP": + return waCompanionReg.DeviceProps_DESKTOP.Enum() + case "IPAD": + return waCompanionReg.DeviceProps_IPAD.Enum() + case "ANDROID_TABLET": + return waCompanionReg.DeviceProps_ANDROID_TABLET.Enum() + case "OHANA": + return waCompanionReg.DeviceProps_OHANA.Enum() + case "ALOHA": + return waCompanionReg.DeviceProps_ALOHA.Enum() + case "CATALINA": + return waCompanionReg.DeviceProps_CATALINA.Enum() + case "TCL_TV": + return waCompanionReg.DeviceProps_TCL_TV.Enum() + case "IOS_PHONE": + return waCompanionReg.DeviceProps_IOS_PHONE.Enum() + case "IOS_CATALYST": + return waCompanionReg.DeviceProps_IOS_CATALYST.Enum() + case "ANDROID_PHONE": + return waCompanionReg.DeviceProps_ANDROID_PHONE.Enum() + case "ANDROID_AMBIGUOUS": + return waCompanionReg.DeviceProps_ANDROID_AMBIGUOUS.Enum() + case "WEAR_OS": + return waCompanionReg.DeviceProps_WEAR_OS.Enum() + case "AR_WRIST": + return waCompanionReg.DeviceProps_AR_WRIST.Enum() + case "AR_DEVICE": + return waCompanionReg.DeviceProps_AR_DEVICE.Enum() + case "UWP": + return waCompanionReg.DeviceProps_UWP.Enum() + case "VR": + return waCompanionReg.DeviceProps_VR.Enum() + default: + log.Warn().Str("platformType", platformType).Msg("Unknown platform type, defaulting to DESKTOP") + return waCompanionReg.DeviceProps_DESKTOP.Enum() + } +} + func (s *server) startClient(userID string, textjid string, token string, subscriptions []string) { log.Info().Str("userid", userID).Str("jid", textjid).Msg("Starting websocket connection to Whatsapp") @@ -407,7 +465,7 @@ func (s *server) startClient(userID string, textjid string, token string, subscr // Now we can use the client with the manager clientManager.SetWhatsmeowClient(userID, client) - store.DeviceProps.PlatformType = waCompanionReg.DeviceProps_DESKTOP.Enum() + store.DeviceProps.PlatformType = getPlatformTypeEnum(*platformType) store.DeviceProps.Os = osName mycli := MyClient{client, 1, userID, token, subscriptions, s.db, s}