FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour enviar mensajes a whatsapp, ¿posible solucion?
Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Fri Oct 20, 2023 07:41 PM
sysctrl2 wrote:Solamente con algún API de paga? :?
lo ideal sería que se puedan enviar adjuntos
sin utilizar pulsaciones
saludos
https://www.whatsendbot.com/en/home/
"Los errores en programación, siempre están entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Fri Oct 20, 2023 10:22 PM

creo que whatsendbot no tiene un API para programadores

Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Tue Oct 24, 2023 11:25 PM

Yo estoy iniciando a trabajar con greenapi, tengo creada una clase la cual ya envía mensajes, y contacto, pero el envío de archivo se me está resistiendo un poco, nomás funcione, la pongo, greenapi es un servicio de paga, pero me parece accesible...

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Wed Oct 25, 2023 01:31 AM

Excelente Carlos.

Es bueno conocer todas la opciones.

Seguramente cada una tendrá su aplicación en determinado escenario.

Saludos!

"Los errores en programación, siempre están entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Thu Oct 26, 2023 09:05 PM
Aprobecho para consultarle a Mr. Rao:
Si tengo las imagenes en el XBrowse y quiero copiarlas al portapapeles para luego despues pegarlas en Whatsapp, como podría hacer?
Ejemplo, si tengo este arreglo:
Code (fw): Select all Collapse
function XbrCopyColumnImage( oCol )

   local aBmp
   local lRet  := .f.

   if IfNil( oCol:cDataType, " " ) $ "PF"
      aBmp  := FW_ReadImage( nil, oCol:Value, nil, .f. )
      if !Empty( aBmp[ 1 ] )
         GDIPLUSHBITMAPTOCLIPBOARD( aBmp[ 1 ], GetDeskTopWindow() )
         lRet  := .t.
         PalBmpFree( aBmp )
      endif
   endif

return lRet
Use this code for copying images to clipboard, not the traditional class/functions.
This can be pasted in whatsapp, word, excel, etc.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Thu Oct 26, 2023 10:58 PM
Muchas gracias Mr. Rao, funcionó perfecto. Ahora pude enviar imagenes y documentos adjuntos de una lista cargada en xbrowse.
Siempre agradecido por sus aportes!
Code (fw): Select all Collapse
#include "FiveWin.ch"
FUNCTION Main()
LOCAL oDlg1, oBrw, oBot1,;
      aCols := {;
{'54999999999','*Jose:*'+chr(13)+'Venezuela','https://forums.fivetechsupport.com/download/file.php?avatar=3176_1605719869.jpg',"c:\fwh21\samples\whatsapp.prg"},;
{'54999999999','*Mr. Rao:*'+chr(13)+'India','https://forums.fivetechsupport.com/download/file.php?avatar=868_1446686491.jpg',"c:\fwh21\samples\whatsapp1.prg"},;
{'54999999999','*Cesar:*'+chr(13)+'Argentina','https://forums.fivetechsupport.com/download/file.php?avatar=294_1327638239.jpg',"c:\fwh21\samples\whatsapp2.prg"}}
DEFINE DIALOG oDlg1 TITLE "Envio de whatsapp" SIZE 700,600 PIXEL TRUEPIXEL RESIZABLE
   @ 60, 20 XBROWSE oBrw SIZE 600,500 pixel OF oDlg1 ARRAY aCols  ;
      HEADERS "Telefono", "Texto","Imagen","Adjunto";
      COLUMNS 1,2,3,4;
      SIZES nil, 100,150,nil;
      CELL LINES NOBORDER
   WITH OBJECT oBrw
      :nRowHeight    := 150
      :aCols[3]:cDataType := "P"
      :CreateFromCode()
   END
@ 05,05 BUTTON oBot1 PROMPT "&Enviar" OF oDlg1 SIZE 100,40 ACTION Enviar(aCols,oBrw) PIXEL   
ACTIVATE DIALOG oDlg1 CENTERED 
RETURN nil


