-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Demo project and OnGetQrCode parameters issues #91
Comments
OnGetQrCode is a component event.
then in the onGetQrCode event the image will be returned:
|
I couldn't understand much from your suggestion because I couldn't install WPP4Delphi design-time components (couldn't find any document for installation steps and Google translate didn't help me much). If I'm not wrong this suppose to get the benefit of component's event without the need to install it for design time. WPP.OnGetQrCode := procedure(Sender: TObject; const QrCode: string; AImage: TBitmap)
begin
imgQrCode.Picture.Assign(AImage);
end; But number of parameters is absolutely wrong. So if you please try help me with my very basic example to be able run WPP4Delphi. BTW, I couldn't run WPP4Delphi demo as well because it uses design-time components |
@DjotaHasse I modified my code based on your suggestion (without understand it well) but I get these errors:
This is my modified code: unit MaintForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
// WPP4Delphi units
uTWPPConnect.ConfigCEF, uTWPPConnect, uTWPPConnect.Constant, uTWPPConnect.JS,
uWPPConnectDecryptFile, JsonDataObjects,
uTWPPConnect.Console, uTWPPConnect.Diversos, uTWPPConnect.AdjustNumber,
uTWPPConnect.Config, uTWPPConnect.Classes,
uTWPPConnect.Emoticons;
type
TMainForm = class(TForm)
btnSendMessage: TButton;
edtPhoneNumber: TEdit;
memoMessage: TMemo;
lblStatus: TLabel;
imgQrCode: TImage;
procedure btnSendMessageClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
WPP: uTWPPConnect.TWPPConnect;
procedure UpdateStatus(Status: string);
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure TMainForm.FormCreate(Sender: TObject);
begin
{$IFDEF CEFCurrentVersion}
ShowMessage('CEFCurrentVersion is defined');
{$ELSE}
ShowMessage('CEFCurrentVersion is not defined');
{$ENDIF}
WPP := uTWPPConnect.TWPPConnect.Create(Self);
if not WPP.Auth(false) then
begin
WPP.FormQrCodeType := TFormQrCodeType(Ft_None);
WPP.FormQrCodeStart;
end;
WPP.OnGetQrCode := procedure(const Sender: TObject; const QrCode: TResultQRCodeClass)
begin
// imgQrCode.Picture.Assign(AImage);
imgQrCode.BeginUpdate;
try
imgQrCode.Bitmap := Base64ToBitmap(StrAfter(QrCode.AQrCode,'base64,'));
sleep(500);
imgQrCode.BringToFront;
imgQrCode.Repaint;
finally
// imgAguardeQrCode.Visible := imgQrCode.Bitmap.IsEmpty;
// lbAguardeQrCode.Visible := imgQrCode.Bitmap.IsEmpty;
// AnimaAguardeQrCode.Stop;
imgQrCode.EndUpdate;
end;
end;
UpdateStatus('Not Connected');
end;
procedure TMainForm.UpdateStatus(Status: string);
begin
lblStatus.Caption := 'Status: ' + Status;
end;
procedure TMainForm.btnSendMessageClick(Sender: TObject);
var
TargetNumber, MessageText: string;
begin
TargetNumber := edtPhoneNumber.Text + '@c.us';
MessageText := memoMessage.Lines.Text;
if WPP.Auth(True) then
begin
UpdateStatus('Connected');
WPP.Send(TargetNumber, MessageText);
end
else
begin
UpdateStatus('Authentication required. Please scan the QR code.');
ShowMessage('Authentication failed. Please scan the QR code.');
end;
end;
end. |
I tried something silly too. I implemented unit MaintForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
uTWPPConnect.ConfigCEF, uTWPPConnect, uTWPPConnect.Constant, uTWPPConnect.JS,
uWPPConnectDecryptFile, JsonDataObjects,
uTWPPConnect.Console, uTWPPConnect.Diversos, uTWPPConnect.AdjustNumber,
uTWPPConnect.Config, uTWPPConnect.Classes,
uTWPPConnect.Emoticons, System.NetEncoding;
type
TMainForm = class(TForm)
btnSendMessage: TButton;
edtPhoneNumber: TEdit;
memoMessage: TMemo;
lblStatus: TLabel;
imgQrCode: TImage;
procedure btnSendMessageClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure WPPGetQrCode(const Sender: TObject; const QrCode: TResultQRCodeClass);
function Base64ToBitmap(const Base64: string): TBitmap;
private
{ Private declarations }
WPP: uTWPPConnect.TWPPConnect;
procedure UpdateStatus(Status: string);
function ExtractBase64(const Input: string): string;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure TMainForm.FormCreate(Sender: TObject);
begin
{$IFDEF CEFCurrentVersion}
ShowMessage('CEFCurrentVersion is defined');
{$ELSE}
ShowMessage('CEFCurrentVersion is not defined');
{$ENDIF}
end;
procedure TMainForm.WPPGetQrCode(const Sender: TObject; const QrCode: TResultQRCodeClass);
begin
imgQrCode.Picture.Bitmap.Canvas.Lock;
try
imgQrCode.Picture.Bitmap := Base64ToBitmap(ExtractBase64(QrCode.AQrCode));
Sleep(500);
imgQrCode.BringToFront;
imgQrCode.Repaint;
finally
imgQrCode.Picture.Bitmap.Canvas.Unlock;
end;
end;
function TMainForm.Base64ToBitmap(const Base64: string): TBitmap;
var
InputStream: TStringStream;
OutputStream: TMemoryStream;
begin
Result := TBitmap.Create;
InputStream := TStringStream.Create(Base64);
OutputStream := TMemoryStream.Create;
try
TNetEncoding.Base64.Decode(InputStream, OutputStream);
OutputStream.Position := 0;
Result.LoadFromStream(OutputStream);
finally
InputStream.Free;
OutputStream.Free;
end;
end;
procedure TMainForm.UpdateStatus(Status: string);
begin
lblStatus.Caption := 'Status: ' + Status;
end;
procedure TMainForm.btnSendMessageClick(Sender: TObject);
var
TargetNumber, MessageText: string;
begin
// ShowMessage('hi');
WPP := uTWPPConnect.TWPPConnect.Create(Self);
if not WPP.Auth(false) then
begin
WPP.FormQrCodeType := TFormQrCodeType(Ft_None);
WPP.FormQrCodeStart;
end;
WPP.OnGetQrCode := WPPGetQrCode;
UpdateStatus('Not Connected');
TargetNumber := edtPhoneNumber.Text + '@c.us';
MessageText := memoMessage.Lines.Text;
if WPP.Auth(True) then
begin
UpdateStatus('Connected');
WPP.Send(TargetNumber, MessageText);
end
else
begin
UpdateStatus('Authentication required. Please scan the QR code.');
ShowMessage('Authentication failed. Please scan the QR code.');
end;
end;
function TMainForm.ExtractBase64(const Input: string): string;
begin
Result := Copy(Input, Pos('base64,', Input) + 7, Length(Input));
end;
end. |
In Project >> View Sorce, add:
|
It's not inside options, it's Project >> View Source |
Create the component and set OnGetQrcode in the create form to test |
I wonder why you closed this issue while it related to #92 ?! |
I reopened this issue, give more details than you need, it seems to me that you are not using it in the traditional way, you are creating in run time, adding and taking parts of the component, for this I will tag someone who is using it this way, which is a little different from the use of most developers, who use the component |
Did it (I finally became able to install WPP4Delphi). here is my recent modification: unit MaintForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
JsonDataObjects, System.NetEncoding,
uTWPPConnect.ConfigCEF, uTWPPConnect, uTWPPConnect.Constant, uTWPPConnect.JS,
uWPPConnectDecryptFile,
uTWPPConnect.Console, uTWPPConnect.Diversos, uTWPPConnect.AdjustNumber,
uTWPPConnect.Config, uTWPPConnect.Classes,
uTWPPConnect.Emoticons;
type
TMainForm = class(TForm)
btnSendMessage: TButton;
edtPhoneNumber: TEdit;
memoMessage: TMemo;
lblStatus: TLabel;
imgQrCode: TImage;
WPP: TWPPConnect;
procedure btnSendMessageClick(Sender: TObject);
function Base64ToBitmap(const Base64: string): TBitmap;
procedure WPPGetQrCode(const Sender: TObject;
const QrCode: TResultQRCodeClass);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure UpdateStatus(Status: string);
function ExtractBase64(const Input: string): string;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
function TMainForm.Base64ToBitmap(const Base64: string): TBitmap;
var
InputStream: TStringStream;
OutputStream: TMemoryStream;
begin
Result := TBitmap.Create;
InputStream := TStringStream.Create(Base64);
OutputStream := TMemoryStream.Create;
try
TNetEncoding.Base64.Decode(InputStream, OutputStream);
OutputStream.Position := 0;
Result.LoadFromStream(OutputStream);
finally
InputStream.Free;
OutputStream.Free;
end;
end;
procedure TMainForm.UpdateStatus(Status: string);
begin
lblStatus.Caption := 'Status: ' + Status;
end;
procedure TMainForm.WPPGetQrCode(const Sender: TObject;
const QrCode: TResultQRCodeClass);
begin
imgQrCode.Picture.Bitmap.Canvas.Lock;
try
imgQrCode.Picture.Bitmap := Base64ToBitmap(ExtractBase64(QrCode.AQrCode));
Sleep(500);
imgQrCode.BringToFront;
imgQrCode.Repaint;
finally
imgQrCode.Picture.Bitmap.Canvas.Unlock;
end;
end;
procedure TMainForm.btnSendMessageClick(Sender: TObject);
var
TargetNumber, MessageText: string;
begin
if not Assigned(WPP) then
WPP := TWPPConnect.Create(Self); // Ensure the WPP instance is created
if not WPP.Auth(false) then
begin
WPP.FormQrCodeType := TFormQrCodeType(Ft_None);
WPP.FormQrCodeStart();
end;
UpdateStatus('Not Connected');
TargetNumber := edtPhoneNumber.Text + '@c.us';
MessageText := memoMessage.Lines.Text;
if WPP.Auth(True) then
begin
UpdateStatus('Connected');
WPP.Send(TargetNumber, MessageText);
end
else
begin
UpdateStatus('Authentication required. Please scan the QR code.');
ShowMessage('Authentication failed. Please scan the QR code.');
end;
end;
function TMainForm.ExtractBase64(const Input: string): string;
begin
Result := Copy(Input, Pos('base64,', Input) + 7, Length(Input));
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
WPP.OnGetQrCode := WPPGetQrCode;
end;
end. You can find the full project here: SimpleDemo.zip |
@DjotaHasse as you can see in object WPP: TWPPConnect
InjectJS.AutoUpdateTimeOut = 10
InjectJS.JSURL =
'https://raw.githubusercontent.com/wppconnect-team/WPP4Delphi/mai' +
'n/Source/JS/js.abr'
InjectJS.DownloadJSType = DT_Indy
Config.AutoDelay = 1000
AjustNumber.LengthPhone = 8
AjustNumber.DDIDefault = 55
FormQrCodeType = Ft_Http
OnGetQrCode = WPPGetQrCode
Left = 304
Top = 224
end |
If you placed the component on the screen, it doesn't make sense for you to create the event at run time, click on the component, press F11, go to the events tab, double click on OnGetQrCode and that's it, problem solved. |
Another thing, the component has a demo folder with a project that is used as an operating parameter for devs who are starting to use it, run this demo and see if it works correctly. |
I already did as I quoted from BTW, I attached the simple project. May you please take a look into it? |
If you created the event directly through the component, you don't need to set the event at run time, remove this from your project: |
Crashes for unknown reason although I put all the dependencies in ConfTWPPConnect.ini [Path Defines]
Data User=C:\Executaveis\WPPConnectDemo\User Data
FrameWork=C:\Executaveis\WPPConnectDemo
Binary=C:\Executaveis\WPPConnectDemo
Locales=C:\Executaveis\WPPConnectDemo\locales
Cache=C:\Executaveis\WPPConnectDemo\cache
Log File=C:\Executaveis\WPPConnectDemo\LogTWppConnect\
Log Console=C:\Executaveis\WPPConnectDemo\LogTWppConnect\
GPU=1
Log Severity=0
Log Console Active=0
language=pt-BR
Auto Receiver attached=0
[TWPPConnect Comp]
TWPPConnect Versão=3.9.0.0
Caminho JS=https://raw.githubusercontent.com/wppconnect-team/WPP4Delphi/main/Source/JS/js.abr
CEF4 Versão=109.1.18.0
CHROME Versão=109.0.5414.120
Dlls=libcef.dll / chrome_elf.dll
Ultima interação=16/09/24 05:08:26
[Config]
AcceptLanguageList=pt-BR,pt-BR;q=0.9,en-US;q=0.8,en;q=0.7
SecondsMonitor=
SecondsMonitorNew=
Evento_msg_ack_change=
Evento_msg_revoke=
Evento_new_message=
Evento_new_reaction=
Evento_active_chat=
Evento_update_label=
Evento_presence_change=
Evento_group_participant_changed=
Evento_live_location_start=
Evento_order_payment_status=
[Informacao]
Aplicativo vinculado=C:\Executaveis\WPPConnectDemo\WPPConnectDemo.exe
Valor True=1
Valor False=0 The runtime files copied from:
|
Delete this file ini and recopile the project. |
Got this runtime error:
|
I belive this issue related to an old OpenSSL binaries. It seems WPP4Delphi uses OpenSSL 1.x.x while the valid one is 1.1.x or 3.x.x
How this demo runs in your machines while it uses deprecated ssl binaries?! |
Inside the component folder there is a folder with the openssl dlls, or you can go to the component properties, InjectJS - DownloadJSType and change it to DT_Rest |
Inside the DEMO folder there is the DLLs subfolder
What error occurs? This error is occurring when downloading the updated js.abr file. This error may also be occurring due to an operating system problem, it is important that it is updated to update the TLS protocol, this error is no longer due to the component. |
To overcome this error, in the InjectJS - AutoUpdate component property, change it from true to false so that the component will not try to download the js file, but this file always changes because it contains the js commands that are injected into the CEF for operation of the component, if it becomes very outdated, some commands stop working and you will have to update this file manually in your project folder. |
It's not because your Chrome opens webwhats that the component has the same behavior, the component uses a Chromium engine. |
It could be a firewall, antivirus, something on your network that could block this as well |
This project has a tiny community so there are no useful result on Google. I Googled a lot before asking my question and if you noticed this issue published since a while which means I reach to a dead end. |
did you add libeay32.dll and ssleay32.dll in your project's exe folder? |
Sure. I mentioned that before. |
Everything is disabled. I even successfully downloaded js manually using my Chrome browser. |
Hi,
I'm building my first basic example but I couldn't figure out the correct parameters of
OnGetQrCode
.I tried to use:
procedure(Sender: TObject; const QrCode: string; AImage: TBitmap)
but didn't work. May you please help me to fix it?
The text was updated successfully, but these errors were encountered: