WhatsApp tests
Posted: Wed Apr 17, 2024 3:55 am
Modesto Rocabado has shared with us this code to send messages and files using WhatsApp.
We do appreciate your tests and feedback to fine tune it. Many thanks!
We do appreciate your tests and feedback to fine tune it. Many thanks!
- Code: Select all Expand view
- FUNC SendToWhatsApp( cPhone, cMsg, aAttach )
LOCAL oShell, aFiles := {}, aOthers := {}, lRet
If (lRet := !Empty( cPhone ))
If !Empty( aAttach )
If( !HB_ISARRAY( aAttach ), aAttach := { aAttach }, )
AEval( aAttach, {|cFile| If( HB_ISSTRING( cFile ) .AND. File( cFile ), AAdd( aFiles, cFile), AAdd( aOthers, cFile ) ) } )
EndIf
cMsg := StrTran( cMsg, CRLF, "%0D%0A" )
oShell := CreateObject( "WScript.Shell" )
ShellExecute( 0, "Open", "whatsapp://send?phone="+cPhone+"&text="+cMsg)
SysWait( 0.2 )
If !Empty( aFiles )
If FW_CopyToClipBoard( aFiles, 15 )
SysWait( 2 )
oShell:SendKeys( "^v" )
SysWait( 1 )
EndIf
EndIf
AEval( aOthers, <|u|
If FW_CopyToClipBoard( u, 2 ) .OR. FW_CopyToClipBoard( u )
SysWait( 1 )
oShell:SendKeys( "^v" )
SysWait( 1 )
EndIf
RETURN NIL
> )
oShell:SendKeys("~")
EndIf
RETURN lRet