*--------------------------------------------------------------------------------
STATIC Function Enviar(aData, oBrw)
Local oShell, cTexto, i
oBrw:GoTop()
FOR i := 1 TO LEN(aData)  
   cTexto := aData[i,2]
   XbrCopyColumnImage(oBrw:aCols[3])
   cTexto := STRTRAN(cTexto," ","%20")
   cTexto := STRTRAN(cTexto,"&","%26")
   cTexto := STRTRAN(cTexto,chr(13),"%0D%0A")
   ShellExecute( 0, "open", "whatsapp://send?phone="+alltrim(aData[i,1])+"&text="+cTexto) 
   oShell := CreateObject( "WScript.Shell" )
   syswait(.2)   
   oShell:SendKeys( "~" )
   syswait(3)      
   oShell:SendKeys( "^v" )
   syswait(4)
   oShell:SendKeys("~")
   syswait(4)
   oShell:SendKeys("+{TAB}")
   syswait(.2)
   oShell:SendKeys("~")
   syswait(.2)
   oShell:SendKeys("{DOWN}")
   syswait(.2)
   oShell:SendKeys("~")  
   syswait(2)
   oShell:SendKeys(aData[i,4])
   syswait(.2)
   oShell:SendKeys("~")
   syswait(4)
   oShell:SendKeys("~")
   syswait(.2)
   oShell:SendKeys("{TAB}")
   oBrw:Skip()
NEXT i   
Return nil


function XbrCopyColumnImage( oCol )

   local aBmp
   local lRet  := .f.

   if IfNil( oCol:cDataType, " " ) $ "PF"
      aBmp  := FW_ReadImage( nil, oCol:Value, nil, .f. )
      if !Empty( aBmp[ 1 ] )
         GDIPLUSHBITMAPTOCLIPBOARD( aBmp[ 1 ], GetDeskTopWindow() )
         lRet  := .t.
         PalBmpFree( aBmp )
      endif
   endif

return lRet
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Fri Oct 27, 2023 04:56 AM
Good.
From now onwards please use this function to copy any image to clipboard.
Do not use any other existing functions and not even tclipboard class (till we improve in next version)
Code (fw): Select all Collapse
function CopyImageToClipboard( cImage )

   local hBitmap  := FW_ReadImage( nil, cImage, , .f. )[ 1 ]

   if !Empty( hBitmap )
      GDIPLUSHBITMAPTOCLIPBOARD( hBitmap, GetDeskTopWindow() )
      DeleteObject( hBitmap )
      return .t.
   endif

return .f.
The parameter cImage can be
1. Image file name. eg: "foto.jpg/png/bmp/..."
2. Web address of an image. eg. 'https://.....jpg"
3. Image buffer. eg. MemoRead( "foto.jpg" )
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Fri Oct 27, 2023 04:59 AM
Now, can you please make a generic function to be used by all of us.
Code (fw): Select all Collapse
SendToWhatsApp( cPhone, cMessage, aFiles, aImages ) --> lSuccess
You may use any other name for the function.
I would also be interested in using the function..
Regards



G. N. Rao.

Hyderabad, India
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Fri Oct 27, 2023 01:06 PM
Estimado Mr. Rao:
Esto es lo que pude lograr. Seguramente ud. podrá mejorarlo.
Hice pruebas y me funcionó para mi.
Code (fw): Select all Collapse
#include "FiveWin.ch"
FUNCTION Main()
//Whatsapp con mensaje por default "Hola"
SendToWhatsApp('5492324463274')
//Whatsapp con mensaje
SendToWhatsApp('5492324463274','*Estimado Mr. Rao'+chr(13)+'Esto es una prueba')
//Whatsapp con imagen y archivo adjunto
SendToWhatsApp('5492324463274','Esto es una prueba',;
               'c:\fwh21\samples\whatsapp2.prg',;
               'https://forums.fivetechsupport.com/download/file.php?avatar=294_1327638239.jpg')
