Skip to content

Commit 003e406

Browse files
committed
Merge branch 'release/v3.3.0'
2 parents ac3d138 + 6da8016 commit 003e406

18 files changed

+2079
-1748
lines changed

Delphinus.Info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dependencies": [],
1313
"author": "M.E.Sysoev",
1414
"description": "Telegram Bot API for Delphi",
15-
"version": "3.1.1",
15+
"version": "3.3.0",
1616
"first_version": "2.3.1",
1717
"project_url": "https://github.com/ms301/TelegAPI",
1818
"homepage_url": "https://t.me/telegaPiBotTest",

Demo/Console/ConsoleBot.dproj

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
1414
<Base>true</Base>
1515
</PropertyGroup>
16-
<PropertyGroup Condition="('$(Platform)'=='Android' and '$(Base)'=='true') or '$(Base_Android)'!=''">
17-
<Base>true</Base>
18-
<CfgParent>Base</CfgParent>
19-
<Base_Android>true</Base_Android>
20-
</PropertyGroup>
2116
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
2217
<Base>true</Base>
2318
<CfgParent>Base</CfgParent>
@@ -53,17 +48,6 @@
5348
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
5449
<VerInfo_Locale>1049</VerInfo_Locale>
5550
</PropertyGroup>
56-
<PropertyGroup Condition="'$(Base_Android)'!=''">
57-
<Android_LauncherIcon144>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_144x144.png</Android_LauncherIcon144>
58-
<Android_LauncherIcon36>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_36x36.png</Android_LauncherIcon36>
59-
<Android_LauncherIcon48>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_48x48.png</Android_LauncherIcon48>
60-
<Android_LauncherIcon72>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_72x72.png</Android_LauncherIcon72>
61-
<Android_LauncherIcon96>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_96x96.png</Android_LauncherIcon96>
62-
<Android_SplashImage426>$(BDS)\bin\Artwork\Android\FM_SplashImage_426x320.png</Android_SplashImage426>
63-
<Android_SplashImage470>$(BDS)\bin\Artwork\Android\FM_SplashImage_470x320.png</Android_SplashImage470>
64-
<Android_SplashImage640>$(BDS)\bin\Artwork\Android\FM_SplashImage_640x480.png</Android_SplashImage640>
65-
<Android_SplashImage960>$(BDS)\bin\Artwork\Android\FM_SplashImage_960x720.png</Android_SplashImage960>
66-
</PropertyGroup>
6751
<PropertyGroup Condition="'$(Base_Win32)'!=''">
6852
<BT_BuildType>Debug</BT_BuildType>
6953
<DCC_ConsoleTarget>true</DCC_ConsoleTarget>
@@ -572,7 +556,6 @@
572556
<ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>
573557
</Deployment>
574558
<Platforms>
575-
<Platform value="Android">False</Platform>
576559
<Platform value="Win32">True</Platform>
577560
</Platforms>
578561
</BorlandProject>

