forked from Al-Muhandis/fp-telegram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtgsendertypes.pas
3230 lines (2882 loc) · 102 KB
/
tgsendertypes.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit tgsendertypes;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, fpjson, tgtypes, ghashmap, ghashset, tgstatlog, eventlog,
tgbasehttpclient
;
type
TParseMode = (pmDefault, pmMarkdown, pmHTML);
TMediaType = (mtPhoto, mtVideo, mtUnknown);
TInlineQueryResultType = (qrtArticle, qrtPhoto, qrtVideo, qrtAudio, qrtVoice, qrtMpeg4Gif,
qrtDocument, qrtUnknown);
TLogMessageEvent = procedure(ASender: TObject; EventType: TEventType; const Msg: String) of object;
TInlineKeyboardButton = class;
TKeyboardButton = class;
TKeybordButtonArray = class;
TInlineKeyboard = class;
TOnUpdateEvent = procedure (ASender: TObject; AnUpdate: TTelegramUpdateObj) of object;
TCommandEvent = procedure (ASender: TObject; const ACommand: String;
AMessage: TTelegramMessageObj) of object;
TCallbackEvent = procedure (ASender: TObject; ACallback: TCallbackQueryObj) of object;
TMessageEvent = procedure (ASender: TObject; AMessage: TTelegramMessageObj) of object;
TInlineQueryEvent = procedure (ASender: TObject; AnInlineQuery: TTelegramInlineQueryObj) of object;
TChosenInlineResultEvent = procedure (ASender: TObject;
AChosenInlineResult: TTelegramChosenInlineResultObj) of object;
TPreCheckoutQueryEvent = procedure (ASender: TObject;
APreCheckoutQuery: TTelegramPreCheckOutQuery) of object;
TSuccessfulPaymentEvent = procedure (ASender: TObject;
ASuccessfulPayment: TTelegramSuccessfulPayment) of object;
{ TStringHash }
TStringHash = class
class function hash(s: String; n: Integer): Integer;
end;
generic TStringHashMap<T> = class(specialize THashMap<String,T,TStringHash>) end;
TCommandHandlersMap = specialize TStringHashMap<TCommandEvent>;
{ TIntegerHash }
TIntegerHash = class
class function hash(i: Int64; n: Integer): Integer;
end;
TIntegerHashSet = specialize THashSet<Int64,TIntegerHash>;
{ TReplyMarkup }
TReplyMarkup = class(TJSONObject)
private
function GetForceReply: Boolean;
function GetInlineKeyBoard: TInlineKeyboard;
function GetOneTimeKeyboard: Boolean;
function GetRemoveKeyboard: Boolean;
function GetReplyKeyboardMarkup: TKeybordButtonArray;
function GetResizeKeyboard: Boolean;
function GetSelective: Boolean;
procedure SetForceReply(AValue: Boolean);
procedure SetInlineKeyBoard(AValue: TInlineKeyboard);
procedure SetOneTimeKeyboard(AValue: Boolean);
procedure SetRemoveKeyboard(AValue: Boolean);
procedure SetReplyKeyboardMarkup(AValue: TKeybordButtonArray);
procedure SetResizeKeyboard(AValue: Boolean);
procedure SetSelective(AValue: Boolean);
public
class function CreateFromObject(aObject: TJSONObject): TReplyMarkup;
class function CreateFromString(const aJSONString: String): TReplyMarkup;
function CreateInlineKeyBoard: TInlineKeyboard;
{ Only one from InlineKeyboard or ReplyMarkup is must to set }
property InlineKeyBoard: TInlineKeyboard read GetInlineKeyBoard write SetInlineKeyBoard;
{ ReplyKeyboard properties }
property ReplyKeyboardMarkup: TKeybordButtonArray read GetReplyKeyboardMarkup
write SetReplyKeyboardMarkup;
property RemoveKeyboard: Boolean read GetRemoveKeyboard write SetRemoveKeyboard;
{ Only if ReplyKeyboard is present then optional}
property ResizeKeyboard: Boolean read GetResizeKeyboard write SetResizeKeyboard;
property OneTimeKeyboard: Boolean read GetOneTimeKeyboard write SetOneTimeKeyboard;
{ ForceReply properties
If property ForceReply is set then ReplyMarkup must be only ForceReply type }
property ForceReply: Boolean read GetForceReply write SetForceReply;
property Selective: Boolean read GetSelective write SetSelective;
end;
TReplyMarkupClass=class of TReplyMarkup;
{ TKeyboardButton }
TKeyboardButton = class(TJSONObject)
private
function GetRequestContact: Boolean;
function GetRequestLocation: Boolean;
function Gettext: String;
procedure SetRequestContact(AValue: Boolean);
procedure SetRequestLocation(AValue: Boolean);
procedure Settext(AValue: String);
public
constructor Create(const AText: String);
property text: String read Gettext write Settext;
property RequestContact: Boolean read GetRequestContact write SetRequestContact; // Optional
property RequestLocation: Boolean read GetRequestLocation write SetRequestLocation; // Optional
end;
{ TKeyboardButtons }
TKeyboardButtons = class(TJSONArray)
private
function GetButtons(Index : Integer): TKeyboardButton;
procedure SetButtons(Index : Integer; AValue: TKeyboardButton);
public
constructor Create(const AText: String); overload;
constructor Create(const AButtons: array of String); overload;
function AddButton(const AButtonText: String): Integer;
procedure AddButtons(const AButtons: array of String);
property Buttons[Index : Integer]: TKeyboardButton read GetButtons write SetButtons;
end;
{ TInlineKeyboardButton }
TInlineKeyboardButton = class(TJSONObject)
private
function CheckOptnlNull: Boolean;
procedure CheckOptnlAndSet(const ParamName, ParamValue: String);
function Getcallback_data: String;
function Getswitch_inline_query: String;
function Getswitch_inline_query_current_chat: String;
function Gettext: String;
function Geturl: String;
procedure Setcallback_data(AValue: String);
procedure Setswitch_inline_query(AValue: String);
procedure Setswitch_inline_query_current_chat(AValue: String);
procedure Settext(AValue: String);
procedure Seturl(AValue: String);
public
constructor Create(const AText: String);
property text: String read Gettext write Settext;
property url: String read Geturl write Seturl;
property callback_data: String read Getcallback_data write Setcallback_data;
property switch_inline_query: String read Getswitch_inline_query write Setswitch_inline_query;
property switch_inline_query_current_chat: String read Getswitch_inline_query_current_chat
write Setswitch_inline_query_current_chat;
end;
{ TInlineKeyboardButtons }
TInlineKeyboardButtons = class(TJSONArray)
public
constructor Create(const AButtonText, CallbackData: String); overload;
function AddButton(const AButtonText, CallbackData: String): Integer;
function AddButtonUrl(const AButtonText, AUrl: String): Integer;
function AddButtonInline(const AButtonText, AQuery: String): Integer;
procedure AddButtons(const AButtons: array of String);
end;
{ TInlineKeyboard }
TInlineKeyboard = class(TJSONArray)
public
function Add(AButtons: TInlineKeyboardButtons): Integer; overload;
function Add: TInlineKeyboardButtons;
{ Added to the last row of buttons. If you specify a MaxColsinRow then
a new row of buttons is automatically created if needed }
procedure AddButton(aButton: TInlineKeyboardButton; MaxColsinRow: Integer = 0);
{ Add button with callback data to the last row of buttons. If you specify a MaxColsinRow then
a new row of buttons is automatically created if needed }
procedure AddButton(const AButtonText, CallbackData: String; MaxColsinRow: Integer = 0);
end;
{ TKeybordButtonArray }
TKeybordButtonArray = class(TJSONArray)
public
function Add(aButtons: TKeyboardButtons): Integer; overload;
function Add: TKeyboardButtons;
end;
{ TInputMessageContent }
TInputMessageContent = class(TJSONObject)
private
function GetMessageText: String;
function GetParseMode: TParseMode;
procedure SetMessageText(AValue: String);
procedure SetParseMode(AValue: TParseMode);
public
constructor Create(const AMessageText: String; AParseMode: TParseMode = pmDefault);
property MessageText: String read GetMessageText write SetMessageText;
property ParseMode: TParseMode read GetParseMode write SetParseMode;
end;
{ TInlineQueryResult }
TInlineQueryResult = class(TJSONObject)
private
function GetAudioDuration: Integer;
function GetAudioFileID: String;
function GetAudioUrl: String;
function GetCaption: String;
function GetDescription: String;
function GetDocumentFileID: String;
function GetID: String;
function GetInputMessageContent: TInputMessageContent;
function GetIQRType: TInlineQueryResultType;
function GetMimeType: String;
function GetMpeg4Height: Integer;
function GetMpeg4Url: String;
function GetMpeg4Width: Integer;
function GetParseMode: TParseMode;
function GetPerformer: String;
function GetPhotoFileID: String;
function GetPhotoHeight: Integer;
function GetPhotoUrl: String;
function GetPhotoWidth: Integer;
function GetReplyMarkup: TReplyMarkup;
function GetThumbUrl: String;
function GetTitle: String;
function GetVideoFileID: String;
function GetVideoUrl: String;
function GetVoiceFileID: String;
procedure SetAudioDuration(AValue: Integer);
procedure SetAudioFileID(AValue: String);
procedure SetAudioUrl(AValue: String);
procedure SetCaption(AValue: String);
procedure SetDescription(AValue: String);
procedure SetDocumentFileID(AValue: String);
procedure SetID(AValue: String);
procedure SetInputMessageContent(AValue: TInputMessageContent);
procedure SetIQRType(AValue: TInlineQueryResultType);
procedure SetMimeType(AValue: String);
procedure SetMpeg4Height(AValue: Integer);
procedure SetMpeg4Url(AValue: String);
procedure SetMpeg4Width(AValue: Integer);
procedure SetParseMode(AValue: TParseMode);
procedure SetPerformer(AValue: String);
procedure SetPhotoFileID(AValue: String);
procedure SetPhotoHeight(AValue: Integer);
procedure SetPhotoUrl(AValue: String);
procedure SetPhotoWidth(AValue: Integer);
procedure SetReplyMarkup(AValue: TReplyMarkup);
procedure SetThumbUrl(AValue: String);
procedure SetTitle(AValue: String);
procedure SetVideoFileID(AValue: String);
procedure SetVideoUrl(AValue: String);
procedure SetVoiceFileID(AValue: String);
public
property IQRType: TInlineQueryResultType read GetIQRType write SetIQRType;
property ID: String read GetID write SetID;
property Title: String read GetTitle write SetTitle;
property InputMessageContent: TInputMessageContent read GetInputMessageContent write SetInputMessageContent;
property ReplyMarkup: TReplyMarkup read GetReplyMarkup write SetReplyMarkup;
property Description: String read GetDescription write SetDescription;
property AudioFileID: String read GetAudioFileID write SetAudioFileID;
property DocumentFileID: String read GetDocumentFileID write SetDocumentFileID;
property PhotoFileID: String read GetPhotoFileID write SetPhotoFileID;
property VideoFileID: String read GetVideoFileID write SetVideoFileID;
property VoiceFileID: String read GetVoiceFileID write SetVoiceFileID;
property PhotoUrl: String read GetPhotoUrl write SetPhotoUrl;
property ThumbUrl: String read GetThumbUrl write SetThumbUrl;
property VideoUrl: String read GetVideoUrl write SetVideoUrl;
property MimeType: String read GetMimeType write SetMimeType;
property PhotoWidth: Integer read GetPhotoWidth write SetPhotoWidth;
property PhotoHeight: Integer read GetPhotoHeight write SetPhotoHeight;
property Mpeg4Url: String read GetMpeg4Url write SetMpeg4Url;
property Mpeg4Height: Integer read GetMpeg4Height write SetMpeg4Height;
property Mpeg4Width: Integer read GetMpeg4Width write SetMpeg4Width;
property AudioUrl: String read GetAudioUrl write SetAudioUrl;
property Caption: String read GetCaption write SetCaption;
property ParseMode: TParseMode read GetParseMode write SetParseMode;
property Performer: String read GetPerformer write SetPerformer;
property AudioDuration: Integer read GetAudioDuration write SetAudioDuration;
end;
{ TInlineQueryResultArray }
TInlineQueryResultArray = class(TJSONArray)
public
function Add(aInlineQueryResult: TInlineQueryResult): Integer; overload;
function Add: TInlineQueryResult;
end;
{ TInputMedia }
TInputMedia = class(TJSONObject)
private
function GetCaption: String;
function GetMedia: String;
function GetMediaType: TMediaType;
function GetParseMode: TParseMode;
procedure SetCaption(AValue: String);
procedure SetMedia(AValue: String);
procedure SetMediaType(AValue: TMediaType);
procedure SetParseMode(AValue: TParseMode);
public
property MediaType: TMediaType read GetMediaType write SetMediaType;
property Media: String read GetMedia write SetMedia;
property Caption: String read GetCaption write SetCaption;
property ParseMode: TParseMode read GetParseMode write SetParseMode;
end;
{ TInputMediaPhoto }
TInputMediaPhoto = class(TInputMedia)
public
constructor Create; reintroduce;
end;
{ TInputMediaVideo }
TInputMediaVideo = class(TInputMedia)
private
function GetDuration: Integer;
function GetHeight: Integer;
function GetSupportsStreaming: Boolean;
function GetWidth: Integer;
procedure SetDuration(AValue: Integer);
procedure SetHeight(AValue: Integer);
procedure SetSupportsStreaming(AValue: Boolean);
procedure SetWidth(AValue: Integer);
public
constructor Create; reintroduce;
property Width: Integer read GetWidth write SetWidth;
property Height: Integer read GetHeight write SetHeight;
property Duration: Integer read GetDuration write SetDuration;
property SupportsStreaming: Boolean read GetSupportsStreaming write SetSupportsStreaming;
end;
{ TInputMediaArray }
TInputMediaArray = class(TJSONArray)
public
function Add(AMedia: TInputMedia): Integer; overload;
function AddPhoto: TInputMediaPhoto;
function AddPhoto(const APhoto: String): Integer; overload;
function AddVideo: TInputMediaVideo;
function AddVideo(const AVideo: String): Integer; overload;
end;
{ TLabeledPrice }
TLabeledPrice = class(TJSONObject)
private
function GetPortionAmount: Integer;
function GetPortionLabel: String;
procedure SetPortionAmount(AValue: Integer);
procedure SetPortionLabel(AValue: String);
public
property PortionLabel: String read GetPortionLabel write SetPortionLabel;
property PortionAmount: Integer read GetPortionAmount write SetPortionAmount;
end;
{ TLabeledPriceArray }
TLabeledPriceArray = class(TJSONArray)
public
constructor Create(const APortionLabel: String; APortionAmount: Integer);
function AddLabeledPrice: TLabeledPrice;
end;
{ TTelegramSender }
TTelegramSender = class
private
FAPIEndPoint: String;
FBotUsername: String;
FCurrentChat: TTelegramChatObj;
FCurrentChatId: Int64;
FCurrentMessage: TTelegramMessageObj;
FCurrentUser: TTelegramUserObj;
FBotUser: TTelegramUserObj;
FFileObj: TTelegramFile;
FHTTPProxyHost: String;
FHTTPProxyPassword: String;
FHTTPProxyUser: String;
FHTTPProxyPort: Word;
FLanguage: string;
FLastErrorCode: Integer;
FLastErrorDescription: String;
FLogDebug: Boolean;
FLogger: TEventLog;
FOnAfterParseUpdate: TNotifyEvent;
FOnReceiveCallbackQuery: TCallbackEvent;
FOnReceiveChannelPost: TMessageEvent;
FOnReceiveChosenInlineResult: TChosenInlineResultEvent;
FOnReceiveEditedChannelPost: TMessageEvent;
FOnReceiveEditedMessage: TMessageEvent;
FOnReceiveInlineQuery: TInlineQueryEvent;
FOnReceiveMessage: TMessageEvent;
FOnReceivePreCheckoutQuery: TPreCheckoutQueryEvent;
FOnReceiveSuccessfulPayment: TMessageEvent;
FUpdate: TTelegramUpdateObj;
FJSONResponse: TJSONData;
FOnLogMessage: TLogMessageEvent;
FOnReceiveUpdate: TOnUpdateEvent;
FProcessUpdate: Boolean;
FResponse: String;
FRequestBody: String;
FToken: String;
FRequestWhenAnswer: Boolean;
FCommandHandlers: TCommandHandlersMap;
FChannelCommandHandlers: TCommandHandlersMap;
FUpdateID: Int64;
FUpdateLogger: TtgStatLog;
FUpdateProcessed: Boolean;
FTimeout: Integer;
procedure AssignHTTProxy(aHTTPClient: TBaseHTTPClient; const aHost: String; aPort: Word;
const aUserName, aPassword: String);
procedure AssignHTTProxy(aHTTPClient: TBaseHTTPClient);
function CurrentLanguage(AUser: TTelegramUserObj): String;
function CurrentLanguage(AMessage: TTelegramMessageObj): String;
function GetAPIEndPoint: String;
function GetChannelCommandHandlers(const Command: String): TCommandEvent;
function GetCommandHandlers(const Command: String): TCommandEvent;
function GetTimeout: Integer;
procedure SetAPIEndPoint(AValue: String);
procedure SetBotUsername(AValue: String);
procedure SetChannelCommandHandlers(const Command: String;
AValue: TCommandEvent);
procedure SetCommandHandlers(const Command: String; AValue: TCommandEvent);
function HTTPPostFile(const Method, FileField, FileName: String; AFormData: TStrings): Boolean;
function HTTPPostJSON(const Method: String): Boolean;
function HTTPPostStream(const Method, FileField, FileName: String;
AStream: TStream; AFormData: TStrings): Boolean;
procedure ProcessCommands(AMessage: TTelegramMessageObj; AHandlers: TCommandHandlersMap);
function ResponseToJSONObject: TJSONObject;
function ResponseHandle: Boolean;
function SendFile(const AMethod, AFileField, AFileName: String;
MethodParameters: TStrings): Boolean;
function SendMethod(const Method: String; MethodParameters: array of const): Boolean;
function SendMethod(const Method: String; MethodParameters: TJSONObject): Boolean; overload;
function SendStream(const AMethod, AFileField, AFileName: String; AStream: TStream;
MethodParameters: TStrings): Boolean;
procedure SetFileObj(AValue: TTelegramFile);
procedure SetJSONResponse(AValue: TJSONData);
procedure SetLastErrorCode(AValue: Integer);
procedure SetLastErrorDescription(AValue: String);
procedure SetLogDebug(AValue: Boolean);
procedure SetLogger(AValue: TEventLog);
procedure SetOnAfterParseUpdate(AValue: TNotifyEvent);
procedure SetProcessUpdate(AValue: Boolean);
procedure SetRequestBody(AValue: String);
procedure SetRequestWhenAnswer(AValue: Boolean);
procedure SetTimeout(AValue: Integer);
procedure SetUpdateID(AValue: Int64);
procedure SetUpdateLogger(AValue: TtgStatLog);
procedure SetUpdateProcessed(AValue: Boolean);
class function StringToJSONObject(const AString: String): TJSONObject;
protected
procedure DoAfterParseUpdate; // After the parse of the update object prior to calling all custom handlers (OnReceive...)
procedure DoReceiveMessageUpdate(AMessage: TTelegramMessageObj); virtual;
procedure DoReceiveEditedMessage(AMessage: TTelegramMessageObj); virtual;
procedure DoReceiveCallbackQuery(ACallback: TCallbackQueryObj); virtual;
procedure DoReceiveChannelPost(AChannelPost: TTelegramMessageObj); virtual;
procedure DoReceiveEditedChannelPost(AChannelPost: TTelegramMessageObj); virtual;
procedure DoReceiveInlineQuery(AnInlineQuery: TTelegramInlineQueryObj); virtual;
procedure DoReceiveChosenInlineResult(AChosenInlineResult: TTelegramChosenInlineResultObj); virtual;
procedure DoReceivePreCheckoutQuery(APreCheckoutQuery: TTelegramPreCheckOutQuery); virtual;
procedure DoReceiveSuccessfulPayment(AMessage: TTelegramMessageObj); virtual;
procedure DebugMessage(const Msg: String); virtual; // it will send all requests and responses to the log. Useful during development
procedure ErrorMessage(const Msg: String); virtual;
procedure InfoMessage(const Msg: String); virtual;
function IsBanned({%H-}ChatID: Int64): Boolean; virtual;
function IsSimpleUser({%H-}ChatID: Int64): Boolean; virtual;
procedure SetLanguage(const AValue: String); virtual;
public
constructor Create(const AToken: String);
function DeepLinkingUrl(const AParameter: String): String;
destructor Destroy; override;
procedure DoReceiveUpdate(AnUpdate: TTelegramUpdateObj); virtual; // After calling the rest of handlers OnReceive...
function CurrentIsSimpleUser: Boolean; overload;
function CurrentIsBanned: Boolean; overload;
function answerCallbackQuery(const CallbackQueryId: String; const Text: String = '';
ShowAlert: Boolean=False; const Url: String = ''; CacheTime: Integer = 0): Boolean; virtual;
function answerPreCheckoutQuery(const PreCheckoutQueryID: String; Ok: Boolean;
AnErrorMessage: String = ''): Boolean;
function deleteMessage(chat_id: Int64; message_id: Int64): Boolean;
function deleteMessage(message_id: Int64): Boolean;
function editMessageReplyMarkup(chat_id: Int64 = 0; message_id: Int64 = 0;
const inline_message_id: String = ''; ReplyMarkup: TReplyMarkup = nil): Boolean;
function editMessageText(const AMessage: String; chat_id: Int64; message_id: Int64;
ParseMode: TParseMode = pmDefault; DisableWebPagePreview: Boolean=False;
inline_message_id: String = ''; ReplyMarkup: TReplyMarkup = nil): Boolean;
function editMessageText(const AMessage: String; ParseMode: TParseMode = pmDefault;
DisableWebPagePreview: Boolean=False; ReplyMarkup: TReplyMarkup = nil): Boolean; overload;
function forwardMessage(chat_id: Int64; from_chat_id: Int64; DisableNotification: Boolean;
message_id: Int64): Boolean;
function forwardMessage(chat_id: String; from_chat_id: Int64; DisableNotification: Boolean;
message_id: Int64): Boolean;
function getChat(chat_id: Int64; out aChat:TTelegramChatObj): Boolean;
function getChat(chat_id: String; out aChat:TTelegramChatObj): Boolean;
function getChatMember(chat_id: Int64; user_id: Integer): Boolean;
function getChatMember(chat_id: Int64; user_id: Integer;
out aChatMember: TTelegramChatMember): Boolean; overload;
function getMe: Boolean;
function getWebhookInfo(out aWebhookInfo: TTelegramWebhookInfo): Boolean;
{ Specify an empty Update set ([]) to receive all updates regardless of type (default).
If not specified or [utUnknown], the previous setting will be used }
function setWebhook(const url: String; MaxConnections: Integer = 0; AllowedUpdates: TUpdateSet = [utUnknown]): Boolean;
function deleteWebhook: Boolean;
function getUpdates(offset: Int64 = 0; limit: Integer = 0; timeout: Integer = 0;
allowed_updates: TUpdateSet = []): Boolean;
{ To receive updates (LongPolling) You do not need to recalculate Offset in procedure below.
The offset itself will take it from the previous UpdateID and increment by one.
LongPollingTimeout in seconds! Timeout with 0 sec only for test cases}
function getUpdatesEx(limit: Integer = 0; timeout: Integer = 0;
allowed_updates: TUpdateSet = []): Boolean;
function kickChatMember(chat_id: Int64; user_id: Int64; kickDuration:Int64): Boolean;
function SendAudio(chat_id: Int64; const audio: String; const Caption: String = '';
ParseMode: TParseMode = pmDefault; Duration: Integer = 0; DisableNotification: Boolean = False;
ReplyToMessageID: Integer = 0; const Performer:String = ''; const Title: String = '';
ReplyMarkup: TReplyMarkup = nil): Boolean;
function sendDocument(chat_id: Int64; const file_id: String; const Caption: String = '';
ParseMode: TParseMode = pmDefault; DisableNotification: Boolean = False;
ReplyToMessageID: Integer = 0; ReplyMarkup: TReplyMarkup = nil): Boolean;
function sendDocumentByFileName(chat_id: Int64; const AFileName: String;
const ACaption: String; ReplyMarkup: TReplyMarkup = nil): Boolean;
function sendDocumentStream(chat_id: Int64; const AFileName: String; ADocStream: TStream;
const ACaption: String; ReplyMarkup: TReplyMarkup = nil): Boolean;
function sendInvoice(chat_id: Int64; const Title, Description, Payload, ProviderToken,
StartParameter, Currency: String; Prices: TLabeledPriceArray; ProviderData: TJSONObject = nil;
const PhotoUrl: String = ''; PhotoSize: Integer = 0; PhotoWidth: Integer = 0; PhotoHeight: Integer = 0;
NeedName: Boolean = False; NeedPhoneNumber: Boolean = False; NeedEmail: Boolean = False; NeedShippingAddress: Boolean = False;
SendPhoneNumberToProvider: Boolean = False; SendEmailToProvider: Boolean = False;
IsFlexible: Boolean = False;
DisableNotification: Boolean = False; ReplyToMessageID: Integer = 0;
ReplyMarkup: TReplyMarkup = nil): Boolean;
function sendLocation(chat_id: Int64; Latitude, Longitude: Real; LivePeriod: Integer = 0;
ParseMode: TParseMode = pmDefault; DisableWebPagePreview: Boolean=False;
ReplyMarkup: TReplyMarkup = nil): Boolean;
function sendMediaGroup(chat_id: Int64; media: TInputMediaArray;
DisableWebPagePreview: Boolean=False; ReplyToMessageID: Integer = 0): Boolean;
function sendMessage(chat_id: Int64; const AMessage: String; ParseMode: TParseMode = pmDefault;
DisableWebPagePreview: Boolean=False; ReplyMarkup: TReplyMarkup = nil;
ReplyToMessageID: Integer = 0): Boolean;
function sendMessageChannel(const chat_id, AMessage: String; ParseMode: TParseMode = pmDefault;
DisableWebPagePreview: Boolean=False; ReplyMarkup: TReplyMarkup = nil;
ReplyToMessageID: Integer = 0): Boolean;
function sendMessage(const AMessage: String; ParseMode: TParseMode = pmDefault;
DisableWebPagePreview: Boolean=False; ReplyMarkup: TReplyMarkup = nil;
ReplyToMessageID: Integer = 0): Boolean; overload;
function sendPhoto(chat_id: Int64; const APhoto: String; const ACaption: String = '';
ParseMode: TParseMode = pmDefault; ReplyMarkup: TReplyMarkup = nil;
ReplyToMessageID: Integer = 0): Boolean;
function sendPhotoByFileName(chat_id: Int64; const AFileName: String; const ACaption: String = '';
ParseMode: TParseMode = pmDefault; ReplyMarkup: TReplyMarkup = nil;
ReplyToMessageID: Integer = 0): Boolean;
function sendPhoto(const APhoto: String; const ACaption: String = '';
ParseMode: TParseMode = pmDefault; ReplyMarkup: TReplyMarkup = nil;
ReplyToMessageID: Integer = 0): Boolean; overload;
{ AFileName is not the fullpath to the file but the filename for request POST data.
Photo pass as a stream in the APhotoStream parameter }
function sendPhotoStream(chat_id: Int64; const AFileName: String; APhotoStream: TStream;
const ACaption: String; ParseMode: TParseMode = pmDefault; ReplyMarkup: TReplyMarkup = nil): Boolean; overload;
function sendVideo(chat_id: Int64; const AVideo: String; const ACaption: String = '';
ParseMode: TParseMode = pmDefault; ReplyMarkup: TReplyMarkup = nil;
ReplyToMessageID: Integer = 0): Boolean;
function sendVideo(const AVideo: String; const ACaption: String = '';
ParseMode: TParseMode = pmDefault; ReplyMarkup: TReplyMarkup = nil;
ReplyToMessageID: Integer = 0): Boolean; overload;
function sendVideoByFileName(chat_id: Int64; const AFileName: String; const ACaption: String = '';
ParseMode: TParseMode = pmDefault; ReplyMarkup: TReplyMarkup = nil;
ReplyToMessageID: Integer = 0): Boolean;
function sendVoice(chat_id: Int64; const Voice: String; const Caption: String = '';
ParseMode: TParseMode = pmDefault; Duration: Integer=0; DisableNotification: Boolean = False;
ReplyToMessageID: Integer = 0; ReplyMarkup: TReplyMarkup = nil): Boolean;
function sendAnimation(chat_id: Int64; const aAnimation: String; const ACaption: String = '';
ParseMode: TParseMode = pmDefault; ReplyMarkup: TReplyMarkup = nil;
ReplyToMessageID: Integer = 0): Boolean;
function sendAnimation(const aAnimation: String; const ACaption: String = '';
ParseMode: TParseMode = pmDefault; ReplyMarkup: TReplyMarkup = nil;
ReplyToMessageID: Integer = 0): Boolean;
function answerInlineQuery(const AnInlineQueryID: String; Results: TInlineQueryResultArray;
CacheTime: Integer = 300; IsPersonal: Boolean = False; const NextOffset: String = '';
const SwitchPmText: String = ''; const SwitchPmParameter: String = ''): Boolean;
function getFile(const FileID: String): Boolean;
property APIEndPoint: String read GetAPIEndPoint write SetAPIEndPoint;
property BotUser: TTelegramUserObj read FBotUser;
property JSONResponse: TJSONData read FJSONResponse write SetJSONResponse;
property CurrentChatId: Int64 read FCurrentChatId;
property CurrentUser: TTelegramUserObj read FCurrentUser;
property CurrentChat: TTelegramChatObj read FCurrentChat;
property CurrentMessage: TTelegramMessageObj read FCurrentMessage;
property CurrentUpdate: TTelegramUpdateObj read FUpdate;
{ If the bot works in a country where telegram API is not available, one of the easiest ways is
to change the API endpoint to its mirror proxy }
property FileObj: TTelegramFile read FFileObj write SetFileObj;
property Language: string read FLanguage write SetLanguage;
property LogDebug: Boolean read FLogDebug write SetLogDebug;
property OnLogMessage: TLogMessageEvent read FOnLogMessage write FOnLogMessage;
property UpdateID: Int64 read FUpdateID write SetUpdateID;
{ Gives a flag that the Update object is processed and there is no need for further processing
and for calling the appropriate events }
property UpdateProcessed: Boolean read FUpdateProcessed write SetUpdateProcessed;
property RequestBody: String read FRequestBody write SetRequestBody;
property Response: String read FResponse;
property HTTPProxyUser: String read FHTTPProxyUser write FHTTPProxyUser;
property HTTPProxyPassword: String read FHTTPProxyPassword write FHTTPProxyPassword;
property HTTPProxyHost: String read FHTTPProxyHost write FHTTPProxyHost;
property HTTPProxyPort: Word read FHTTPProxyPort write FHTTPProxyPort;
property Token: String read FToken write FToken;
{ If you're using webhooks, you can perform a request to the API while sending an answer...
In this case the method to be invoked in the method parameter of the request.}
property RequestWhenAnswer: Boolean read FRequestWhenAnswer write SetRequestWhenAnswer;
{ if ProcessUpdate then the incoming update object will be processed.
May be useful for multithreaded work when updates is receiving in one Sender object and
processing and sending to telegram server in another Sender object. In this case ProcessUpdate = False}
property ProcessUpdate: Boolean read FProcessUpdate write SetProcessUpdate;
property CommandHandlers [const Command: String]: TCommandEvent read GetCommandHandlers
write SetCommandHandlers; // It can create command handlers by assigning their to array elements
property ChannelCommandHandlers [const Command: String]: TCommandEvent read GetChannelCommandHandlers
write SetChannelCommandHandlers; // It can create command handlers by assigning their to array elements
property BotUsername: String read FBotUsername write SetBotUsername;
property LastErrorCode: Integer read FLastErrorCode write SetLastErrorCode;
property LastErrorDescription: String read FLastErrorDescription write SetLastErrorDescription;
property Logger: TEventLog read FLogger write SetLogger;
property UpdateLogger: TtgStatLog read FUpdateLogger write SetUpdateLogger; //We will log the update object completely if need
property Timeout: Integer read GetTimeout write SetTimeout;
{ After the parse of the update object prior to calling all other custom events (OnReceive...) }
property OnAfterParseUpdate: TNotifyEvent read FOnAfterParseUpdate write SetOnAfterParseUpdate;
{ After calling the rest of events OnReceive... }
property OnReceiveUpdate: TOnUpdateEvent read FOnReceiveUpdate write FOnReceiveUpdate;
property OnReceiveMessage: TMessageEvent read FOnReceiveMessage write FOnReceiveMessage;
property OnReceiveEditedMessage: TMessageEvent read FOnReceiveEditedMessage
write FOnReceiveEditedMessage;
property OnReceiveCallbackQuery: TCallbackEvent read FOnReceiveCallbackQuery
write FOnReceiveCallbackQuery;
property OnReceiveChannelPost: TMessageEvent read FOnReceiveChannelPost write FOnReceiveChannelPost;
property OnReceiveEditedChannelPost: TMessageEvent read FOnReceiveEditedChannelPost
write FOnReceiveEditedChannelPost;
property OnReceiveInlineQuery: TInlineQueryEvent read FOnReceiveInlineQuery
write FOnReceiveInlineQuery;
property OnReceiveChosenInlineResult: TChosenInlineResultEvent read FOnReceiveChosenInlineResult
write FOnReceiveChosenInlineResult;
property OnReceivePreCheckoutQuery: TPreCheckoutQueryEvent read FOnReceivePreCheckoutQuery
write FOnReceivePreCheckoutQuery;
property OnReceiveSuccessfulPayment: TMessageEvent read FOnReceiveSuccessfulPayment
write FOnReceiveSuccessfulPayment;
end;
{ Procedure style method to send message from Bot to chat/user }
function TgBotSendMessage(const AToken: String; chat_id: Int64; const AMessage: String;
out AReply: String;
ParseMode: TParseMode = pmDefault; DisableWebPagePreview: Boolean=False;
AReplyMarkup: TReplyMarkup = nil; ReplyToMessageID: Integer = 0): Boolean;
var
TelegramAPI_URL: String ='https://api.telegram.org/bot';
implementation
uses
jsonparser, jsonscanner
{ added tgfclhttpclientbroker unit by default for backward compatibility.
But in your projects it is better to specify the appropriate broker explicitly }
, tgfclhttpclientbroker
;
const
// API names constants
s_editMessageText='editMessageText';
s_editMessageReplyMarkup='editMessageReplyMarkup';
s_sendMessage='sendMessage';
s_sendPhoto='sendPhoto';
s_sendAudio='sendAudio';
s_sendVoice='sendVoice';
s_sendVideo='sendVideo';
s_sendAnimation='sendAnimation';
s_sendDocument='sendDocument';
s_sendLocation='sendLocation';
s_sendInvoice='sendInvoice';
s_sendMediaGroup='sendMediaGroup';
s_getChat = 'getChat';
s_getWebhookInfo = 'getWebhookInfo';
s_setWebhook = 'setWebhook';
s_deleteWebhook = 'deleteWebhook';
s_getUpdates='getUpdates';
s_getMe='getMe';
s_getChatMember='getChatMember';
s_forwardMessage='forwardMessage';
s_answerInlineQuery='answerInlineQuery';
s_answerPreCheckoutQuery='answerPreCheckoutQuery';
s_deleteMessage='deleteMessage';
s_getFile = 'getFile';
s_kickChatMember = 'kickChatMember';
s_Method='method';
s_Url = 'url';
s_MaxConnections = 'max_connections';
s_Text = 'text';
s_ChatId = 'chat_id';
s_UserID = 'user_id';
s_MessageId = 'message_id';
s_InlineMessageId = 'inline_message_id';
s_Document = 'document';
s_Photo = 'photo';
s_Video = 'video';
s_Audio = 'audio';
s_Voice = 'voice';
s_Animation='animation';
s_Caption = 'caption';
s_Media = 'media';
s_ParseMode = 'parse_mode';
s_ReplyMarkup = 'reply_markup';
s_ReplyToMessageID = 'reply_to_message_id';
s_Latitude = 'latitude';
s_Longitude = 'longitude';
s_LivePeriod = 'live_period';
s_DsblWbpgPrvw = 'disable_web_page_preview';
s_DsblNtfctn = 'disable_notification';
s_Performer = 'performer';
s_Duration = 'duration';
s_SupportsStreaming = 'supports_streaming';
s_InlineKeyboard = 'inline_keyboard';
s_Keyboard = 'keyboard';
s_RemoveKeyboard = 'remove_keyboard';
s_ResizeKeyboard = 'resize_keyboard';
s_OneTimeKeyboard = 'one_time_keyboard';
s_RequestContact = 'request_contact';
s_RequestLocation = 'request_location';
s_SwitchInlineQuery = 'switch_inline_query';
s_CallbackData = 'callback_data';
s_SwitchInlineQueryCurrentChat = 's_switch_inline_query_current_chat';
s_Selective = 'selective';
s_ForceReply = 'force_reply';
s_Offset = 'offset';
s_Limit = 'limit';
s_Timeout = 'timeout';
s_AllowedUpdates = 'allowed_updates';
s_Ok = 'ok';
s_ErrorCode = 'error_code';
s_ErrorMessage = 'error_message';
s_Description = 'description';
s_Result = 'result';
s_BotCommand = 'bot_command';
s_Amount = 'amount';
s_Label = 'label';
s_Payload = 'payload';
s_ProviderToken = 'provider_token';
s_ProviderData = 'provider_data';
s_StartParameter = 'start_parameter';
s_Currency = 'currency';
s_Prices = 'prices';
s_PreCheckoutQueryID = 'pre_checkout_query_id';
s_FromChatID='from_chat_id';
s_UntilDate = 'until_date';
s_CallbackQueryID = 'callback_query_id';
s_ShowAlert = 'show_alert';
s_ID = 'id';
s_InputMessageContent = 'input_message_content';
s_Type = 'type';
s_Title = 'title';
s_MessageText = 'message_text';
s_InlineQueryID = 'inline_query_id';
s_Results = 'results';
s_CacheTime = 'cache_time';
s_IsPersonal = 'is_personal';
s_NextOffset = 'next_offset';
s_SwitchPmText = 'switch_pm_text';
s_SwitchPmParameter = 'switch_pm_parameter';
s_FileID = 'file_id';
s_answerCallbackQuery = 'answerCallbackQuery';
s_PhotoUrl ='photo_url';
s_ThumbUrl ='thumb_url';
s_VideoUrl ='video_url';
s_MimeType ='mime_type';
s_PhotoHeight = 'photo_height';
s_PhotoWidth = 'photo_width';
s_PhotoSize = 'photo_size';
s_AudioFileID = 'audio_file_id';
s_DocumentFileID = 'document_file_id';
s_PhotoFileID = 'photo_file_id';
s_VideoFileID = 'video_file_id';
s_VoiceFileID = 'voice_file_id';
s_Mpeg4Url = 'mpeg4_url';
s_Mpeg4Width = 'mpeg4_width';
s_Mpeg4Height = 'mpeg4_height';
s_Width = 'width';
s_Height = 'height';
s_NeedName = 'need_name';
s_NeedPhoneNumber = 'need_phone_number';
s_NeedEmail = 'need_email';
s_NeedShippingAddress = 'need_shipping_address';
s_SendPhoneNumber2Provider = 'send_phone_number_to_provider';
s_SendEmail2Provider = 'send_email_to_provider';
s_IsFlexible = 'is_flexible';
s_AudioDuration = 'audio_duration';
s_AudioUrl = 'audio_url';
ParseModes: array[TParseMode] of PChar = ('', 'Markdown', 'HTML');
MediaTypes: array[TMediaType] of PChar = ('photo', 'video', '');
QueryResultTypeArray: array[TInlineQueryResultType] of PChar =
('article', 'photo', 'video', 'audio', 'voice', 'mpeg4_gif', 'document', '');
TgBotUrlStart = 'https://t.me/';
function StringToIQRType(const S: String): TInlineQueryResultType;
var
iqrt: TInlineQueryResultType;
begin
Result:=qrtUnknown;
for iqrt:=Low(QueryResultTypeArray) to High(QueryResultTypeArray) do
if AnsiSameStr(QueryResultTypeArray[iqrt], S) then
Exit(iqrt);
end;
function StringToParseMode(const S: String): TParseMode;
var
pm: TParseMode;
begin
Result:=pmDefault;
for pm:=Low(ParseModes) to High(ParseModes) do
if AnsiSameStr(ParseModes[pm], S) then
Exit(pm);
end;
function StringToMediaType(const S: String): TMediaType;
var
mt: TMediaType;
begin
Result:=mtUnknown;
for mt:=Low(MediaTypes) to High(MediaTypes) do
if AnsiSameStr(MediaTypes[mt], S) then
Exit(mt);
end;
function TgBotSendMessage(const AToken: String; chat_id: Int64;
const AMessage: String; out AReply: String; ParseMode: TParseMode;
DisableWebPagePreview: Boolean; AReplyMarkup: TReplyMarkup;
ReplyToMessageID: Integer): Boolean;
var
ABot: TTelegramSender;
begin
Result:=False;
ABot:=TTelegramSender.Create(AToken);
try
ABot.APIEndPoint:=TelegramAPI_URL;
Result:=ABot.sendMessage(chat_id, AMessage, ParseMode, DisableWebPagePreview, AReplyMarkup, ReplyToMessageID);
AReply:=ABot.Response;
finally
ABot.Free;
end;
end;
{ TKeybordButtonArray }
function TKeybordButtonArray.Add(aButtons: TKeyboardButtons): Integer;
begin
Result:=Add(aButtons as TJSONArray);
end;
function TKeybordButtonArray.Add: TKeyboardButtons;
begin
Result:=TKeyboardButtons.Create;
Add(Result);
end;
{ TInlineQueryResultArray }
function TInlineQueryResultArray.Add(aInlineQueryResult: TInlineQueryResult
): Integer;
begin
Result:=Add(aInlineQueryResult as TJSONObject);
end;
function TInlineQueryResultArray.Add: TInlineQueryResult;
begin
Result:=TInlineQueryResult.Create;
Add(Result);
end;
{ TLabeledPriceArray }
constructor TLabeledPriceArray.Create(const APortionLabel: String;
APortionAmount: Integer);
var
ALabeledPrice: TLabeledPrice;
begin
inherited Create;
ALabeledPrice:=AddLabeledPrice;
ALabeledPrice.PortionLabel:=APortionLabel;
ALabeledPrice.PortionAmount:=APortionAmount;
end;
function TLabeledPriceArray.AddLabeledPrice: TLabeledPrice;
begin
Result:=TLabeledPrice.Create;
Add(Result);
end;
{ TLabeledPrice }
function TLabeledPrice.GetPortionAmount: Integer;
begin
Result:=Integers[s_Amount];
end;
function TLabeledPrice.GetPortionLabel: String;
begin
Result:=Strings[s_Label];
end;
procedure TLabeledPrice.SetPortionAmount(AValue: Integer);
begin
Integers[s_Amount]:=AValue;
end;
procedure TLabeledPrice.SetPortionLabel(AValue: String);
begin
Strings[s_Label]:=AValue;
end;
{ TIntegerHash }
class function TIntegerHash.hash(i: Int64; n: Integer): Integer;
begin
Result:=i mod n;
end;
{ TInputMediaPhoto }
constructor TInputMediaPhoto.Create;
begin
inherited Create;
MediaType:=mtPhoto;
end;
{ TInputMediaArray }
function TInputMediaArray.Add(AMedia: TInputMedia): Integer;
begin
Result:=Add(AMedia as TJSONObject);
end;
function TInputMediaArray.AddPhoto: TInputMediaPhoto;
begin
Result:=TInputMediaPhoto.Create;
Add(Result);
end;
function TInputMediaArray.AddPhoto(const APhoto: String): Integer;
var
AnInputMedia: TInputMedia;
begin
AnInputMedia:=TInputMediaPhoto.Create;
AnInputMedia.Media:=APhoto;
Result:=Add(AnInputMedia);
end;
function TInputMediaArray.AddVideo: TInputMediaVideo;
begin
Result:=TInputMediaVideo.Create;
Add(Result);
end;
function TInputMediaArray.AddVideo(const AVideo: String): Integer;
var
AnInputMedia: TInputMedia;
begin
AnInputMedia:=TInputMediaVideo.Create;
AnInputMedia.Media:=AVideo;
Result:=Add(AnInputMedia);
end;
{ TInputMediaVideo }
function TInputMediaVideo.GetDuration: Integer;
begin
Result:=Get(s_Duration, 0);
end;
function TInputMediaVideo.GetHeight: Integer;
begin