//Whatsapp con array de imagenes y array de archivos adjuntos
SendToWhatsApp('5492324463274','Esto es una prueba',;
              {'c:\fwh21\samples\whatsapp2.prg','c:\fwh21\samples\whatsapp1.prg'},;
              {'https://forums.fivetechsupport.com/download/file.php?avatar=294_1327638239.jpg',;
               'https://forums.fivetechsupport.com/download/file.php?avatar=868_1446686491.jpg'})
RETURN nil


Function SendToWhatsApp( cPhone, cMessage, aFiles, aImages )
Local oShell, cTextFormated, i, cImage, cFile
Default cMessage := 'Hola'
oShell := CreateObject( "WScript.Shell" )
If cPhone == nil .or. empty(cPhone) 
   Return .f.
endif   
cTextFormated := cMessage
cTextFormated := STRTRAN(cTextFormated," ","%20")
cTextFormated := STRTRAN(cTextFormated,"&","%26")
cTextFormated := STRTRAN(cTextFormated,chr(13),"%0D%0A")
cTextFormated := STRTRAN(cTextFormated,chr(10),"%0D%0A")
// Primer envio el whatsapp comun 
ShellExecute( 0, "open", "whatsapp://send?phone="+alltrim(cPhone)+"&text="+cTextFormated) 
syswait(.5)   
oShell:SendKeys( "~" )
//Tercero me fijo si tiene adjuntos y los voy agregando
if !(aImages == nil)
   if ValType(aImages) == 'C'
      syswait(2)
      CopyImageToClipboard(aImages)
      oShell:SendKeys( "^v" )
      syswait(2)
      oShell:SendKeys("~")
      syswait(2)
      else 
      if ValType(aImages) == 'A'
         for each cImage in aImages
             syswait(2)
             CopyImageToClipboard(cImage)
             oShell:SendKeys( "^v" )
             syswait(2)
             oShell:SendKeys("~")
             syswait(4)
         next
      endif
   endif
endif
//Tercero me fijo si tiene adjuntos y los voy agregando
if !(aFiles == nil)
   if ValType(aFiles) == 'C'
      syswait(2)
      oShell:SendKeys("+{TAB}")
      syswait(.2)
      oShell:SendKeys("~")
      syswait(.2)
      oShell:SendKeys("{DOWN}")
      syswait(.2)
      oShell:SendKeys("~")  
      syswait(2)
      oShell:SendKeys(aFiles)
      syswait(.2)
      oShell:SendKeys("~")
      syswait(4)
      oShell:SendKeys("~")
      syswait(.2)
      oShell:SendKeys("{TAB}")
      syswait(2)
      else 
      if ValType(aFiles) == 'A'
         for each cFile in aFiles
               syswait(2)
               oShell:SendKeys("+{TAB}")
               syswait(.2)
               oShell:SendKeys("~")
               syswait(.2)
               oShell:SendKeys("{DOWN}")
               syswait(.2)
               oShell:SendKeys("~")  
               syswait(2)
               oShell:SendKeys(cFile)
               syswait(.2)
               oShell:SendKeys("~")
               syswait(2)
               oShell:SendKeys("~")
               syswait(.2)
               oShell:SendKeys("{TAB}")
               syswait(2)
         next
      endif
   endif
endif
return .t.

function CopyImageToClipboard( cImage )

   local hBitmap  := FW_ReadImage( nil, cImage, , .f. )[ 1 ]

   if !Empty( hBitmap )
      GDIPLUSHBITMAPTOCLIPBOARD( hBitmap, GetDeskTopWindow() )
      DeleteObject( hBitmap )
      return .t.
   endif

return .f.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Fri Oct 27, 2023 02:00 PM
Let me tell you one more thing.
If we want to attach any number of files on our disk we can also do this.
Note: Works with recent versions.

We can copy an array of files to clipboard. Each file name should be specified with full path. Full path is important.
Code (fw): Select all Collapse
FW_CopyToClipBoard( { FullName( cFile1 ), FullName( cFile2 ), ... } ) --> lSuccess