Demo/EchoBot/EchoBot.Main.fmx

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,63 @@ object Main: TMain
22
Left = 0
33
Top = 0
44
Caption = 'Form1'
5-
ClientHeight = 319
6-
ClientWidth = 577
5+
ClientHeight = 409
6+
ClientWidth = 453
77
FormFactor.Width = 320
88
FormFactor.Height = 480
99
FormFactor.Devices = [Desktop]
10-
OnCreate = FormCreate
1110
OnClose = FormClose
1211
DesignerMasterStyle = 0
13-
object mmo1: TMemo
12+
object mmoLog: TMemo
1413
Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
1514
DataDetectorTypes = []
1615
Align = Client
17-
Size.Width = 577.000000000000000000
18-
Size.Height = 297.000000000000000000
16+
Size.Width = 453.000000000000000000
17+
Size.Height = 376.000000000000000000
1918
Size.PlatformDefault = False
2019
TabOrder = 2
21-
Viewport.Width = 573.000000000000000000
22-
Viewport.Height = 293.000000000000000000
20+
Viewport.Width = 449.000000000000000000
21+
Viewport.Height = 372.000000000000000000
2322
end
24-
object edt1: TEdit
25-
Touch.InteractiveGestures = [LongTap, DoubleTap]
23+
object Layout1: TLayout
2624
Align = Top
27-
TabOrder = 4
28-
Text = 'C:\Users\maks4\Desktop\1.json'
29-
Size.Width = 577.000000000000000000
30-
Size.Height = 22.000000000000000000
25+
Padding.Left = 5.000000000000000000
26+
Padding.Top = 5.000000000000000000
27+
Padding.Right = 5.000000000000000000
28+
Padding.Bottom = 5.000000000000000000
29+
Size.Width = 453.000000000000000000
30+
Size.Height = 33.000000000000000000
3131
Size.PlatformDefault = False
32-
TextPrompt = 'Debug. FilePath to JSON response'
33-
object btn1: TEditButton
34-
CanFocus = False
35-
Cursor = crArrow
36-
Size.Width = 76.000000000000000000
37-
Size.Height = 18.000000000000000000
32+
TabOrder = 4
33+
object lblToken: TLabel
34+
Align = Left
35+
Position.X = 5.000000000000000000
36+
Position.Y = 5.000000000000000000
37+
Size.Width = 44.000000000000000000
38+
Size.Height = 23.000000000000000000
39+
Size.PlatformDefault = False
40+
Text = 'Token: '
41+
end
42+
object edtToken: TEdit
43+
Touch.InteractiveGestures = [LongTap, DoubleTap]
44+
Align = Client
45+
TabOrder = 1
46+
Margins.Right = 5.000000000000000000
47+
Size.Width = 346.000000000000000000
48+
Size.Height = 23.000000000000000000
49+
Size.PlatformDefault = False
50+
TextPrompt = 'Token from @BotFather'
51+
end
52+
object swtchToken: TSwitch
53+
Align = Right
54+
IsChecked = False
55+
Position.X = 400.000000000000000000
56+
Position.Y = 5.000000000000000000
57+
Size.Width = 48.000000000000000000
58+
Size.Height = 23.000000000000000000
3859
Size.PlatformDefault = False
39-
TabOrder = 0
40-
Text = 'Apply'
41-
OnClick = btn1Click
60+
TabOrder = 2
61+
OnSwitch = swtchTokenSwitch
4262
end
4363
end
4464
object tgBot: TTelegramBot

Demo/EchoBot/EchoBot.Main.pas

Lines changed: 47 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,50 @@ interface
77
System.Types,
88
System.UITypes,
99
System.Classes,
10-
System.Variants,
1110
FMX.Types,
12-
FMX.Controls,
1311
FMX.Forms,
14-
FMX.Graphics,
1512
FMX.Dialogs,
16-
FMX.Controls.Presentation,
1713
FMX.Memo,
18-
FMX.ScrollBox,
1914
TelegAPI.Bot,
2015
TelegAPI.Types,
2116
TelegAPI.Exceptions,
17+
FMX.Edit,
2218
FMX.StdCtrls,
23-
FMX.Edit;
19+
FMX.Controls,
20+
FMX.Controls.Presentation,
21+
FMX.ScrollBox,
22+
FMX.Layouts;
2423

