fwh\samples\whatsapp.prg
- Code: Select all Expand view RUN
- #include "FiveWin.ch"
#define ORANGES "https://www.jesmondfruitbarn.com.au/wp-content/uploads/2016/10/Jesmond-Fruit-Barn-Oranges.jpg"
function Main()
local cPhone := ""
local cMsg := "Hello"
if EDITVARS cPhone, cMsg
SendToWhatsApp( AllTrim( cPhone ), AllTrim( cMsg ), ;
{ "pdfharu1H.pdf", ; // document file
"..\bitmaps\007.bmp", ; // image file
ORANGES, ; // web image
"https://forums.fivetechsupport.com/" ; // url ref
} )
endif
return nil
Images from files and web (can be images from any source ) are displayed as images in the message body and other documents as attachments. Url refs are shown as url refs.
- Code: Select all Expand view RUN
- function SendToWhatsApp( cPhone, cMsg, aAttach )
local oShell
local aFiles := {}
local aOthers := {}
if Empty( cPhone ); return .f.; endif
DEFAULT cMsg := "Hello"
if !Empty( aAttach )
if !HB_ISARRAY( aAttach ); aAttach := { aAttach }; endif
AEval( aAttach, {|c| if( HB_ISSTRING( c ) .and. File( c ), ;
AAdd( aFiles, c ), AAdd( aOthers, c ) ) } )
endif
cMsg := StrTran( cMsg, CRLF, "%0D%0A" )
oShell := CreateObject( "WScript.Shell" )
ShellExecute( 0, "Open", "whatsapp://send?phone="+cPhone+"&text="+cMsg )
SysWait( 0.5 )
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("~")
return nil