After this, press Ctrl-V in WhatsApp and then all files are attached. All at a time with only one click of Ctrl-V.

Image files are displayed as images and other files are shown as attachments.

Please try.

Note: In the next version, the function FW_CopyToClipboard( aFiles ) checks for existence of the files and also coverts them to fullpath using FullName() function.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Fri Oct 27, 2023 02:59 PM
This worked for me
Code (fw): Select all Collapse
function SendToWhatsApp( cPhone, cMsg, aFiles )

   local oShell

   // Aftere check params and format cMsg

   oShell := CreateObject( "WScript.Shell" )
   ShellExecute( 0, "Open", "whatsapp://send?phone="+cPhone+"&text="+cMsg )
   SysWait(2)
   if !Empty( aFiles )
      if HB_ISSTRING( aFiles ); aFiles := { aFiles }; endif
      FW_CopyToClipBoard( aFiles )
      SysWait( 2 )
      oShell:SendKeys( "^v" )
      SysWait( 2 )
   endif
   oShell:SendKeys("~")

return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Fri Oct 27, 2023 03:26 PM
Further improved
Code (fw): Select all Collapse
function SendToWhatsApp( cPhone, cMsg, aFiles, aImages )

   local oShell, tmp

   // Aftere check params and format cMsg

   oShell := CreateObject( "WScript.Shell" )
   ShellExecute( 0, "Open", "whatsapp://send?phone="+cPhone+"&text="+cMsg )
   SysWait(1)
   if !Empty( aFiles )
      if HB_ISSTRING( aFiles ); aFiles := { aFiles }; endif
      if !Empty( aImages )
         if !HG_ISARRAY( aImages ); aImages := { aImages }; endif
         tmp := {}
         AEval( aImages, { |c| If( File( c ), AAdd( aFiles, c ), AAdd( tmp, c ) ) } )
         aImages := tmp
      endif
      if FW_CopyToClipBoard( aFiles )
         SysWait( 2 )
         oShell:SendKeys( "^v" )
         SysWait( 2 )
      endif
      for each tmp in aImages
         if CopyImageToClipBoard( tmp ) // present vesion
//         if FW_CopyToClipBoard( tmp ) // FWH2310
            SysWait( 1 )
            oShell:SendKeys( "^v" )
         endif
      next
   endif
   oShell:SendKeys("~")

return nil
SysWait() times may need to be fine tuned.

Can you please check, comment and improve?
Regards



G. N. Rao.

Hyderabad, India
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Fri Oct 27, 2023 03:28 PM

Excelente!!!! Mucho mejor!!!

Muchas gracias por compartirlo!

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Fri Oct 27, 2023 03:37 PM
cmsoft wrote:Excelente!!!! Mucho mejor!!!
Muchas gracias por compartirlo!
I am asking your help to finalize this.
Regards



G. N. Rao.

Hyderabad, India
Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Re: enviar mensajes a whatsapp, ¿posible solucion?
Posted: Fri Oct 27, 2023 03:44 PM

Hola a todos, estimados colegas.

Excelente el aporte de todos para lograr integrar whatsapp como una herramienta a nuetras app.

¡Aplauso para todos uds!

Ahora bien, hay un tema que cosidero importante tener en cuenta y estudiar alguna manera de evitar un posible inconveniente:

WhatsApp podria banear la cuenta desde la cual se realizan los envíos, si el uso es continuo, de mucho volumen de mensajes o la cantidad de destinatarios sea grande, en cada ciclo de mensajes emitidos. Tal es el caso de mi aplicacion.

Sería bueno aportar ideas para prevenir esto.

Por los momentos, yo puse en mi app un ciclo de espera de 10sg cada 12 mensajes.

Quizas alla otras formas de ayudar a esto.

"Los errores en programación, siempre están entre la silla y el teclado..."



Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin



Carora, Estado Lara, Venezuela.