2524
type
2625
TMain = class(TForm)
2726
tgBot: TTelegramBot;
28-
mmo1: TMemo;
29-
edt1: TEdit;
30-
btn1: TEditButton;
31-
procedure FormCreate(Sender: TObject);
27+
mmoLog: TMemo;
28+
Layout1: TLayout;
29+
lblToken: TLabel;
30+
edtToken: TEdit;
31+
swtchToken: TSwitch;
3232
procedure tgBotInlineResultChosen(ASender: TObject; AChosenInlineResult: TtgChosenInlineResult);
3333
procedure tgBotInlineQuery(ASender: TObject; AInlineQuery: TtgInlineQuery);
34-
procedure tgBotMessage(ASender: TObject; AMessage: TtgMessage);
34+
procedure tgBotMessage(ASender: TObject; AMessage: TTgMessage);
3535
procedure tgBotCallbackQuery(ASender: TObject; ACallbackQuery: TtgCallbackQuery);
3636
procedure tgBotReceiveError(ASender: TObject; AApiRequestException: EApiRequestException);
3737
procedure tgBotConnect(Sender: TObject);
3838
procedure tgBotDisconnect(Sender: TObject);
3939
procedure FormClose(Sender: TObject; var Action: TCloseAction);
4040
procedure tgBotReceiveGeneralError(ASender: TObject; AException: Exception);
41-
procedure btn1Click(Sender: TObject);
41+
procedure swtchTokenSwitch(Sender: TObject);
4242
private
4343
{ Private declarations }
4444
procedure WriteLine(const AValue: string);
45-
procedure SendInline(Msg: TtgMessage);
46-
procedure SendKeyboard(Msg: TtgMessage);
47-
procedure SendPhoto(Msg: TtgMessage);
48-
procedure SendRequest(Msg: TtgMessage);
49-
procedure SendQuest(Msg: TtgMessage);
45+
procedure SendInline(Msg: TTgMessage);
46+
procedure SendKeyboard(Msg: TTgMessage);
47+
procedure SendPhoto(Msg: TTgMessage);
48+
procedure SendRequest(Msg: TTgMessage);
49+
procedure SendQuest(Msg: TTgMessage);
5050
// parsing
51-
procedure ParseTextMessage(Msg: TtgMessage);
52-
procedure ParsePhotoMessage(Msg: TtgMessage);
53-
procedure ParseLocationMessage(Msg: TtgMessage);
51+
procedure ParseTextMessage(Msg: TTgMessage);
52+
procedure ParsePhotoMessage(Msg: TTgMessage);
53+
procedure ParseLocationMessage(Msg: TTgMessage);
5454
public
5555
{ Public declarations }
5656
end;
@@ -69,35 +69,17 @@ implementation
6969
TelegAPI.Types.InputMessageContents;
7070
{$R *.fmx}
7171

72-
procedure TMain.btn1Click(Sender: TObject);
73-
var
74-
LJson: string;
75-
LReturn: TArray<TtgUpdate>;
76-
begin
77-
LJson := TFile.ReadAllText(edt1.Text, TEncoding.UTF8);
78-
LReturn := tgBot.ApiTest<TArray<TtgUpdate>>(LJson);
79-
end;
80-
8172
procedure TMain.FormClose(Sender: TObject; var Action: TCloseAction);
8273
begin
8374
tgBot.IsReceiving := False;
8475
end;
8576

86-
procedure TMain.FormCreate(Sender: TObject);
87-
begin
88-
ReportMemoryLeaksOnShutdown := True;
89-
tgBot.Token := {$I ..\token.inc};
90-
if not tgBot.IsValidToken then
91-
raise ELoginCredentialError.Create('invalid token format');
92-
tgBot.IsReceiving := True;
93-
end;
94-
95-
procedure TMain.ParseLocationMessage(Msg: TtgMessage);
77+
procedure TMain.ParseLocationMessage(Msg: TTgMessage);
9678
begin
9779
WriteLine('Location: ' + Msg.Location.Longitude.ToString + ' ' + Msg.Location.Latitude.ToString);
9880
end;
9981

100-
procedure TMain.ParsePhotoMessage(Msg: TtgMessage);
82+
procedure TMain.ParsePhotoMessage(Msg: TTgMessage);
10183
var
10284
LFile: TtgFile;
10385
begin
@@ -111,7 +93,7 @@ procedure TMain.ParsePhotoMessage(Msg: TtgMessage);
11193
end;
11294
end;
11395

114-
procedure TMain.ParseTextMessage(Msg: TtgMessage);
96+
procedure TMain.ParseTextMessage(Msg: TTgMessage);
11597
var
11698
usage: string;
11799
begin
@@ -147,7 +129,7 @@ procedure TMain.ParseTextMessage(Msg: TtgMessage);
147129
end;
148130
end;
149131

150-
procedure TMain.SendRequest(Msg: TtgMessage);
132+
procedure TMain.SendRequest(Msg: TTgMessage);
151133
var
152134
kb: IReplyMarkup;
153135
begin
@@ -157,13 +139,23 @@ procedure TMain.SendRequest(Msg: TtgMessage);
157139
tgBot.SendMessage(Msg.Chat.Id, 'Who or Where are you?', TtgParseMode.default, False, False, 0, kb).Free;
158140
end;
159141

