Page 3 of 4

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Fri Oct 20, 2023 7:41 pm
by JoseAlvarez
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/

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Fri Oct 20, 2023 10:22 pm
by sysctrl2
creo que whatsendbot no tiene un API para programadores

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Tue Oct 24, 2023 11:25 pm
by carlos vargas
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...

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Wed Oct 25, 2023 1:31 am
by JoseAlvarez
Excelente Carlos.
Es bueno conocer todas la opciones.

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

Saludos!

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Thu Oct 26, 2023 9:05 pm
by nageswaragunupudi
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: Select all  Expand view
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.

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Thu Oct 26, 2023 10:58 pm
by cmsoft
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: Select all  Expand view

#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
 

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Fri Oct 27, 2023 4:56 am
by nageswaragunupudi
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: Select all  Expand view
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" )

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Fri Oct 27, 2023 4:59 am
by nageswaragunupudi
Now, can you please make a generic function to be used by all of us.
Code: Select all  Expand view
SendToWhatsApp( cPhone, cMessage, aFiles, aImages ) --> lSuccess

You may use any other name for the function.
I would also be interested in using the function..

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Fri Oct 27, 2023 1:06 pm
by cmsoft
Estimado Mr. Rao:
Esto es lo que pude lograr. Seguramente ud. podrá mejorarlo.
Hice pruebas y me funcionó para mi.
Code: Select all  Expand view

#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.
 

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Fri Oct 27, 2023 2:00 pm
by nageswaragunupudi
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: Select all  Expand view
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.

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Fri Oct 27, 2023 2:59 pm
by nageswaragunupudi
This worked for me
Code: Select all  Expand view
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
 

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Fri Oct 27, 2023 3:26 pm
by nageswaragunupudi
Further improved
Code: Select all  Expand view
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?

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Fri Oct 27, 2023 3:28 pm
by cmsoft
Excelente!!!! Mucho mejor!!!
Muchas gracias por compartirlo!

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Fri Oct 27, 2023 3:37 pm
by nageswaragunupudi
cmsoft wrote:Excelente!!!! Mucho mejor!!!
Muchas gracias por compartirlo!


I am asking your help to finalize this.

Re: enviar mensajes a whatsapp, ¿posible solucion?

PostPosted: Fri Oct 27, 2023 3:44 pm
by JoseAlvarez
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.