160-
procedure TMain.SendPhoto(Msg: TtgMessage);
142+
procedure TMain.swtchTokenSwitch(Sender: TObject);
143+
begin
144+
tgBot.Token := edtToken.Text;
145+
if not tgBot.IsValidToken then
146+
raise ELoginCredentialError.Create('invalid token format');
147+
tgBot.IsReceiving := swtchToken.IsChecked;
148+
end;
149+
150+
procedure TMain.SendPhoto(Msg: TTgMessage);
161151
const
162152
PATH_PHOTO = 'C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg';
163153
var
164154
LFile: TtgFileToSend;
165155
begin
166156
tgBot.SendChatAction(Msg.Chat.Id, TtgSendChatAction.UploadPhoto);
157+
if not TFile.Exists(PATH_PHOTO) then
158+
WriteLine('Change path to photo in metod: TMain.SendPhoto');
167159
LFile := TtgFileToSend.Create(PATH_PHOTO);
168160
try
169161
tgBot.SendPhoto(Msg.Chat.ID, LFile, 'Nice Picture').Free;
@@ -186,7 +178,7 @@ procedure TMain.SendInline;
186178
tgBot.SendMessage(Msg.Chat.Id, 'Choose', TtgParseMode.default, False, False, 0, keyboard).Free;
187179
end;
188180

189-
procedure TMain.SendKeyboard(Msg: TtgMessage);
181+
procedure TMain.SendKeyboard(Msg: TTgMessage);
190182
var
191183
keyboard: IReplyMarkup;
192184
begin
@@ -258,7 +250,7 @@ procedure TMain.tgBotInlineQuery(ASender: TObject; AInlineQuery: TtgInlineQuery)
258250
tgBot.AnswerInlineQuery(AInlineQuery.Id, results, 0, True);
259251
end;
260252

261-
procedure TMain.SendQuest(Msg: TtgMessage);
253+
procedure TMain.SendQuest(Msg: TTgMessage);
262254
var
263255
keyboard: IReplyMarkup;
264256
begin
@@ -275,7 +267,7 @@ procedure TMain.tgBotInlineResultChosen(ASender: TObject; AChosenInlineResult: T
275267
WriteLine('Received choosen inline result: ' + AChosenInlineResult.ResultId);
276268
end;
277269

278-
procedure TMain.tgBotMessage(ASender: TObject; AMessage: TtgMessage);
270+
procedure TMain.tgBotMessage(ASender: TObject; AMessage: TTgMessage);
279271
begin
280272
case AMessage.&Type of
281273
TtgMessageType.TextMessage:
@@ -289,15 +281,7 @@ procedure TMain.tgBotMessage(ASender: TObject; AMessage: TtgMessage);
289281

290282
procedure TMain.tgBotReceiveError(ASender: TObject; AApiRequestException: EApiRequestException);
291283
begin
292-
case AApiRequestException.ErrorCode of
293-
401:
294-
begin
295-
tgBot.IsReceiving := False;
296-
ShowMessage(AApiRequestException.Message);
297-
end;
298-
end;
299284
WriteLine(AApiRequestException.ToString);
300-
AApiRequestException.Free;
301285
end;
302286

303287
procedure TMain.tgBotReceiveGeneralError(ASender: TObject; AException: Exception);
@@ -307,8 +291,16 @@ procedure TMain.tgBotReceiveGeneralError(ASender: TObject; AException: Exception
307291

308292
procedure TMain.WriteLine(const AValue: string);
309293
begin
310-
mmo1.Lines.Insert(0, AValue);
294+
mmoLog.Lines.Add(AValue);
295+
mmoLog.ScrollBy(0, mmoLog.ContentBounds.Bottom, False);
311296
end;
312297

298+
initialization
299+
ReportMemoryLeaksOnShutdown := True;
300+
301+
finalization
302+
if ReportMemoryLeaksOnShutdown then
303+
CheckSynchronize();
304+
313305
end.
314306

Install/TelegaPiBot.dpk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ contains
4242
TelegaPi.Types.InlineQueryResults in '..\Source\TelegaPi.Types.InlineQueryResults.pas',
4343
TelegaPi.Types.Enums in '..\Source\TelegaPi.Types.Enums.pas',
4444
TelegaPi.Exceptions in '..\Source\TelegaPi.Exceptions.pas',
45-
TelegAPI.Bot.Console in '..\Source\TelegAPI.Bot.Console.pas';
45+
TelegAPI.Bot.Console in '..\Source\TelegAPI.Bot.Console.pas',
46+
TelegAPI.Utils.Params in '..\Source\TelegAPI.Utils.Params.pas';
4647

4748
end.
4849

0 commit comments

Comments
 (0)