├── .gitattributes ├── .gitignore ├── Bin ├── Win32 │ ├── libcrypto-1_1.dll │ ├── libssl-1_1.dll │ ├── tdjson.dll │ └── zlib1.dll └── Win64 │ └── tdjson.dll ├── LICENSE ├── Package ├── TGC.Component.pas ├── TGC_API.dpk ├── TGC_API.dproj └── TGC_API.res ├── README.md ├── Samples ├── Client │ ├── TGClient.dpr │ ├── TGClient.dproj │ ├── TGClient.res │ ├── Unit4.fmx │ └── Unit4.pas └── UpdateOptionJSToClass │ ├── Project32.dpr │ ├── Project32.dproj │ ├── Project32.res │ ├── Unit5.fmx │ └── Unit5.pas ├── Sources ├── HGM.JSONParams.pas ├── TGC.Builder.GetMe.pas ├── TGC.Builder.GetUser.pas ├── TGC.Builder.GetUserFullInfo.pas ├── TGC.Builder.SendMessage.pas ├── TGC.Builder.SendMessageAlbum.pas ├── TGC.Classes.pas ├── TGC.Client.pas ├── TGC.Entity.AObject.pas ├── TGC.Entity.AnimatedChatPhoto.pas ├── TGC.Entity.BotCommand.pas ├── TGC.Entity.ChatPhoto.pas ├── TGC.Entity.Files.pas ├── TGC.Entity.FormatedText.pas ├── TGC.Entity.Message.pas ├── TGC.Entity.MiniThumbnail.pas ├── TGC.Entity.PhotoSize.pas ├── TGC.Entity.ProfilePhoto.pas ├── TGC.Entity.Sticker.pas ├── TGC.Entity.User.pas ├── TGC.Entity.UserFullInfo.pas ├── TGC.Errors.pas ├── TGC.Handler.Error.pas ├── TGC.Handler.UpdateAuthorizationState.pas ├── TGC.Handler.UpdateOption.pas ├── TGC.Handler.pas ├── TGC.Options.pas └── TGC.Wrapper.pas └── TGC_API_Group.groupproj /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Uncomment these types if you want even more clean repository. But be careful. 2 | # It can make harm to an existing project source. Read explanations below. 3 | # 4 | # Resource files are binaries containing manifest, project icon and version info. 5 | # They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files. 6 | #*.res 7 | # 8 | # Type library file (binary). In old Delphi versions it should be stored. 9 | # Since Delphi 2009 it is produced from .ridl file and can safely be ignored. 10 | #*.tlb 11 | # 12 | # Diagram Portfolio file. Used by the diagram editor up to Delphi 7. 13 | # Uncomment this if you are not using diagrams or use newer Delphi version. 14 | #*.ddp 15 | # 16 | # Visual LiveBindings file. Added in Delphi XE2. 17 | # Uncomment this if you are not using LiveBindings Designer. 18 | #*.vlb 19 | # 20 | # Deployment Manager configuration file for your project. Added in Delphi XE2. 21 | # Uncomment this if it is not mobile development and you do not use remote debug feature. 22 | #*.deployproj 23 | # 24 | # C++ object files produced when C/C++ Output file generation is configured. 25 | # Uncomment this if you are not using external objects (zlib library for example). 26 | #*.obj 27 | # 28 | 29 | # Delphi compiler-generated binaries (safe to delete) 30 | *.exe 31 | *.bpl 32 | *.bpi 33 | *.dcp 34 | *.so 35 | *.apk 36 | *.drc 37 | *.map 38 | *.dres 39 | *.rsm 40 | *.tds 41 | *.dcu 42 | *.lib 43 | *.a 44 | *.o 45 | *.ocx 46 | 47 | # Delphi autogenerated files (duplicated info) 48 | *.cfg 49 | *.hpp 50 | *Resource.rc 51 | 52 | # Delphi local files (user-specific info) 53 | *.local 54 | *.identcache 55 | *.projdata 56 | *.tvsconfig 57 | *.dsk 58 | 59 | # Delphi history and backups 60 | __history/ 61 | __recovery/ 62 | *.~* 63 | Samples/Client/Win32 64 | 65 | # Castalia statistics file (since XE7 Castalia is distributed with Delphi) 66 | *.stat 67 | 68 | # Boss dependency manager vendor folder https://github.com/HashLoad/boss 69 | modules/ 70 | -------------------------------------------------------------------------------- /Bin/Win32/libcrypto-1_1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HemulGM/TGC_API/11c9fb22624adadd7e0c1725301d90cbd550158e/Bin/Win32/libcrypto-1_1.dll -------------------------------------------------------------------------------- /Bin/Win32/libssl-1_1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HemulGM/TGC_API/11c9fb22624adadd7e0c1725301d90cbd550158e/Bin/Win32/libssl-1_1.dll -------------------------------------------------------------------------------- /Bin/Win32/tdjson.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HemulGM/TGC_API/11c9fb22624adadd7e0c1725301d90cbd550158e/Bin/Win32/tdjson.dll -------------------------------------------------------------------------------- /Bin/Win32/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HemulGM/TGC_API/11c9fb22624adadd7e0c1725301d90cbd550158e/Bin/Win32/zlib1.dll -------------------------------------------------------------------------------- /Bin/Win64/tdjson.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HemulGM/TGC_API/11c9fb22624adadd7e0c1725301d90cbd550158e/Bin/Win64/tdjson.dll -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 alinvip22@gmail.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package/TGC.Component.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Component; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Classes, TGC.Client; 7 | 8 | procedure Register; 9 | 10 | implementation 11 | 12 | procedure Register; 13 | begin 14 | RegisterComponents('Telegram Client', [TTelegramClient]); 15 | end; 16 | 17 | end. 18 | 19 | -------------------------------------------------------------------------------- /Package/TGC_API.dpk: -------------------------------------------------------------------------------- 1 | package TGC_API; 2 | 3 | {$R *.res} 4 | {$IFDEF IMPLICITBUILDING This IFDEF should not be used by users} 5 | {$ALIGN 8} 6 | {$ASSERTIONS ON} 7 | {$BOOLEVAL OFF} 8 | {$DEBUGINFO OFF} 9 | {$EXTENDEDSYNTAX ON} 10 | {$IMPORTEDDATA ON} 11 | {$IOCHECKS ON} 12 | {$LOCALSYMBOLS ON} 13 | {$LONGSTRINGS ON} 14 | {$OPENSTRINGS ON} 15 | {$OPTIMIZATION OFF} 16 | {$OVERFLOWCHECKS ON} 17 | {$RANGECHECKS ON} 18 | {$REFERENCEINFO ON} 19 | {$SAFEDIVIDE OFF} 20 | {$STACKFRAMES ON} 21 | {$TYPEDADDRESS OFF} 22 | {$VARSTRINGCHECKS ON} 23 | {$WRITEABLECONST OFF} 24 | {$MINENUMSIZE 1} 25 | {$IMAGEBASE $400000} 26 | {$DEFINE DEBUG} 27 | {$ENDIF IMPLICITBUILDING} 28 | {$IMPLICITBUILD ON} 29 | 30 | requires 31 | rtl, 32 | RESTComponents; 33 | 34 | contains 35 | TGC.Wrapper in '..\Sources\TGC.Wrapper.pas', 36 | TGC.Client in '..\Sources\TGC.Client.pas', 37 | TGC.Handler in '..\Sources\TGC.Handler.pas', 38 | TGC.Handler.UpdateAuthorizationState in '..\Sources\TGC.Handler.UpdateAuthorizationState.pas', 39 | TGC.Component in 'TGC.Component.pas', 40 | HGM.JSONParams in '..\Sources\HGM.JSONParams.pas', 41 | TGC.Handler.Error in '..\Sources\TGC.Handler.Error.pas', 42 | TGC.Classes in '..\Sources\TGC.Classes.pas', 43 | TGC.Handler.UpdateOption in '..\Sources\TGC.Handler.UpdateOption.pas', 44 | TGC.Options in '..\Sources\TGC.Options.pas', 45 | TGC.Builder.SendMessage in '..\Sources\TGC.Builder.SendMessage.pas', 46 | TGC.Builder.GetMe in '..\Sources\TGC.Builder.GetMe.pas', 47 | TGC.Builder.SendMessageAlbum in '..\Sources\TGC.Builder.SendMessageAlbum.pas', 48 | TGC.Builder.GetUser in '..\Sources\TGC.Builder.GetUser.pas', 49 | TGC.Entity.AObject in '..\Sources\TGC.Entity.AObject.pas', 50 | TGC.Entity.ChatPhoto in '..\Sources\TGC.Entity.ChatPhoto.pas', 51 | TGC.Entity.Files in '..\Sources\TGC.Entity.Files.pas', 52 | TGC.Entity.FormatedText in '..\Sources\TGC.Entity.FormatedText.pas', 53 | TGC.Entity.Message in '..\Sources\TGC.Entity.Message.pas', 54 | TGC.Entity.MiniThumbnail in '..\Sources\TGC.Entity.MiniThumbnail.pas', 55 | TGC.Entity.PhotoSize in '..\Sources\TGC.Entity.PhotoSize.pas', 56 | TGC.Entity.ProfilePhoto in '..\Sources\TGC.Entity.ProfilePhoto.pas', 57 | TGC.Entity.Sticker in '..\Sources\TGC.Entity.Sticker.pas', 58 | TGC.Entity.User in '..\Sources\TGC.Entity.User.pas', 59 | TGC.Entity.UserFullInfo in '..\Sources\TGC.Entity.UserFullInfo.pas', 60 | TGC.Entity.AnimatedChatPhoto in '..\Sources\TGC.Entity.AnimatedChatPhoto.pas', 61 | TGC.Entity.BotCommand in '..\Sources\TGC.Entity.BotCommand.pas', 62 | TGC.Builder.GetUserFullInfo in '..\Sources\TGC.Builder.GetUserFullInfo.pas'; 63 | 64 | end. 65 | -------------------------------------------------------------------------------- /Package/TGC_API.dproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {D6CBD190-10CD-4ED9-BA95-4F5E10418940} 4 | TGC_API.dpk 5 | 19.5 6 | None 7 | True 8 | Debug 9 | Win32 10 | 1 11 | Package 12 | 13 | 14 | true 15 | 16 | 17 | true 18 | Base 19 | true 20 | 21 | 22 | true 23 | Base 24 | true 25 | 26 | 27 | true 28 | Base 29 | true 30 | 31 | 32 | true 33 | Base 34 | true 35 | 36 | 37 | true 38 | Base 39 | true 40 | 41 | 42 | true 43 | Base 44 | true 45 | 46 | 47 | true 48 | Base 49 | true 50 | 51 | 52 | true 53 | Base 54 | true 55 | 56 | 57 | true 58 | Cfg_1 59 | true 60 | true 61 | 62 | 63 | true 64 | Base 65 | true 66 | 67 | 68 | .\$(Platform)\$(Config) 69 | .\$(Platform)\$(Config) 70 | false 71 | false 72 | false 73 | false 74 | false 75 | true 76 | true 77 | System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace) 78 | All 79 | TGC_API 80 | 81 | 82 | None 83 | annotation-1.2.0.dex.jar;asynclayoutinflater-1.0.0.dex.jar;billing-4.0.0.dex.jar;browser-1.0.0.dex.jar;cloud-messaging.dex.jar;collection-1.0.0.dex.jar;coordinatorlayout-1.0.0.dex.jar;core-1.5.0-rc02.dex.jar;core-common-2.0.1.dex.jar;core-runtime-2.0.1.dex.jar;cursoradapter-1.0.0.dex.jar;customview-1.0.0.dex.jar;documentfile-1.0.0.dex.jar;drawerlayout-1.0.0.dex.jar;firebase-annotations-16.0.0.dex.jar;firebase-common-20.0.0.dex.jar;firebase-components-17.0.0.dex.jar;firebase-datatransport-18.0.0.dex.jar;firebase-encoders-17.0.0.dex.jar;firebase-encoders-json-18.0.0.dex.jar;firebase-iid-interop-17.1.0.dex.jar;firebase-installations-17.0.0.dex.jar;firebase-installations-interop-17.0.0.dex.jar;firebase-measurement-connector-19.0.0.dex.jar;firebase-messaging-22.0.0.dex.jar;fmx.dex.jar;fragment-1.0.0.dex.jar;google-play-licensing.dex.jar;interpolator-1.0.0.dex.jar;javax.inject-1.dex.jar;legacy-support-core-ui-1.0.0.dex.jar;legacy-support-core-utils-1.0.0.dex.jar;lifecycle-common-2.0.0.dex.jar;lifecycle-livedata-2.0.0.dex.jar;lifecycle-livedata-core-2.0.0.dex.jar;lifecycle-runtime-2.0.0.dex.jar;lifecycle-service-2.0.0.dex.jar;lifecycle-viewmodel-2.0.0.dex.jar;listenablefuture-1.0.dex.jar;loader-1.0.0.dex.jar;localbroadcastmanager-1.0.0.dex.jar;play-services-ads-20.1.0.dex.jar;play-services-ads-base-20.1.0.dex.jar;play-services-ads-identifier-17.0.0.dex.jar;play-services-ads-lite-20.1.0.dex.jar;play-services-base-17.5.0.dex.jar;play-services-basement-17.6.0.dex.jar;play-services-cloud-messaging-16.0.0.dex.jar;play-services-drive-17.0.0.dex.jar;play-services-games-21.0.0.dex.jar;play-services-location-18.0.0.dex.jar;play-services-maps-17.0.1.dex.jar;play-services-measurement-base-18.0.0.dex.jar;play-services-measurement-sdk-api-18.0.0.dex.jar;play-services-places-placereport-17.0.0.dex.jar;play-services-stats-17.0.0.dex.jar;play-services-tasks-17.2.0.dex.jar;print-1.0.0.dex.jar;room-common-2.1.0.dex.jar;room-runtime-2.1.0.dex.jar;slidingpanelayout-1.0.0.dex.jar;sqlite-2.0.1.dex.jar;sqlite-framework-2.0.1.dex.jar;swiperefreshlayout-1.0.0.dex.jar;transport-api-3.0.0.dex.jar;transport-backend-cct-3.0.0.dex.jar;transport-runtime-3.0.0.dex.jar;user-messaging-platform-1.0.0.dex.jar;versionedparcelable-1.1.1.dex.jar;viewpager-1.0.0.dex.jar;work-runtime-2.1.0.dex.jar 84 | rtl;RESTComponents;$(DCC_UsePackage) 85 | 86 | 87 | None 88 | annotation-1.2.0.dex.jar;asynclayoutinflater-1.0.0.dex.jar;billing-4.0.0.dex.jar;browser-1.0.0.dex.jar;cloud-messaging.dex.jar;collection-1.0.0.dex.jar;coordinatorlayout-1.0.0.dex.jar;core-1.5.0-rc02.dex.jar;core-common-2.0.1.dex.jar;core-runtime-2.0.1.dex.jar;cursoradapter-1.0.0.dex.jar;customview-1.0.0.dex.jar;documentfile-1.0.0.dex.jar;drawerlayout-1.0.0.dex.jar;firebase-annotations-16.0.0.dex.jar;firebase-common-20.0.0.dex.jar;firebase-components-17.0.0.dex.jar;firebase-datatransport-18.0.0.dex.jar;firebase-encoders-17.0.0.dex.jar;firebase-encoders-json-18.0.0.dex.jar;firebase-iid-interop-17.1.0.dex.jar;firebase-installations-17.0.0.dex.jar;firebase-installations-interop-17.0.0.dex.jar;firebase-measurement-connector-19.0.0.dex.jar;firebase-messaging-22.0.0.dex.jar;fmx.dex.jar;fragment-1.0.0.dex.jar;google-play-licensing.dex.jar;interpolator-1.0.0.dex.jar;javax.inject-1.dex.jar;legacy-support-core-ui-1.0.0.dex.jar;legacy-support-core-utils-1.0.0.dex.jar;lifecycle-common-2.0.0.dex.jar;lifecycle-livedata-2.0.0.dex.jar;lifecycle-livedata-core-2.0.0.dex.jar;lifecycle-runtime-2.0.0.dex.jar;lifecycle-service-2.0.0.dex.jar;lifecycle-viewmodel-2.0.0.dex.jar;listenablefuture-1.0.dex.jar;loader-1.0.0.dex.jar;localbroadcastmanager-1.0.0.dex.jar;play-services-ads-20.1.0.dex.jar;play-services-ads-base-20.1.0.dex.jar;play-services-ads-identifier-17.0.0.dex.jar;play-services-ads-lite-20.1.0.dex.jar;play-services-base-17.5.0.dex.jar;play-services-basement-17.6.0.dex.jar;play-services-cloud-messaging-16.0.0.dex.jar;play-services-drive-17.0.0.dex.jar;play-services-games-21.0.0.dex.jar;play-services-location-18.0.0.dex.jar;play-services-maps-17.0.1.dex.jar;play-services-measurement-base-18.0.0.dex.jar;play-services-measurement-sdk-api-18.0.0.dex.jar;play-services-places-placereport-17.0.0.dex.jar;play-services-stats-17.0.0.dex.jar;play-services-tasks-17.2.0.dex.jar;print-1.0.0.dex.jar;room-common-2.1.0.dex.jar;room-runtime-2.1.0.dex.jar;slidingpanelayout-1.0.0.dex.jar;sqlite-2.0.1.dex.jar;sqlite-framework-2.0.1.dex.jar;swiperefreshlayout-1.0.0.dex.jar;transport-api-3.0.0.dex.jar;transport-backend-cct-3.0.0.dex.jar;transport-runtime-3.0.0.dex.jar;user-messaging-platform-1.0.0.dex.jar;versionedparcelable-1.1.1.dex.jar;viewpager-1.0.0.dex.jar;work-runtime-2.1.0.dex.jar 89 | rtl;RESTComponents;$(DCC_UsePackage) 90 | 91 | 92 | None 93 | rtl;RESTComponents;$(DCC_UsePackage) 94 | 95 | 96 | None 97 | rtl;RESTComponents;$(DCC_UsePackage) 98 | 99 | 100 | rtl;RESTComponents;$(DCC_UsePackage) 101 | 102 | 103 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 104 | Debug 105 | true 106 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 107 | 1033 108 | rtl;RESTComponents;$(DCC_UsePackage) 109 | 110 | 111 | rtl;RESTComponents;$(DCC_UsePackage) 112 | 113 | 114 | DEBUG;$(DCC_Define) 115 | true 116 | false 117 | true 118 | true 119 | true 120 | true 121 | true 122 | 123 | 124 | false 125 | 126 | 127 | false 128 | RELEASE;$(DCC_Define) 129 | 0 130 | 0 131 | 132 | 133 | 134 | MainSource 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 | Base 168 | 169 | 170 | Cfg_1 171 | Base 172 | 173 | 174 | Cfg_2 175 | Base 176 | 177 | 178 | 179 | Delphi.Personality.12 180 | Package 181 | 182 | 183 | 184 | TGC_API.dpk 185 | 186 | 187 | 188 | 189 | 190 | true 191 | 192 | 193 | 194 | 195 | true 196 | 197 | 198 | 199 | 200 | true 201 | 202 | 203 | 204 | 205 | TGC_API.bpl 206 | true 207 | 208 | 209 | 210 | 211 | 1 212 | 213 | 214 | 0 215 | 216 | 217 | 218 | 219 | classes 220 | 64 221 | 222 | 223 | classes 224 | 64 225 | 226 | 227 | 228 | 229 | res\xml 230 | 1 231 | 232 | 233 | res\xml 234 | 1 235 | 236 | 237 | 238 | 239 | library\lib\armeabi-v7a 240 | 1 241 | 242 | 243 | 244 | 245 | library\lib\armeabi 246 | 1 247 | 248 | 249 | library\lib\armeabi 250 | 1 251 | 252 | 253 | 254 | 255 | library\lib\armeabi-v7a 256 | 1 257 | 258 | 259 | 260 | 261 | library\lib\mips 262 | 1 263 | 264 | 265 | library\lib\mips 266 | 1 267 | 268 | 269 | 270 | 271 | library\lib\armeabi-v7a 272 | 1 273 | 274 | 275 | library\lib\arm64-v8a 276 | 1 277 | 278 | 279 | 280 | 281 | library\lib\armeabi-v7a 282 | 1 283 | 284 | 285 | 286 | 287 | res\drawable 288 | 1 289 | 290 | 291 | res\drawable 292 | 1 293 | 294 | 295 | 296 | 297 | res\values 298 | 1 299 | 300 | 301 | res\values 302 | 1 303 | 304 | 305 | 306 | 307 | res\values-v21 308 | 1 309 | 310 | 311 | res\values-v21 312 | 1 313 | 314 | 315 | 316 | 317 | res\values 318 | 1 319 | 320 | 321 | res\values 322 | 1 323 | 324 | 325 | 326 | 327 | res\drawable 328 | 1 329 | 330 | 331 | res\drawable 332 | 1 333 | 334 | 335 | 336 | 337 | res\drawable-xxhdpi 338 | 1 339 | 340 | 341 | res\drawable-xxhdpi 342 | 1 343 | 344 | 345 | 346 | 347 | res\drawable-xxxhdpi 348 | 1 349 | 350 | 351 | res\drawable-xxxhdpi 352 | 1 353 | 354 | 355 | 356 | 357 | res\drawable-ldpi 358 | 1 359 | 360 | 361 | res\drawable-ldpi 362 | 1 363 | 364 | 365 | 366 | 367 | res\drawable-mdpi 368 | 1 369 | 370 | 371 | res\drawable-mdpi 372 | 1 373 | 374 | 375 | 376 | 377 | res\drawable-hdpi 378 | 1 379 | 380 | 381 | res\drawable-hdpi 382 | 1 383 | 384 | 385 | 386 | 387 | res\drawable-xhdpi 388 | 1 389 | 390 | 391 | res\drawable-xhdpi 392 | 1 393 | 394 | 395 | 396 | 397 | res\drawable-mdpi 398 | 1 399 | 400 | 401 | res\drawable-mdpi 402 | 1 403 | 404 | 405 | 406 | 407 | res\drawable-hdpi 408 | 1 409 | 410 | 411 | res\drawable-hdpi 412 | 1 413 | 414 | 415 | 416 | 417 | res\drawable-xhdpi 418 | 1 419 | 420 | 421 | res\drawable-xhdpi 422 | 1 423 | 424 | 425 | 426 | 427 | res\drawable-xxhdpi 428 | 1 429 | 430 | 431 | res\drawable-xxhdpi 432 | 1 433 | 434 | 435 | 436 | 437 | res\drawable-xxxhdpi 438 | 1 439 | 440 | 441 | res\drawable-xxxhdpi 442 | 1 443 | 444 | 445 | 446 | 447 | res\drawable-small 448 | 1 449 | 450 | 451 | res\drawable-small 452 | 1 453 | 454 | 455 | 456 | 457 | res\drawable-normal 458 | 1 459 | 460 | 461 | res\drawable-normal 462 | 1 463 | 464 | 465 | 466 | 467 | res\drawable-large 468 | 1 469 | 470 | 471 | res\drawable-large 472 | 1 473 | 474 | 475 | 476 | 477 | res\drawable-xlarge 478 | 1 479 | 480 | 481 | res\drawable-xlarge 482 | 1 483 | 484 | 485 | 486 | 487 | res\values 488 | 1 489 | 490 | 491 | res\values 492 | 1 493 | 494 | 495 | 496 | 497 | 1 498 | 499 | 500 | 1 501 | 502 | 503 | 0 504 | 505 | 506 | 507 | 508 | 1 509 | .framework 510 | 511 | 512 | 1 513 | .framework 514 | 515 | 516 | 1 517 | .framework 518 | 519 | 520 | 0 521 | 522 | 523 | 524 | 525 | 1 526 | .dylib 527 | 528 | 529 | 1 530 | .dylib 531 | 532 | 533 | 1 534 | .dylib 535 | 536 | 537 | 0 538 | .dll;.bpl 539 | 540 | 541 | 542 | 543 | 1 544 | .dylib 545 | 546 | 547 | 1 548 | .dylib 549 | 550 | 551 | 1 552 | .dylib 553 | 554 | 555 | 1 556 | .dylib 557 | 558 | 559 | 1 560 | .dylib 561 | 562 | 563 | 1 564 | .dylib 565 | 566 | 567 | 0 568 | .bpl 569 | 570 | 571 | 572 | 573 | 0 574 | 575 | 576 | 0 577 | 578 | 579 | 0 580 | 581 | 582 | 0 583 | 584 | 585 | 0 586 | 587 | 588 | 0 589 | 590 | 591 | 0 592 | 593 | 594 | 0 595 | 596 | 597 | 0 598 | 599 | 600 | 601 | 602 | 1 603 | 604 | 605 | 1 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | Contents\Resources 614 | 1 615 | 616 | 617 | Contents\Resources 618 | 1 619 | 620 | 621 | Contents\Resources 622 | 1 623 | 624 | 625 | 626 | 627 | library\lib\armeabi-v7a 628 | 1 629 | 630 | 631 | library\lib\arm64-v8a 632 | 1 633 | 634 | 635 | 1 636 | 637 | 638 | 1 639 | 640 | 641 | 1 642 | 643 | 644 | 1 645 | 646 | 647 | 1 648 | 649 | 650 | 1 651 | 652 | 653 | 1 654 | 655 | 656 | 0 657 | 658 | 659 | 660 | 661 | library\lib\armeabi-v7a 662 | 1 663 | 664 | 665 | 666 | 667 | 1 668 | 669 | 670 | 1 671 | 672 | 673 | 674 | 675 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 676 | 1 677 | 678 | 679 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 680 | 1 681 | 682 | 683 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 684 | 1 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 1 693 | 694 | 695 | 1 696 | 697 | 698 | 1 699 | 700 | 701 | 702 | 703 | Assets 704 | 1 705 | 706 | 707 | Assets 708 | 1 709 | 710 | 711 | 712 | 713 | Assets 714 | 1 715 | 716 | 717 | Assets 718 | 1 719 | 720 | 721 | 722 | 723 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 724 | 1 725 | 726 | 727 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 728 | 1 729 | 730 | 731 | 732 | 733 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 734 | 1 735 | 736 | 737 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 738 | 1 739 | 740 | 741 | 742 | 743 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 744 | 1 745 | 746 | 747 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 748 | 1 749 | 750 | 751 | 752 | 753 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 754 | 1 755 | 756 | 757 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 758 | 1 759 | 760 | 761 | 762 | 763 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 764 | 1 765 | 766 | 767 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 768 | 1 769 | 770 | 771 | 772 | 773 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 774 | 1 775 | 776 | 777 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 778 | 1 779 | 780 | 781 | 782 | 783 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 784 | 1 785 | 786 | 787 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 788 | 1 789 | 790 | 791 | 792 | 793 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 794 | 1 795 | 796 | 797 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 798 | 1 799 | 800 | 801 | 802 | 803 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 804 | 1 805 | 806 | 807 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 808 | 1 809 | 810 | 811 | 812 | 813 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 814 | 1 815 | 816 | 817 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 818 | 1 819 | 820 | 821 | 822 | 823 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 824 | 1 825 | 826 | 827 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 828 | 1 829 | 830 | 831 | 832 | 833 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 834 | 1 835 | 836 | 837 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 838 | 1 839 | 840 | 841 | 842 | 843 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 844 | 1 845 | 846 | 847 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 848 | 1 849 | 850 | 851 | 852 | 853 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 854 | 1 855 | 856 | 857 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 858 | 1 859 | 860 | 861 | 862 | 863 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 864 | 1 865 | 866 | 867 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 868 | 1 869 | 870 | 871 | 872 | 873 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 874 | 1 875 | 876 | 877 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 878 | 1 879 | 880 | 881 | 882 | 883 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 884 | 1 885 | 886 | 887 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 888 | 1 889 | 890 | 891 | 892 | 893 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 894 | 1 895 | 896 | 897 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 898 | 1 899 | 900 | 901 | 902 | 903 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 904 | 1 905 | 906 | 907 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 908 | 1 909 | 910 | 911 | 912 | 913 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 914 | 1 915 | 916 | 917 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 918 | 1 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | False 935 | False 936 | False 937 | False 938 | False 939 | True 940 | False 941 | 942 | 943 | 12 944 | 945 | 946 | 947 | 948 | 949 | -------------------------------------------------------------------------------- /Package/TGC_API.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HemulGM/TGC_API/11c9fb22624adadd7e0c1725301d90cbd550158e/Package/TGC_API.res -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TGC_API 2 | Telegram Client for Delphi 3 | 4 | Hello. The package is still being worked on. Authorization and full-fledged work with the client is done. You can already use the library, but I will implement more convenient methods and describe the Telegram classes. 5 | 6 | A package is a non-visual component that you need to configure for yourself in the designer. 7 | To work with a client, you need to have `ApiId` and `ApiHash` - the data of the application you registered on the Telegram website. `https://my.telegram.org/apps` 8 | Next, you can customize the Parameters section to your liking. 9 | 10 | The client requires the assembly of the `tdjson.dll` library version `1.8.11`, as well as the library: `libcrypto-1_1.dll`, `libssl-1_1.dll`, `zlib1.dll`. 11 | Libraries are in the Bin folder 12 | -------------------------------------------------------------------------------- /Samples/Client/TGClient.dpr: -------------------------------------------------------------------------------- 1 | program TGClient; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | Unit4 in 'Unit4.pas' {Form4}, 7 | TGC.Component in '..\..\Package\TGC.Component.pas', 8 | HGM.JSONParams in '..\..\Sources\HGM.JSONParams.pas', 9 | TGC.Classes in '..\..\Sources\TGC.Classes.pas', 10 | TGC.Client in '..\..\Sources\TGC.Client.pas', 11 | TGC.Errors in '..\..\Sources\TGC.Errors.pas', 12 | TGC.Handler.Error in '..\..\Sources\TGC.Handler.Error.pas', 13 | TGC.Handler in '..\..\Sources\TGC.Handler.pas', 14 | TGC.Handler.UpdateAuthorizationState in '..\..\Sources\TGC.Handler.UpdateAuthorizationState.pas', 15 | TGC.Handler.UpdateOption in '..\..\Sources\TGC.Handler.UpdateOption.pas', 16 | TGC.Options in '..\..\Sources\TGC.Options.pas', 17 | TGC.Wrapper in '..\..\Sources\TGC.Wrapper.pas', 18 | TGC.Builder.SendMessage in '..\..\Sources\TGC.Builder.SendMessage.pas', 19 | TGC.Builder.GetMe in '..\..\Sources\TGC.Builder.GetMe.pas', 20 | TGC.Builder.SendMessageAlbum in '..\..\Sources\TGC.Builder.SendMessageAlbum.pas', 21 | TGC.Builder.GetUser in '..\..\Sources\TGC.Builder.GetUser.pas', 22 | TGC.Builder.GetUserFullInfo in '..\..\Sources\TGC.Builder.GetUserFullInfo.pas', 23 | TGC.Entity.AnimatedChatPhoto in '..\..\Sources\TGC.Entity.AnimatedChatPhoto.pas', 24 | TGC.Entity.AObject in '..\..\Sources\TGC.Entity.AObject.pas', 25 | TGC.Entity.BotCommand in '..\..\Sources\TGC.Entity.BotCommand.pas', 26 | TGC.Entity.ChatPhoto in '..\..\Sources\TGC.Entity.ChatPhoto.pas', 27 | TGC.Entity.Files in '..\..\Sources\TGC.Entity.Files.pas', 28 | TGC.Entity.FormatedText in '..\..\Sources\TGC.Entity.FormatedText.pas', 29 | TGC.Entity.Message in '..\..\Sources\TGC.Entity.Message.pas', 30 | TGC.Entity.MiniThumbnail in '..\..\Sources\TGC.Entity.MiniThumbnail.pas', 31 | TGC.Entity.PhotoSize in '..\..\Sources\TGC.Entity.PhotoSize.pas', 32 | TGC.Entity.ProfilePhoto in '..\..\Sources\TGC.Entity.ProfilePhoto.pas', 33 | TGC.Entity.Sticker in '..\..\Sources\TGC.Entity.Sticker.pas', 34 | TGC.Entity.User in '..\..\Sources\TGC.Entity.User.pas', 35 | TGC.Entity.UserFullInfo in '..\..\Sources\TGC.Entity.UserFullInfo.pas'; 36 | 37 | {$R *.res} 38 | 39 | begin 40 | Application.Initialize; 41 | Application.CreateForm(TForm4, Form4); 42 | Application.Run; 43 | end. 44 | -------------------------------------------------------------------------------- /Samples/Client/TGClient.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HemulGM/TGC_API/11c9fb22624adadd7e0c1725301d90cbd550158e/Samples/Client/TGClient.res -------------------------------------------------------------------------------- /Samples/Client/Unit4.fmx: -------------------------------------------------------------------------------- 1 | object Form4: TForm4 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form4' 5 | ClientHeight = 480 6 | ClientWidth = 640 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | OnCreate = FormCreate 11 | OnDestroy = FormDestroy 12 | DesignerMasterStyle = 0 13 | object Memo1: TMemo 14 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 15 | DataDetectorTypes = [] 16 | Position.X = 8.000000000000000000 17 | Position.Y = 38.000000000000000000 18 | Size.Width = 449.000000000000000000 19 | Size.Height = 434.000000000000000000 20 | Size.PlatformDefault = False 21 | TabOrder = 0 22 | Viewport.Width = 445.000000000000000000 23 | Viewport.Height = 430.000000000000000000 24 | end 25 | object ButtonGetMe: TButton 26 | Position.X = 465.000000000000000000 27 | Position.Y = 38.000000000000000000 28 | Size.Width = 136.000000000000000000 29 | Size.Height = 22.000000000000000000 30 | Size.PlatformDefault = False 31 | TabOrder = 4 32 | Text = 'ButtonGetMe' 33 | OnClick = ButtonGetMeClick 34 | end 35 | object ButtonSendMessage: TButton 36 | Position.X = 465.000000000000000000 37 | Position.Y = 68.000000000000000000 38 | Size.Width = 136.000000000000000000 39 | Size.Height = 22.000000000000000000 40 | Size.PlatformDefault = False 41 | TabOrder = 7 42 | Text = 'ButtonSendMessage' 43 | OnClick = ButtonSendMessageClick 44 | end 45 | object ButtonAuth: TButton 46 | Position.X = 116.000000000000000000 47 | Position.Y = 8.000000000000000000 48 | TabOrder = 9 49 | Text = 'ButtonAuth' 50 | OnClick = ButtonAuthClick 51 | end 52 | object EditNumber: TEdit 53 | Touch.InteractiveGestures = [LongTap, DoubleTap] 54 | TabOrder = 11 55 | Position.X = 8.000000000000000000 56 | Position.Y = 8.000000000000000000 57 | TextPrompt = 'Phone number' 58 | end 59 | object Edit1: TEdit 60 | Touch.InteractiveGestures = [LongTap, DoubleTap] 61 | TabOrder = 13 62 | Text = 'Label' 63 | Position.X = 472.000000000000000000 64 | Position.Y = 272.000000000000000000 65 | Size.Width = 129.000000000000000000 66 | Size.Height = 33.000000000000000000 67 | Size.PlatformDefault = False 68 | StyledSettings = [Family, Size, Style] 69 | OnChangeTracking = Edit1ChangeTracking 70 | OnEnter = Edit1Enter 71 | OnExit = Edit1Exit 72 | object LabelFormat: TLabel 73 | Align = Client 74 | Margins.Left = 3.000000000000000000 75 | Margins.Top = 3.000000000000000000 76 | Margins.Right = 3.000000000000000000 77 | Margins.Bottom = 3.000000000000000000 78 | Size.Width = 123.000000000000000000 79 | Size.Height = 27.000000000000000000 80 | Size.PlatformDefault = False 81 | Text = 'LabelFormat' 82 | Visible = False 83 | TabOrder = 0 84 | end 85 | end 86 | object Button1: TButton 87 | Position.X = 465.000000000000000000 88 | Position.Y = 98.000000000000000000 89 | Size.Width = 136.000000000000000000 90 | Size.Height = 22.000000000000000000 91 | Size.PlatformDefault = False 92 | TabOrder = 3 93 | Text = 'ButtonGetUserFullInfo' 94 | OnClick = Button1Click 95 | end 96 | object TelegramClient1: TTelegramClient 97 | OnReceive = TelegramClient1Receive 98 | SyncEvents = True 99 | SyncMethodsCallback = True 100 | Timeout = 10.000000000000000000 101 | Parameters.DatabaseDirectory = 'tdlib' 102 | Parameters.FilesDirectory = 'tdlib_files' 103 | Parameters.SystemLanguageCode = 'ru' 104 | Parameters.DeviceModel = 'Desktop' 105 | Parameters.ApplicationVersion = '0.1' 106 | ApiId = 29265223 107 | ApiHash = 'd8c53e8da942aa5bfe1147d307196cb5' 108 | OnNeedAuthCode = TelegramClient1NeedAuthCode 109 | OnRegistration = TelegramClient1Registration 110 | OnNeedAuthPassword = TelegramClient1NeedAuthPassword 111 | OnNeedAuthConfirm = TelegramClient1NeedAuthConfirm 112 | OnAuthReady = TelegramClient1AuthReady 113 | OnClose = TelegramClient1Close 114 | OnError = TelegramClient1Error 115 | Left = 512 116 | Top = 168 117 | end 118 | end 119 | -------------------------------------------------------------------------------- /Samples/Client/Unit4.pas: -------------------------------------------------------------------------------- 1 | unit Unit4; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, TGC.Client, 8 | FMX.Memo.Types, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, 9 | TGC.Handler, TGC.Handler.UpdateAuthorizationState, FMX.StdCtrls, FMX.Edit, 10 | FMX.Objects; 11 | 12 | type 13 | TForm4 = class(TForm) 14 | Memo1: TMemo; 15 | TelegramClient1: TTelegramClient; 16 | ButtonGetMe: TButton; 17 | ButtonSendMessage: TButton; 18 | ButtonAuth: TButton; 19 | EditNumber: TEdit; 20 | Edit1: TEdit; 21 | LabelFormat: TLabel; 22 | Button1: TButton; 23 | procedure FormCreate(Sender: TObject); 24 | procedure TelegramClient1NeedAuthCode(Sender: TObject); 25 | procedure TelegramClient1AuthReady(Sender: TObject); 26 | procedure TelegramClient1NeedAuthPassword(Sender: TObject); 27 | procedure TelegramClient1Receive(Sender: TObject; const Data: string); 28 | procedure TelegramClient1Registration(Sender: TObject; const Terms: TTermsOfService); 29 | procedure TelegramClient1Error(Sender: TObject; const Code: Integer; const Message: string); 30 | procedure TelegramClient1NeedAuthConfirm(Sender: TObject; const Link: string); 31 | procedure ButtonGetMeClick(Sender: TObject); 32 | procedure TelegramClient1Close(Sender: TObject); 33 | procedure FormDestroy(Sender: TObject); 34 | procedure ButtonSendMessageClick(Sender: TObject); 35 | procedure ButtonAuthClick(Sender: TObject); 36 | procedure Edit1Enter(Sender: TObject); 37 | procedure Edit1Exit(Sender: TObject); 38 | procedure Edit1ChangeTracking(Sender: TObject); 39 | procedure Button1Click(Sender: TObject); 40 | public 41 | end; 42 | 43 | var 44 | Form4: TForm4; 45 | 46 | implementation 47 | 48 | uses 49 | FMX.DialogService, TGC.Entity.User, System.JSON, TGC.Classes, System.DateUtils, 50 | TGC.Builder.SendMessage, TGC.Entity.Message, TGC.Builder.GetMe, 51 | TGC.Builder.SendMessageAlbum, TGC.Entity.UserFullInfo; 52 | 53 | {$R *.fmx} 54 | 55 | procedure TForm4.ButtonGetMeClick(Sender: TObject); 56 | begin 57 | TelegramClient1.Methods.GetMe( 58 | procedure(User: TtgUser) 59 | begin 60 | Memo1.Lines.Add('TelegramClient1.Methods.GetMe callback'#13#10 + User.FirstName + ' ' + User.LastName); 61 | end); 62 | 63 | TelegramClient1.Methods.Execute(TGetMe.Create, '', 64 | procedure(User: TJSONObject) 65 | begin 66 | Memo1.Lines.Add('TelegramClient1.Methods.GetMe callback'#13#10 + User.Format); 67 | end); 68 | end; 69 | 70 | procedure TForm4.ButtonSendMessageClick(Sender: TObject); 71 | begin 72 | if not TelegramClient1.IsInitialized then 73 | Exit; { 74 | TelegramClient1.Methods.SendMessage( 75 | TSendMessage.Create.InputMessageContent( 76 | TInputMessageText.Create.Text(TFormattedText.Create.Text('😁')) 77 | ).ChatId(1288857534) //268284944 78 | .Options(TMessageSendOptions.Create.SchedulingState(TMessageSchedulingStateSendAtDate.Create.SendDate(Now.IncMinute(2)))), 79 | procedure(Msg: TtgMessage) 80 | begin 81 | // сообщение отправлено 82 | Memo1.Lines.Add('sended msg'); 83 | end); } 84 | 85 | TelegramClient1.Methods.SendMessageAlbum( 86 | TSendMessageAlbum.Create.InputMessageContents([ 87 | TInputMessagePhoto.Create.Photo(TInputFileLocal.Create.Path('D:\Temp\Photos\299990769.jpg')), 88 | TInputMessagePhoto.Create.Photo(TInputFileLocal.Create.Path('D:\Temp\Photos\299990763.jpg')) 89 | ]).ChatId(1288857534), 90 | procedure(Msg: TtgMessage) 91 | begin 92 | if Msg.IsError then 93 | Memo1.Lines.Add(Msg.Message) 94 | else 95 | Memo1.Lines.Add('sended msg'); 96 | end); 97 | { 98 | TelegramClient1.Methods.SendMessage( 99 | TSendMessage.Create.InputMessageContent( 100 | TInputMessageDocument.Create.Document(TInputFileLocal.Create.Path('D:\Temp\Iconion\HGM\Material Icons_e80e(0)_128.png')) 101 | ).ChatId(1288857534), 102 | procedure(Msg: TtgMessage) 103 | begin 104 | // сообщение отправлено 105 | Memo1.Lines.Add('sended msg'); 106 | end); } 107 | end; 108 | 109 | procedure TForm4.Edit1ChangeTracking(Sender: TObject); 110 | begin 111 | var Date: TDateTime; 112 | if TryStrToDateTime(Edit1.Text, Date) then 113 | LabelFormat.Text := FormatDateTime('dd mmmm yyyy г.', Date) 114 | else 115 | LabelFormat.Text := 'Не корректная дата'; 116 | end; 117 | 118 | procedure TForm4.Edit1Enter(Sender: TObject); 119 | begin 120 | LabelFormat.Visible := False; 121 | Edit1.FontColor := TAlphaColorRec.Black; 122 | end; 123 | 124 | procedure TForm4.Edit1Exit(Sender: TObject); 125 | begin 126 | LabelFormat.Visible := True; 127 | Edit1.FontColor := TAlphaColorRec.Null; 128 | end; 129 | 130 | procedure TForm4.Button1Click(Sender: TObject); 131 | begin 132 | TelegramClient1.Methods.GetUser(1065413441, 133 | procedure(Info: TtgUser) 134 | begin 135 | if Info.IsError then 136 | Memo1.Lines.Add(Info.Message) 137 | else 138 | Memo1.Lines.Add('FirstName ' + Info.FirstName); 139 | end); 140 | end; 141 | 142 | procedure TForm4.ButtonAuthClick(Sender: TObject); 143 | begin 144 | TelegramClient1.PhoneNumber := EditNumber.Text; 145 | if not TelegramClient1.Initializate then 146 | ShowMessage('Not inited'); 147 | end; 148 | 149 | procedure TForm4.FormCreate(Sender: TObject); 150 | begin 151 | // 152 | end; 153 | 154 | procedure TForm4.FormDestroy(Sender: TObject); 155 | begin 156 | TThread.RemoveQueuedEvents(nil); 157 | end; 158 | 159 | procedure TForm4.TelegramClient1AuthReady(Sender: TObject); 160 | begin 161 | //ShowMessage('ready'); 162 | end; 163 | 164 | procedure TForm4.TelegramClient1Close(Sender: TObject); 165 | begin 166 | Memo1.Lines.Add('Client closed. Recreating'); 167 | TelegramClient1.Initializate; 168 | end; 169 | 170 | procedure TForm4.TelegramClient1Error(Sender: TObject; const Code: Integer; const Message: string); 171 | begin 172 | ShowMessage('Error: ' + Message + #13#10' Code: ' + Code.ToString); 173 | end; 174 | 175 | procedure TForm4.TelegramClient1NeedAuthCode(Sender: TObject); 176 | begin 177 | TDialogService.InputQuery('User Authorization', ['Enter the authorization code'], [''], 178 | procedure(const AResult: TModalResult; const AValues: array of string) 179 | begin 180 | if AResult = mrOk then 181 | TelegramClient1.SetAuthCode(AValues[0]); 182 | end); 183 | end; 184 | 185 | procedure TForm4.TelegramClient1NeedAuthConfirm(Sender: TObject; const Link: string); 186 | begin 187 | ShowMessage('Confirm ' + Link); 188 | end; 189 | 190 | procedure TForm4.TelegramClient1NeedAuthPassword(Sender: TObject); 191 | begin 192 | TDialogService.InputQuery('User Authentication', ['Enter the access code (password)'], [''], 193 | procedure(const AResult: TModalResult; const AValues: array of string) 194 | begin 195 | if AResult = mrOk then 196 | TelegramClient1.SetAuthPassword(AValues[0]); 197 | end); 198 | end; 199 | 200 | procedure TForm4.TelegramClient1Receive(Sender: TObject; const Data: string); 201 | begin 202 | Memo1.Lines.Add(Data); 203 | end; 204 | 205 | procedure TForm4.TelegramClient1Registration(Sender: TObject; const Terms: TTermsOfService); 206 | begin 207 | TDialogService.InputQuery('User Registration', ['First Name', 'Last Name'], ['', ''], 208 | procedure(const AResult: TModalResult; const AValues: array of string) 209 | begin 210 | if AResult = mrOk then 211 | TelegramClient1.SetRegisterUser(AValues[0], AValues[1]); 212 | end); 213 | end; 214 | 215 | initialization 216 | ReportMemoryLeaksOnShutdown := True; 217 | 218 | end. 219 | 220 | -------------------------------------------------------------------------------- /Samples/UpdateOptionJSToClass/Project32.dpr: -------------------------------------------------------------------------------- 1 | program Project32; 2 | 3 | uses 4 | System.StartUpCopy, 5 | FMX.Forms, 6 | Unit5 in 'Unit5.pas' {Form5}; 7 | 8 | {$R *.res} 9 | 10 | begin 11 | Application.Initialize; 12 | Application.CreateForm(TForm5, Form5); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /Samples/UpdateOptionJSToClass/Project32.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HemulGM/TGC_API/11c9fb22624adadd7e0c1725301d90cbd550158e/Samples/UpdateOptionJSToClass/Project32.res -------------------------------------------------------------------------------- /Samples/UpdateOptionJSToClass/Unit5.fmx: -------------------------------------------------------------------------------- 1 | object Form5: TForm5 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form5' 5 | ClientHeight = 642 6 | ClientWidth = 899 7 | FormFactor.Width = 320 8 | FormFactor.Height = 480 9 | FormFactor.Devices = [Desktop] 10 | OnCreate = FormCreate 11 | OnDestroy = FormDestroy 12 | DesignerMasterStyle = 0 13 | object MemoIn: TMemo 14 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 15 | DataDetectorTypes = [] 16 | Align = Client 17 | Size.Width = 466.000000000000000000 18 | Size.Height = 600.000000000000000000 19 | Size.PlatformDefault = False 20 | TabOrder = 1 21 | Viewport.Width = 462.000000000000000000 22 | Viewport.Height = 596.000000000000000000 23 | end 24 | object MemoOut: TMemo 25 | Touch.InteractiveGestures = [Pan, LongTap, DoubleTap] 26 | DataDetectorTypes = [] 27 | Align = Right 28 | Position.X = 466.000000000000000000 29 | Position.Y = 42.000000000000000000 30 | Size.Width = 433.000000000000000000 31 | Size.Height = 600.000000000000000000 32 | Size.PlatformDefault = False 33 | TabOrder = 0 34 | Viewport.Width = 429.000000000000000000 35 | Viewport.Height = 596.000000000000000000 36 | end 37 | object Layout1: TLayout 38 | Align = Top 39 | Size.Width = 899.000000000000000000 40 | Size.Height = 42.000000000000000000 41 | Size.PlatformDefault = False 42 | TabOrder = 2 43 | object ButtonProc: TButton 44 | Position.X = 8.000000000000000000 45 | Position.Y = 10.000000000000000000 46 | TabOrder = 0 47 | Text = 'ButtonProc' 48 | OnClick = ButtonProcClick 49 | end 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /Samples/UpdateOptionJSToClass/Unit5.pas: -------------------------------------------------------------------------------- 1 | unit Unit5; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Memo.Types, 8 | FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, FMX.Layouts, FMX.StdCtrls, 9 | System.JSON, System.Generics.Collections; 10 | 11 | type 12 | TProp = record 13 | AType: string; 14 | AName: string; 15 | FName: string; 16 | end; 17 | 18 | TForm5 = class(TForm) 19 | MemoIn: TMemo; 20 | MemoOut: TMemo; 21 | Layout1: TLayout; 22 | ButtonProc: TButton; 23 | procedure ButtonProcClick(Sender: TObject); 24 | procedure FormCreate(Sender: TObject); 25 | procedure FormDestroy(Sender: TObject); 26 | private 27 | FProps: TList; 28 | procedure ProcUpdateOption(JSON: TJSONObject); 29 | procedure BuildClass; 30 | end; 31 | 32 | var 33 | Form5: TForm5; 34 | 35 | implementation 36 | 37 | {$R *.fmx} 38 | 39 | procedure TForm5.FormCreate(Sender: TObject); 40 | begin 41 | FProps := TList.Create; 42 | end; 43 | 44 | procedure TForm5.FormDestroy(Sender: TObject); 45 | begin 46 | FProps.Free; 47 | end; 48 | 49 | procedure TForm5.ProcUpdateOption(JSON: TJSONObject); 50 | begin 51 | var Prop: TProp; 52 | var AType := JSON.GetValue('value.@type', ''); 53 | if AType = 'optionValueString' then 54 | AType := 'string' 55 | else if AType = 'optionValueInteger' then 56 | AType := 'Int64' 57 | else if AType = 'optionValueBoolean' then 58 | AType := 'Boolean'; 59 | Prop.AType := AType; 60 | Prop.AName := JSON.GetValue('name', ''); 61 | Prop.FName := Prop.AName; 62 | Prop.FName[1] := UpCase(Prop.FName[1]); 63 | Prop.FName := 'F' + Prop.FName; 64 | FProps.Add(Prop); 65 | end; 66 | 67 | procedure TForm5.BuildClass; 68 | begin 69 | MemoOut.Lines.Clear; 70 | MemoOut.Lines.Add('TtgOptions = class'); 71 | MemoOut.Lines.Add('private'); 72 | for var Prop in FProps do 73 | MemoOut.Lines.Add(' ' + Prop.FName + ': ' + Prop.AType + ';'); 74 | MemoOut.Lines.Add('public'); 75 | for var Prop in FProps do 76 | begin 77 | var FieldName := ''; 78 | var PrevC: Char := #0; 79 | for var C in Prop.AName do 80 | begin 81 | if (PrevC = #0) or (PrevC = '_') then 82 | begin 83 | FieldName := FieldName + UpCase(C); 84 | end 85 | else if C <> '_' then 86 | FieldName := FieldName + C; 87 | PrevC := C; 88 | end; 89 | 90 | MemoOut.Lines.Add(' property ' + FieldName + ': ' + Prop.AType + ' read ' + Prop.FName + ';'); 91 | end; 92 | MemoOut.Lines.Add('end;'); 93 | end; 94 | 95 | procedure TForm5.ButtonProcClick(Sender: TObject); 96 | begin 97 | for var Line in MemoIn.Lines do 98 | if Line.StartsWith('{"@type":"updateOption","name":"') then 99 | try 100 | var JSON := TJSONObject.ParseJSONValue(Line) as TJSONObject; 101 | if Assigned(JSON) then 102 | try 103 | ProcUpdateOption(JSON); 104 | finally 105 | JSON.Free; 106 | end; 107 | except 108 | // 109 | end; 110 | BuildClass; 111 | end; 112 | 113 | end. 114 | 115 | -------------------------------------------------------------------------------- /Sources/HGM.JSONParams.pas: -------------------------------------------------------------------------------- 1 | unit HGM.JSONParams; 2 | 3 | interface 4 | 5 | uses 6 | System.Classes, System.JSON, System.Generics.Collections; 7 | 8 | type 9 | TJSONParam = class 10 | private 11 | FJSON: TJSONObject; 12 | procedure SetJSON(const Value: TJSONObject); 13 | function GetCount: Integer; 14 | public 15 | constructor Create; virtual; 16 | destructor Destroy; override; 17 | function Add(const Key: string; const Value: string): TJSONParam; overload; virtual; 18 | function Add(const Key: string; const Value: Int64): TJSONParam; overload; virtual; 19 | function Add(const Key: string; const Value: integer): TJSONParam; overload; virtual; 20 | function Add(const Key: string; const Value: Extended): TJSONParam; overload; virtual; 21 | function Add(const Key: string; const Value: Boolean): TJSONParam; overload; virtual; 22 | function Add(const Key: string; const Value: TDateTime; Format: string): TJSONParam; overload; virtual; 23 | function Add(const Key: string; const Value: TDateTime): TJSONParam; overload; virtual; 24 | function Add(const Key: string; const Value: TJSONValue): TJSONParam; overload; virtual; 25 | function Add(const Key: string; const Value: TJSONParam): TJSONParam; overload; virtual; 26 | function Add(const Key: string; Value: TArray): TJSONParam; overload; virtual; 27 | function Add(const Key: string; Value: TArray): TJSONParam; overload; virtual; 28 | function Add(const Key: string; Value: TArray): TJSONParam; overload; virtual; 29 | function Add(const Key: string; Value: TArray): TJSONParam; overload; virtual; 30 | function Add(const Key: string; Value: TArray): TJSONParam; overload; virtual; 31 | function Add(const Key: string; Value: TArray): TJSONParam; overload; virtual; 32 | function Add(const Key: string; Value: TArray>): TJSONParam; overload; virtual; 33 | function GetOrCreateObject(const Name: string): TJSONObject; 34 | function GetOrCreate(const Name: string): T; 35 | procedure Delete(const Key: string); virtual; 36 | procedure Clear; virtual; 37 | function Clone: TJSONObject; 38 | property Count: Integer read GetCount; 39 | property JSON: TJSONObject read FJSON write SetJSON; 40 | function ToJsonString(FreeObject: Boolean = False): string; virtual; 41 | function ToStream: TStringStream; 42 | end; 43 | 44 | var 45 | DATE_TIME_FORMAT: string = 'DD.MM.YYYY hh:nn'; 46 | 47 | implementation 48 | 49 | uses 50 | System.SysUtils, System.DateUtils; 51 | 52 | { Fetch } 53 | 54 | type 55 | Fetch = class 56 | type 57 | TFetchProc = reference to procedure(const Element: T); 58 | public 59 | class procedure All(const Items: TArray; Proc: TFetchProc); 60 | end; 61 | 62 | { Fetch } 63 | 64 | class procedure Fetch.All(const Items: TArray; Proc: TFetchProc); 65 | var 66 | Item: T; 67 | begin 68 | for Item in Items do 69 | Proc(Item); 70 | end; 71 | 72 | { TJSONParam } 73 | 74 | function TJSONParam.Add(const Key, Value: string): TJSONParam; 75 | begin 76 | Delete(Key); 77 | FJSON.AddPair(Key, Value); 78 | Result := Self; 79 | end; 80 | 81 | function TJSONParam.Add(const Key: string; const Value: TJSONValue): TJSONParam; 82 | begin 83 | Delete(Key); 84 | FJSON.AddPair(Key, Value); 85 | Result := Self; 86 | end; 87 | 88 | function TJSONParam.Add(const Key: string; const Value: TJSONParam): TJSONParam; 89 | begin 90 | try 91 | var JSON := Value.JSON; 92 | Value.JSON := nil; 93 | Add(Key, JSON); 94 | finally 95 | Value.Free; 96 | end; 97 | Result := Self; 98 | end; 99 | 100 | function TJSONParam.Add(const Key: string; const Value: TDateTime): TJSONParam; 101 | begin 102 | Add(Key, TJSONNumber.Create(DateTimeToUnix(Value, False))); 103 | Result := Self; 104 | end; 105 | 106 | function TJSONParam.Add(const Key: string; const Value: TDateTime; Format: string): TJSONParam; 107 | begin 108 | if Format.IsEmpty then 109 | Format := DATE_TIME_FORMAT; 110 | Add(Key, FormatDateTime(Format, System.DateUtils.TTimeZone.local.ToUniversalTime(Value))); 111 | Result := Self; 112 | end; 113 | 114 | function TJSONParam.Add(const Key: string; const Value: Boolean): TJSONParam; 115 | begin 116 | Add(Key, TJSONBool.Create(Value)); 117 | Result := Self; 118 | end; 119 | 120 | function TJSONParam.Add(const Key: string; const Value: Int64): TJSONParam; 121 | begin 122 | Add(Key, TJSONNumber.Create(Value)); 123 | Result := Self; 124 | end; 125 | 126 | function TJSONParam.Add(const Key: string; const Value: Extended): TJSONParam; 127 | begin 128 | Add(Key, TJSONNumber.Create(Value)); 129 | Result := Self; 130 | end; 131 | 132 | function TJSONParam.Add(const Key: string; Value: TArray): TJSONParam; 133 | var 134 | JArr: TJSONArray; 135 | begin 136 | JArr := TJSONArray.Create; 137 | Fetch.All(Value, JArr.AddElement); 138 | Add(Key, JArr); 139 | Result := Self; 140 | end; 141 | 142 | function TJSONParam.Add(const Key: string; Value: TArray): TJSONParam; 143 | var 144 | JArr: TJSONArray; 145 | Item: TJSONParam; 146 | begin 147 | JArr := TJSONArray.Create; 148 | for Item in Value do 149 | begin 150 | try 151 | JArr.AddElement(Item.JSON); 152 | Item.JSON := nil; 153 | finally 154 | Item.Free; 155 | end; 156 | end; 157 | 158 | Add(Key, JArr); 159 | Result := Self; 160 | end; 161 | 162 | function TJSONParam.Add(const Key: string; Value: TArray): TJSONParam; 163 | var 164 | JArr: TJSONArray; 165 | Item: Byte; 166 | begin 167 | JArr := TJSONArray.Create; 168 | for Item in Value do 169 | JArr.Add(Item); 170 | 171 | Add(Key, JArr); 172 | Result := Self; 173 | end; 174 | 175 | function TJSONParam.Add(const Key: string; Value: TArray): TJSONParam; 176 | var 177 | JArr: TJSONArray; 178 | Item: Integer; 179 | begin 180 | JArr := TJSONArray.Create; 181 | for Item in Value do 182 | JArr.Add(Item); 183 | 184 | Add(Key, JArr); 185 | Result := Self; 186 | end; 187 | 188 | function TJSONParam.Add(const Key: string; const Value: integer): TJSONParam; 189 | begin 190 | Add(Key, TJSONNumber.Create(Value)); 191 | Result := Self; 192 | end; 193 | 194 | function TJSONParam.Add(const Key: string; Value: TArray): TJSONParam; 195 | var 196 | JArr: TJSONArray; 197 | Item: Int64; 198 | begin 199 | JArr := TJSONArray.Create; 200 | for Item in Value do 201 | JArr.Add(Item); 202 | 203 | Add(Key, JArr); 204 | Result := Self; 205 | end; 206 | 207 | function TJSONParam.Add(const Key: string; Value: TArray): TJSONParam; 208 | var 209 | JArr: TJSONArray; 210 | Item: string; 211 | begin 212 | JArr := TJSONArray.Create; 213 | for Item in Value do 214 | JArr.Add(Item); 215 | 216 | Add(Key, JArr); 217 | Result := Self; 218 | end; 219 | 220 | procedure TJSONParam.Clear; 221 | begin 222 | FJSON.Free; 223 | FJSON := TJSONObject.Create; 224 | end; 225 | 226 | function TJSONParam.Clone: TJSONObject; 227 | begin 228 | Result := TJSONObject(FJSON.Clone); 229 | end; 230 | 231 | constructor TJSONParam.Create; 232 | begin 233 | FJSON := TJSONObject.Create; 234 | end; 235 | 236 | procedure TJSONParam.Delete(const Key: string); 237 | var 238 | Item: TJSONPair; 239 | begin 240 | Item := FJSON.RemovePair(Key); 241 | if Assigned(Item) then 242 | Item.Free; 243 | end; 244 | 245 | destructor TJSONParam.Destroy; 246 | begin 247 | if Assigned(FJSON) then 248 | FJSON.Free; 249 | inherited; 250 | end; 251 | 252 | function TJSONParam.GetCount: Integer; 253 | begin 254 | Result := FJSON.Count; 255 | end; 256 | 257 | function TJSONParam.GetOrCreate(const Name: string): T; 258 | begin 259 | if not FJSON.TryGetValue(Name, Result) then 260 | begin 261 | Result := T.Create; 262 | FJSON.AddPair(Name, Result); 263 | end; 264 | end; 265 | 266 | function TJSONParam.GetOrCreateObject(const Name: string): TJSONObject; 267 | begin 268 | Result := GetOrCreate(Name); 269 | end; 270 | 271 | procedure TJSONParam.SetJSON(const Value: TJSONObject); 272 | begin 273 | FJSON := Value; 274 | end; 275 | 276 | function TJSONParam.ToJsonString(FreeObject: Boolean): string; 277 | begin 278 | Result := FJSON.ToJSON; 279 | if FreeObject then 280 | Free; 281 | end; 282 | 283 | function TJSONParam.ToStream: TStringStream; 284 | begin 285 | Result := TStringStream.Create; 286 | try 287 | Result.WriteString(ToJsonString); 288 | Result.Position := 0; 289 | except 290 | Result.Free; 291 | raise; 292 | end; 293 | end; 294 | 295 | function TJSONParam.Add(const Key: string; Value: TArray>): TJSONParam; 296 | var 297 | JArr: TJSONArray; 298 | JRow: TJSONArray; 299 | Item: TJSONParam; 300 | ItemRow: TArray; 301 | begin 302 | JArr := TJSONArray.Create; 303 | for ItemRow in Value do 304 | begin 305 | JRow := TJSONArray.Create; 306 | for Item in ItemRow do 307 | begin 308 | try 309 | JRow.AddElement(Item.JSON); 310 | Item.JSON := nil; 311 | finally 312 | Item.Free; 313 | end; 314 | end; 315 | JArr.Add(JRow); 316 | end; 317 | 318 | Add(Key, JArr); 319 | Result := Self; 320 | end; 321 | 322 | end. 323 | 324 | -------------------------------------------------------------------------------- /Sources/TGC.Builder.GetMe.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Builder.GetMe; 2 | 3 | interface 4 | 5 | uses 6 | TGC.Classes; 7 | 8 | type 9 | /// 10 | /// Returns the current user. 11 | /// 12 | TGetMe = class(TParam) 13 | constructor Create; reintroduce; 14 | end; 15 | 16 | implementation 17 | 18 | { TGetMe } 19 | 20 | constructor TGetMe.Create; 21 | begin 22 | inherited Create('getMe'); 23 | end; 24 | 25 | end. 26 | 27 | -------------------------------------------------------------------------------- /Sources/TGC.Builder.GetUser.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Builder.GetUser; 2 | 3 | interface 4 | 5 | uses 6 | TGC.Classes; 7 | 8 | type 9 | /// 10 | /// Returns information about a user by their identifier. This is an offline request if the current user is not a bot. 11 | /// 12 | TGetUser = class(TParam) 13 | constructor Create; reintroduce; 14 | /// 15 | /// User identifier. 16 | /// 17 | function UserId(const Value: Int64): TGetUser; 18 | end; 19 | 20 | implementation 21 | 22 | { TGetUser } 23 | 24 | constructor TGetUser.Create; 25 | begin 26 | inherited Create('getUser'); 27 | end; 28 | 29 | function TGetUser.UserId(const Value: Int64): TGetUser; 30 | begin 31 | Result := TGetUser(Add('user_id', Value)); 32 | end; 33 | 34 | end. 35 | 36 | -------------------------------------------------------------------------------- /Sources/TGC.Builder.GetUserFullInfo.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Builder.GetUserFullInfo; 2 | 3 | interface 4 | 5 | uses 6 | TGC.Classes; 7 | 8 | type 9 | /// 10 | /// Returns full information about a user by their identifier. 11 | /// 12 | TGetUserFullInfo = class(TParam) 13 | constructor Create; reintroduce; 14 | /// 15 | /// User identifier. 16 | /// 17 | function UserId(const Value: Int64): TGetUserFullInfo; 18 | end; 19 | 20 | implementation 21 | 22 | { TGetUserFullInfo } 23 | 24 | constructor TGetUserFullInfo.Create; 25 | begin 26 | inherited Create('getUserFullInfo'); 27 | end; 28 | 29 | function TGetUserFullInfo.UserId(const Value: Int64): TGetUserFullInfo; 30 | begin 31 | Result := TGetUserFullInfo(Add('user_id', Value)); 32 | end; 33 | 34 | end. 35 | 36 | -------------------------------------------------------------------------------- /Sources/TGC.Builder.SendMessageAlbum.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Builder.SendMessageAlbum; 2 | 3 | interface 4 | 5 | uses 6 | TGC.Classes, TGC.Builder.SendMessage; 7 | 8 | type 9 | /// 10 | /// Sends 2-10 messages grouped together into an album. Currently, only audio, document, photo and video messages can be grouped into an album. Documents and audio files can be only grouped in an album with messages of the same type. Returns sent messages. 11 | /// 12 | TSendMessageAlbum = class(TParam) 13 | /// 14 | /// Target chat. 15 | /// 16 | function ChatId(const Value: Int64): TSendMessageAlbum; 17 | /// 18 | /// If not 0, a message thread identifier in which the message will be sent. 19 | /// 20 | function MessageThreadId(const Value: Int64): TSendMessageAlbum; 21 | /// 22 | /// Identifier of the message to reply to or 0. 23 | /// 24 | function ReplyToMessageId(const Value: Int64): TSendMessageAlbum; 25 | /// 26 | /// Contents of messages to be sent. At most 10 messages can be added to an album. 27 | /// 28 | function InputMessageContents(const Value: TArray): TSendMessageAlbum; 29 | /// 30 | /// Options to be used to send the message; pass null to use default options. 31 | /// 32 | function Options(const Value: TMessageSendOptions): TSendMessageAlbum; 33 | constructor Create; reintroduce; 34 | end; 35 | 36 | implementation 37 | 38 | uses 39 | HGM.JSONParams; 40 | 41 | { TSendMessageAlbum } 42 | 43 | function TSendMessageAlbum.ChatId(const Value: Int64): TSendMessageAlbum; 44 | begin 45 | Result := TSendMessageAlbum(Add('chat_id', Value)); 46 | end; 47 | 48 | constructor TSendMessageAlbum.Create; 49 | begin 50 | inherited Create('sendMessageAlbum'); 51 | end; 52 | 53 | function TSendMessageAlbum.InputMessageContents(const Value: TArray): TSendMessageAlbum; 54 | begin 55 | Result := TSendMessageAlbum(Add('input_message_contents', TArray(Value))); 56 | end; 57 | 58 | function TSendMessageAlbum.MessageThreadId(const Value: Int64): TSendMessageAlbum; 59 | begin 60 | Result := TSendMessageAlbum(Add('message_thread_id', Value)); 61 | end; 62 | 63 | function TSendMessageAlbum.Options(const Value: TMessageSendOptions): TSendMessageAlbum; 64 | begin 65 | Result := TSendMessageAlbum(Add('options', Value)); 66 | end; 67 | 68 | function TSendMessageAlbum.ReplyToMessageId(const Value: Int64): TSendMessageAlbum; 69 | begin 70 | Result := TSendMessageAlbum(Add('reply_to_message_id', Value)); 71 | end; 72 | 73 | end. 74 | 75 | -------------------------------------------------------------------------------- /Sources/TGC.Classes.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Classes; 2 | 3 | interface 4 | 5 | uses 6 | System.Classes, HGM.JSONParams, System.Generics.Collections, System.SysUtils; 7 | 8 | type 9 | TThreadObject = class 10 | private 11 | FLock: TObject; 12 | protected 13 | FObject: T; 14 | public 15 | constructor Create; 16 | destructor Destroy; override; 17 | function Lock: T; 18 | procedure Locked(Proc: TProc); 19 | procedure Unlock; inline; 20 | end; 21 | 22 | TSafeDictionary = class(TDictionary) 23 | constructor Create; 24 | end; 25 | 26 | TThreadDict = class(TThreadObject>) 27 | public 28 | procedure Add(const Key: KeyType; const Item: ValueType); 29 | procedure Clear; 30 | procedure Remove(const Key: KeyType); inline; 31 | end; 32 | 33 | TParam = class(TJSONParam) 34 | function Extra(const Value: Int64): TParam; 35 | constructor Create(AType: string); reintroduce; 36 | end; 37 | 38 | implementation 39 | 40 | { TParam } 41 | 42 | constructor TParam.Create(AType: string); 43 | begin 44 | inherited Create; 45 | Add('@type', AType); 46 | end; 47 | 48 | function TParam.Extra(const Value: Int64): TParam; 49 | begin 50 | Result := TParam(Add('@extra', Value)); 51 | end; 52 | 53 | { TThreadObject } 54 | 55 | constructor TThreadObject.Create; 56 | begin 57 | if T.ClassName.StartsWith('TDictionary<') then 58 | raise Exception.Create('Not allow default TDictionary'); 59 | inherited Create; 60 | FLock := TObject.Create; 61 | FObject := T.Create; 62 | end; 63 | 64 | destructor TThreadObject.Destroy; 65 | begin 66 | Lock; 67 | try 68 | FObject.Free; 69 | inherited Destroy; 70 | finally 71 | Unlock; 72 | FLock.Free; 73 | end; 74 | end; 75 | 76 | function TThreadObject.Lock: T; 77 | begin 78 | TMonitor.Enter(FLock); 79 | Result := FObject; 80 | end; 81 | 82 | procedure TThreadObject.Locked(Proc: TProc); 83 | begin 84 | Lock; 85 | try 86 | Proc(FObject); 87 | finally 88 | Unlock; 89 | end; 90 | end; 91 | 92 | procedure TThreadObject.Unlock; 93 | begin 94 | TMonitor.Exit(FLock); 95 | end; 96 | { TThreadDict } 97 | 98 | procedure TThreadDict.Add(const Key: KeyType; const Item: ValueType); 99 | begin 100 | Lock; 101 | try 102 | FObject.AddOrSetValue(Key, Item); 103 | finally 104 | Unlock; 105 | end; 106 | end; 107 | 108 | procedure TThreadDict.Clear; 109 | begin 110 | Lock; 111 | try 112 | FObject.Clear; 113 | finally 114 | Unlock; 115 | end; 116 | end; 117 | 118 | procedure TThreadDict.Remove(const Key: KeyType); 119 | begin 120 | Lock; 121 | try 122 | Remove(Key); 123 | finally 124 | Unlock; 125 | end; 126 | end; 127 | { TSafeDictionary } 128 | 129 | constructor TSafeDictionary.Create; 130 | begin 131 | inherited Create(0); 132 | end; 133 | 134 | end. 135 | 136 | -------------------------------------------------------------------------------- /Sources/TGC.Client.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Client; 2 | 3 | interface 4 | 5 | uses 6 | System.Classes, System.SysUtils, System.Generics.Collections, System.Threading, 7 | System.JSON, TGC.Wrapper, TGC.Handler, TGC.Handler.UpdateAuthorizationState, 8 | TGC.Entity.User, TGC.Classes, TGC.Options, TGC.Builder.SendMessage, 9 | TGC.Entity.Message, TGC.Builder.SendMessageAlbum, TGC.Builder.GetMe, 10 | TGC.Builder.GetUser, TGC.Entity.UserFullInfo, TGC.Builder.GetUserFullInfo; 11 | 12 | const 13 | DEFAULT_WAIT_TIMEOUT = 10.0; 14 | 15 | type 16 | TRequestId = Int64; 17 | 18 | TTelegramClientCustom = class; 19 | 20 | TOnReceiveRaw = procedure(Sender: TObject; const Data: string) of object; 21 | 22 | TOnNeedAuthConfirm = procedure(Sender: TObject; const Link: string) of object; 23 | 24 | TOnNeedRegistration = procedure(Sender: TObject; const Terms: TTermsOfService) of object; 25 | 26 | TOnError = procedure(Sender: TObject; const Code: Integer; const Message: string) of object; 27 | 28 | THandlers = TObjectDictionary; 29 | 30 | TTDLibParameters = class(TPersistent) 31 | private 32 | FUseFileDatabase: Boolean; 33 | FDatabaseDirectory: string; 34 | FUseChatInfoDatabase: Boolean; 35 | FFilesDirectory: string; 36 | FUseMessageDatabase: Boolean; 37 | FUseSecretChats: Boolean; 38 | FEnableStorageOptimizer: Boolean; 39 | FIgnoreFileNames: Boolean; 40 | FSystemVersion: string; 41 | FDeviceModel: string; 42 | FSystemLanguageCode: string; 43 | FApplicationVersion: string; 44 | FDatabaseEncryptionKey: string; 45 | procedure SetDatabaseDirectory(const Value: string); 46 | procedure SetFilesDirectory(const Value: string); 47 | procedure SetUseChatInfoDatabase(const Value: Boolean); 48 | procedure SetUseFileDatabase(const Value: Boolean); 49 | procedure SetUseMessageDatabase(const Value: Boolean); 50 | procedure SetUseSecretChats(const Value: Boolean); 51 | procedure SetApplicationVersion(const Value: string); 52 | procedure SetDeviceModel(const Value: string); 53 | procedure SetEnableStorageOptimizer(const Value: Boolean); 54 | procedure SetIgnoreFileNames(const Value: Boolean); 55 | procedure SetSystemLanguageCode(const Value: string); 56 | procedure SetSystemVersion(const Value: string); 57 | procedure SetDatabaseEncryptionKey(const Value: string); 58 | published 59 | /// 60 | /// The path to the directory for the persistent database; if empty, the current working directory will be used. 61 | /// 62 | property DatabaseDirectory: string read FDatabaseDirectory write SetDatabaseDirectory; 63 | /// 64 | /// The path to the directory for storing files; if empty, DatabaseDirectory will be used. 65 | /// 66 | property FilesDirectory: string read FFilesDirectory write SetFilesDirectory; 67 | /// 68 | /// If set to true, information about downloaded and uploaded files will be saved between application restarts. 69 | /// 70 | property UseFileDatabase: Boolean read FUseFileDatabase write SetUseFileDatabase default True; 71 | /// 72 | /// If set to true, the library will maintain a cache of users, basic groups, supergroups, channels and secret chats. Implies UseFileDatabase. 73 | /// 74 | property UseChatInfoDatabase: Boolean read FUseChatInfoDatabase write SetUseChatInfoDatabase default True; 75 | /// 76 | /// If set to true, the library will maintain a cache of chats and messages. Implies UseChatInfoDatabase. 77 | /// 78 | property UseMessageDatabase: Boolean read FUseMessageDatabase write SetUseMessageDatabase default True; 79 | /// 80 | /// If set to true, support for secret chats will be enabled. 81 | /// 82 | property UseSecretChats: Boolean read FUseSecretChats write SetUseSecretChats default True; 83 | /// 84 | /// IETF language tag of the user's operating system language; must be non-empty. 85 | /// 86 | property SystemLanguageCode: string read FSystemLanguageCode write SetSystemLanguageCode; 87 | /// 88 | /// Model of the device the application is being run on; must be non-empty. 89 | /// 90 | property DeviceModel: string read FDeviceModel write SetDeviceModel; 91 | /// 92 | /// Version of the operating system the application is being run on. If empty, the version is automatically detected by TDLib. 93 | /// 94 | property SystemVersion: string read FSystemVersion write SetSystemVersion; 95 | /// 96 | /// Application version; must be non-empty. 97 | /// 98 | property ApplicationVersion: string read FApplicationVersion write SetApplicationVersion; 99 | /// 100 | /// If set to true, old files will automatically be deleted. 101 | /// 102 | property EnableStorageOptimizer: Boolean read FEnableStorageOptimizer write SetEnableStorageOptimizer default False; 103 | /// 104 | /// If set to true, original file names will be ignored. Otherwise, downloaded files will be saved under names as close as possible to the original name. 105 | /// 106 | property IgnoreFileNames: Boolean read FIgnoreFileNames write SetIgnoreFileNames default False; 107 | /// 108 | /// Encryption key for database to let know TDLib how to open the database 109 | /// 110 | property DatabaseEncryptionKey: string read FDatabaseEncryptionKey write SetDatabaseEncryptionKey; 111 | end; 112 | 113 | TDLibMethods = class 114 | private 115 | FPoll: TThreadDict>; 116 | FClient: TTelegramClientCustom; 117 | FRequestQueue: TRequestId; 118 | FSync: Boolean; 119 | function NewRequestId: TRequestId; 120 | procedure SetSync(const Value: Boolean); 121 | procedure Sync(Proc: TProc); 122 | protected 123 | procedure Clear; 124 | function Proc(const RequestId: TRequestId; JSON: TJSONObject): Boolean; 125 | property SyncCallback: Boolean read FSync write SetSync; 126 | public 127 | /// 128 | /// Returns the current user. 129 | /// 130 | procedure GetMe(Callback: TProc); 131 | /// 132 | /// Returns information about a user by their identifier. This is an offline request if the current user is not a bot. 133 | /// 134 | procedure GetUser(UserId: Int64; Callback: TProc); 135 | /// 136 | /// Returns full information about a user by their identifier. 137 | /// 138 | procedure GetUserFullInfo(UserId: Int64; Callback: TProc); 139 | /// 140 | /// Sends a message. Returns the sent message. 141 | /// 142 | procedure SendMessage(Params: TSendMessage; Callback: TProc); 143 | /// 144 | /// Sends 2-10 messages grouped together into an album. Currently, only audio, document, photo and video messages can be grouped into an album. Documents and audio files can be only grouped in an album with messages of the same type. Returns sent messages. 145 | /// 146 | procedure SendMessageAlbum(Params: TSendMessageAlbum; Callback: TProc); 147 | procedure Execute(Query: TParam; FieldName: string; Callback: TProc); overload; 148 | procedure Execute(Query: TParam; FieldName: string; Callback: TProc); overload; 149 | constructor Create(Client: TTelegramClientCustom); 150 | destructor Destroy; override; 151 | end; 152 | 153 | TTelegramClientCustom = class(TComponent) 154 | private 155 | FClient: TVoid; 156 | FReceiver: ITask; 157 | FOnReceive: TOnReceiveRaw; 158 | FDoStopReceiver: Boolean; 159 | FSyncEvents: Boolean; 160 | FTimeout: Double; 161 | FHandlers: THandlers; 162 | FUseTestDC: Boolean; 163 | FParameters: TTDLibParameters; 164 | FApiHash: string; 165 | FApiId: Int32; 166 | FBotToken: string; 167 | FPhoneNumber: string; 168 | FOnNeedAuthCode: TNotifyEvent; 169 | FOnRegistration: TOnNeedRegistration; 170 | FOnNeedAuthPassword: TNotifyEvent; 171 | FOnNeedAuthConfirm: TOnNeedAuthConfirm; 172 | FOnAuthReady: TNotifyEvent; 173 | FOnError: TOnError; 174 | FMethods: TDLibMethods; 175 | FOnClose: TNotifyEvent; 176 | FOptions: TtgOptions; 177 | function GetIsInitialized: Boolean; 178 | procedure SetOnReceive(const Value: TOnReceiveRaw); 179 | procedure StartReceiver; 180 | procedure ReceiverWorker; 181 | procedure SetSyncEvents(const Value: Boolean); 182 | procedure SetTimeout(const Value: Double); 183 | procedure ProcReceive(JSON: TJSONObject); 184 | procedure DoReceiveRaw(const JSON: string); 185 | procedure CreateHandlers; 186 | procedure SetUseTestDC(const Value: Boolean); 187 | procedure SetApiHash(const Value: string); 188 | procedure SetApiId(const Value: Int32); 189 | procedure DefaultParameters; 190 | function GetInternalSystemLangCode: string; 191 | procedure SetBotToken(const Value: string); 192 | procedure SetPhoneNumber(const Value: string); 193 | procedure SetOnNeedAuthCode(const Value: TNotifyEvent); 194 | procedure SetOnRegistration(const Value: TOnNeedRegistration); 195 | procedure SetOnNeedAuthPassword(const Value: TNotifyEvent); 196 | procedure SetOnNeedAuthConfirm(const Value: TOnNeedAuthConfirm); 197 | procedure SetOnAuthReady(const Value: TNotifyEvent); 198 | procedure SetOnError(const Value: TOnError); 199 | function InternalRecreate: Boolean; 200 | procedure DoClose; 201 | procedure SetOnClose(const Value: TNotifyEvent); 202 | procedure SetSyncMethodsCallback(const Value: Boolean); 203 | function GetSyncMethodsCallback: Boolean; 204 | procedure Sync(Proc: TProc); 205 | protected 206 | FInitializedLib: Boolean; 207 | function InitializateLib: Boolean; 208 | procedure InternalClose; 209 | public 210 | // service 211 | procedure Close; 212 | procedure NeedAuthCode; 213 | procedure NeedRegistration(Terms: TTermsOfService); 214 | procedure NeedAuthenticationPassword; 215 | procedure NeedOtherDeviceConfirmation(const Link: string); 216 | procedure AuthReady; 217 | procedure Send(const JSON: TJSONObject; AutoFree: Boolean = True); overload; 218 | procedure Send(const AType, AName: string; const JSON: TJSONValue); overload; 219 | procedure Send(const AType: string; APairs: TArray>); overload; 220 | function Receive(const TimeOut: Double): TJSONObject; 221 | function Execute(const JSON: TJSONObject; AutoFree: Boolean = True): TJSONObject; 222 | procedure Error(const Code: Integer; const Message: string); 223 | // user 224 | constructor Create(AOwner: TComponent); override; 225 | destructor Destroy; override; 226 | property Client: TVoid read FClient; 227 | property IsInitialized: Boolean read GetIsInitialized; 228 | function Initializate: Boolean; 229 | procedure SetAuthCode(const Value: string); 230 | procedure SetRegisterUser(const FirstName, LastName: string); 231 | procedure SetAuthPassword(const Value: string); 232 | /// 233 | /// Accessing API Methods 234 | /// 235 | property Methods: TDLibMethods read FMethods; 236 | /// 237 | /// List of session options 238 | /// 239 | property Options: TtgOptions read FOptions; 240 | published 241 | property OnReceive: TOnReceiveRaw read FOnReceive write SetOnReceive; 242 | property SyncEvents: Boolean read FSyncEvents write SetSyncEvents; 243 | property SyncMethodsCallback: Boolean read GetSyncMethodsCallback write SetSyncMethodsCallback; 244 | property Timeout: Double read FTimeout write SetTimeout; 245 | property UseTestDC: Boolean read FUseTestDC write SetUseTestDC; 246 | property Parameters: TTDLibParameters read FParameters write FParameters; 247 | property ApiId: Int32 read FApiId write SetApiId; 248 | property ApiHash: string read FApiHash write SetApiHash; 249 | property BotToken: string read FBotToken write SetBotToken; 250 | property PhoneNumber: string read FPhoneNumber write SetPhoneNumber; 251 | property OnNeedAuthCode: TNotifyEvent read FOnNeedAuthCode write SetOnNeedAuthCode; 252 | property OnRegistration: TOnNeedRegistration read FOnRegistration write SetOnRegistration; 253 | property OnNeedAuthPassword: TNotifyEvent read FOnNeedAuthPassword write SetOnNeedAuthPassword; 254 | property OnNeedAuthConfirm: TOnNeedAuthConfirm read FOnNeedAuthConfirm write SetOnNeedAuthConfirm; 255 | property OnAuthReady: TNotifyEvent read FOnAuthReady write SetOnAuthReady; 256 | property OnClose: TNotifyEvent read FOnClose write SetOnClose; 257 | property OnError: TOnError read FOnError write SetOnError; 258 | end; 259 | 260 | TTelegramClient = class(TTelegramClientCustom) 261 | published 262 | /// 263 | /// Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org. 264 | /// 265 | property ApiHash; 266 | /// 267 | /// Application identifier for Telegram API access, which can be obtained at https://my.telegram.org. 268 | /// 269 | property ApiId default 0; 270 | /// 271 | /// Bot token for use client as bot 272 | /// 273 | property BotToken; 274 | /// 275 | /// The user has been successfully authorized. TDLib is now ready to answer queries. 276 | /// 277 | property OnAuthReady; 278 | /// 279 | /// TDLib client is in its final state. All databases are closed and all resources are released. 280 | /// No other updates will be received after this. All queries will be responded to with error code 500. 281 | /// To continue working, one must create a new instance of the TDLib client. 282 | /// 283 | property OnClose; 284 | /// 285 | /// Error handle 286 | /// 287 | property OnError; 288 | /// 289 | /// Authorization code needed. Use SetAuthCode 290 | /// 291 | property OnNeedAuthCode; 292 | /// 293 | /// The user needs to confirm authorization on another logged in device by scanning a QR code 294 | /// with the provided link 295 | /// 296 | property OnNeedAuthConfirm; 297 | /// 298 | /// The user has been authorized, but needs to enter a password to start using the application. 299 | /// Use SetAuthPassword 300 | /// 301 | property OnNeedAuthPassword; 302 | /// 303 | /// TDLib receive raw data 304 | /// 305 | property OnReceive; 306 | /// 307 | /// Finishes user registration. Use SetRegisterUser 308 | /// 309 | property OnRegistration; 310 | /// 311 | /// Contains parameters for TDLib initialization. 312 | /// 313 | property Parameters; 314 | /// 315 | /// User phone number 316 | /// 317 | property PhoneNumber; 318 | /// 319 | /// Do synchronize component events 320 | /// 321 | property SyncEvents default False; 322 | /// 323 | /// Do synchronize methods callback 324 | /// 325 | property SyncMethodsCallback default False; 326 | /// 327 | /// Receive timeout (in seconds). Default 10.0 sec 328 | /// 329 | property Timeout; 330 | /// 331 | /// If set to true, the Telegram test environment will be used instead of the production environment. 332 | /// 333 | property UseTestDC default False; 334 | end; 335 | 336 | implementation 337 | 338 | uses 339 | TGC.Handler.Error, REST.Json, TGC.Handler.UpdateOption; 340 | 341 | { TTelegramClientCustom } 342 | 343 | procedure TTelegramClientCustom.InternalClose; 344 | begin 345 | FMethods.Clear; 346 | if FReceiver <> nil then 347 | begin 348 | FDoStopReceiver := True; 349 | FReceiver.Wait; 350 | FReceiver := nil; 351 | end; 352 | if FClient <> 0 then 353 | begin 354 | JsonClientDestroy(FClient); 355 | FClient := 0; 356 | end; 357 | end; 358 | 359 | procedure TTelegramClientCustom.Close; 360 | begin 361 | InternalClose; 362 | DoClose; 363 | end; 364 | 365 | constructor TTelegramClientCustom.Create; 366 | begin 367 | inherited; 368 | FInitializedLib := False; 369 | FOptions := TtgOptions.Create; 370 | FMethods := TDLibMethods.Create(Self); 371 | FHandlers := THandlers.Create([doOwnsValues]); 372 | FParameters := TTDLibParameters.Create; 373 | DefaultParameters; 374 | CreateHandlers; 375 | FClient := 0; 376 | FReceiver := nil; 377 | FTimeout := DEFAULT_WAIT_TIMEOUT; 378 | FSyncEvents := False; 379 | FDoStopReceiver := False; 380 | end; 381 | 382 | destructor TTelegramClientCustom.Destroy; 383 | begin 384 | InternalClose; 385 | FMethods.Free; 386 | FHandlers.Free; 387 | FParameters.Free; 388 | FOptions.Free; 389 | TDLibFinalize; 390 | inherited; 391 | end; 392 | 393 | procedure TTelegramClientCustom.Sync(Proc: TProc); 394 | begin 395 | TThread.Queue(nil, 396 | procedure 397 | begin 398 | Proc; 399 | end); 400 | end; 401 | 402 | procedure TTelegramClientCustom.Error(const Code: Integer; const Message: string); 403 | begin 404 | if Assigned(FOnError) then 405 | if FSyncEvents then 406 | Sync( 407 | procedure 408 | begin 409 | FOnError(Self, Code, Message); 410 | end) 411 | else 412 | FOnError(Self, Code, Message); 413 | end; 414 | 415 | function TTelegramClientCustom.Execute(const JSON: TJSONObject; AutoFree: Boolean): TJSONObject; 416 | var 417 | JSONString: string; 418 | begin 419 | Result := nil; 420 | try 421 | JSONString := JSON.ToJSON; 422 | finally 423 | if AutoFree then 424 | JSON.Free; 425 | end; 426 | JSONString := TgCharToString(JsonClientExecute(FClient, StringToTgChar(JSONString))); 427 | if not JSONString.IsEmpty then 428 | Result := TJSONObject.ParseJSONValue(JSONString) as TJSONObject; 429 | end; 430 | 431 | function TTelegramClientCustom.GetIsInitialized: Boolean; 432 | begin 433 | Result := FClient <> 0; 434 | end; 435 | 436 | function TTelegramClientCustom.GetSyncMethodsCallback: Boolean; 437 | begin 438 | Result := FMethods.SyncCallback; 439 | end; 440 | 441 | function TTelegramClientCustom.GetInternalSystemLangCode: string; 442 | var 443 | ID: Integer; 444 | begin 445 | ID := Languages.IndexOf(Languages.UserDefaultLocale); 446 | if ID >= 0 then 447 | Result := Languages.LocaleName[ID].SubString(0, 2) 448 | else 449 | Result := ''; 450 | end; 451 | 452 | procedure TTelegramClientCustom.DefaultParameters; 453 | begin 454 | FParameters.DatabaseDirectory := 'tdlib'; 455 | FParameters.FilesDirectory := 'tdlib_files'; 456 | FParameters.UseFileDatabase := True; 457 | FParameters.UseChatInfoDatabase := True; 458 | FParameters.UseMessageDatabase := True; 459 | FParameters.UseSecretChats := True; 460 | FParameters.SystemLanguageCode := GetInternalSystemLangCode; 461 | FParameters.ApplicationVersion := '0.1'; 462 | FParameters.DeviceModel := 'Desktop'; 463 | end; 464 | 465 | procedure TTelegramClientCustom.CreateHandlers; 466 | begin 467 | FHandlers.Clear; 468 | FHandlers.Add('error', TError.Create(Self)); 469 | FHandlers.Add('updateAuthorizationState', TUpdateAuthorizationState.Create(Self)); 470 | FHandlers.Add('updateOption', TUpdateOption.Create(Self)); 471 | end; 472 | 473 | function TTelegramClientCustom.InternalRecreate: Boolean; 474 | begin 475 | InternalClose; 476 | FClient := JsonCreateClient; 477 | StartReceiver; 478 | Result := IsInitialized; 479 | end; 480 | 481 | function TTelegramClientCustom.Initializate: Boolean; 482 | begin 483 | Result := InitializateLib and InternalRecreate; 484 | end; 485 | 486 | function TTelegramClientCustom.InitializateLib: Boolean; 487 | begin 488 | if not FInitializedLib then 489 | FInitializedLib := TDLibInitialize; 490 | Result := FInitializedLib; 491 | end; 492 | 493 | procedure TTelegramClientCustom.AuthReady; 494 | begin 495 | if Assigned(FOnAuthReady) then 496 | if FSyncEvents then 497 | Sync( 498 | procedure 499 | begin 500 | FOnAuthReady(Self); 501 | end) 502 | else 503 | FOnAuthReady(Self); 504 | end; 505 | 506 | procedure TTelegramClientCustom.DoClose; 507 | begin 508 | if Assigned(FOnClose) then 509 | if FSyncEvents then 510 | Sync( 511 | procedure 512 | begin 513 | FOnClose(Self); 514 | end) 515 | else 516 | FOnClose(Self); 517 | end; 518 | 519 | procedure TTelegramClientCustom.NeedAuthCode; 520 | begin 521 | if Assigned(FOnNeedAuthCode) then 522 | if FSyncEvents then 523 | Sync( 524 | procedure 525 | begin 526 | FOnNeedAuthCode(Self); 527 | end) 528 | else 529 | FOnNeedAuthCode(Self); 530 | end; 531 | 532 | procedure TTelegramClientCustom.NeedAuthenticationPassword; 533 | begin 534 | if Assigned(FOnNeedAuthPassword) then 535 | if FSyncEvents then 536 | Sync( 537 | procedure 538 | begin 539 | FOnNeedAuthPassword(Self); 540 | end) 541 | else 542 | FOnNeedAuthPassword(Self); 543 | end; 544 | 545 | procedure TTelegramClientCustom.NeedOtherDeviceConfirmation(const Link: string); 546 | begin 547 | if Assigned(FOnNeedAuthConfirm) then 548 | if FSyncEvents then 549 | Sync( 550 | procedure 551 | begin 552 | FOnNeedAuthConfirm(Self, Link); 553 | end) 554 | else 555 | FOnNeedAuthConfirm(Self, Link); 556 | end; 557 | 558 | procedure TTelegramClientCustom.NeedRegistration(Terms: TTermsOfService); 559 | begin 560 | if Assigned(FOnRegistration) then 561 | if FSyncEvents then 562 | Sync( 563 | procedure 564 | begin 565 | try 566 | FOnRegistration(Self, Terms); 567 | finally 568 | Terms.Free; 569 | end; 570 | end) 571 | else 572 | try 573 | FOnRegistration(Self, Terms); 574 | finally 575 | Terms.Free; 576 | end 577 | else 578 | Terms.Free; 579 | end; 580 | 581 | procedure TTelegramClientCustom.DoReceiveRaw(const JSON: string); 582 | begin 583 | if Assigned(FOnReceive) then 584 | if FSyncEvents then 585 | Sync( 586 | procedure 587 | begin 588 | FOnReceive(Self, JSON); 589 | end) 590 | else 591 | FOnReceive(Self, JSON); 592 | end; 593 | 594 | procedure TTelegramClientCustom.StartReceiver; 595 | begin 596 | FReceiver := TTask.Run(ReceiverWorker); 597 | end; 598 | 599 | procedure TTelegramClientCustom.ReceiverWorker; 600 | begin 601 | while not ((FDoStopReceiver) or (TTask.CurrentTask.Status = TTaskStatus.Canceled)) do 602 | try 603 | ProcReceive(Receive(FTimeout)); 604 | except 605 | on E: Exception do 606 | Error(-1, E.Message); 607 | end; 608 | end; 609 | 610 | function TTelegramClientCustom.Receive(const TimeOut: Double): TJSONObject; 611 | var 612 | JSONString: string; 613 | begin 614 | Result := nil; 615 | JSONString := TgCharToString(JsonClientReceive(FClient, TimeOut)); 616 | if not JSONString.IsEmpty then 617 | Result := TJSONObject.ParseJSONValue(JSONString) as TJSONObject; 618 | end; 619 | 620 | procedure TTelegramClientCustom.ProcReceive(JSON: TJSONObject); 621 | var 622 | AExtra: TRequestId; 623 | AHandler: THandler; 624 | begin 625 | if Assigned(JSON) then 626 | try 627 | // Событие с сырыми данными для пользовательской обработки 628 | DoReceiveRaw(JSON.ToJSON); 629 | 630 | // Обработка запросов с указанным RequestId 631 | AExtra := JSON.GetValue('@extra', -1); 632 | if AExtra >= 0 then 633 | if FMethods.Proc(AExtra, JSON) then 634 | Exit; 635 | 636 | // Обработка запросов подписанными обработчиками 637 | if FHandlers.TryGetValue(JSON.GetValue('@type', ''), AHandler) then 638 | begin 639 | AHandler.Execute(JSON); 640 | Exit; 641 | end; 642 | finally 643 | JSON.Free; 644 | end; 645 | end; 646 | 647 | procedure TTelegramClientCustom.Send(const JSON: TJSONObject; AutoFree: Boolean); 648 | var 649 | JSONString: string; 650 | begin 651 | try 652 | JSONString := JSON.ToJSON; 653 | finally 654 | if AutoFree then 655 | JSON.Free; 656 | end; 657 | DoReceiveRaw(JSONString); 658 | JsonClientSend(FClient, StringToTgChar(JSONString)); 659 | end; 660 | 661 | procedure TTelegramClientCustom.Send(const AType, AName: string; const JSON: TJSONValue); 662 | var 663 | JSONObject: TJSONObject; 664 | begin 665 | if Assigned(JSON) and AName.IsEmpty and (JSON is TJSONObject) then 666 | JSONObject := JSON as TJSONObject 667 | else 668 | begin 669 | JSONObject := TJSONObject.Create; 670 | if Assigned(JSON) then 671 | JSONObject.AddPair(AName, JSON); 672 | end; 673 | JSONObject.AddPair('@type', AType); 674 | Send(JSONObject); 675 | end; 676 | 677 | procedure TTelegramClientCustom.Send(const AType: string; APairs: TArray>); 678 | var 679 | JSONObject: TJSONObject; 680 | begin 681 | JSONObject := TJSONObject.Create; 682 | JSONObject.AddPair('@type', AType); 683 | for var Pair in APairs do 684 | JSONObject.AddPair(Pair.Key, Pair.Value); 685 | Send(JSONObject); 686 | end; 687 | 688 | procedure TTelegramClientCustom.SetApiHash(const Value: string); 689 | begin 690 | FApiHash := Value; 691 | end; 692 | 693 | procedure TTelegramClientCustom.SetApiId(const Value: Int32); 694 | begin 695 | FApiId := Value; 696 | end; 697 | 698 | procedure TTelegramClientCustom.SetAuthCode(const Value: string); 699 | begin 700 | Send('checkAuthenticationCode', 'code', TJSONString.Create(Value)); 701 | end; 702 | 703 | procedure TTelegramClientCustom.SetAuthPassword(const Value: string); 704 | begin 705 | Send('checkAuthenticationPassword', 'password', TJSONString.Create(Value)); 706 | end; 707 | 708 | procedure TTelegramClientCustom.SetBotToken(const Value: string); 709 | begin 710 | FBotToken := Value; 711 | end; 712 | 713 | procedure TTelegramClientCustom.SetOnAuthReady(const Value: TNotifyEvent); 714 | begin 715 | FOnAuthReady := Value; 716 | end; 717 | 718 | procedure TTelegramClientCustom.SetOnClose(const Value: TNotifyEvent); 719 | begin 720 | FOnClose := Value; 721 | end; 722 | 723 | procedure TTelegramClientCustom.SetOnError(const Value: TOnError); 724 | begin 725 | FOnError := Value; 726 | end; 727 | 728 | procedure TTelegramClientCustom.SetOnNeedAuthCode(const Value: TNotifyEvent); 729 | begin 730 | FOnNeedAuthCode := Value; 731 | end; 732 | 733 | procedure TTelegramClientCustom.SetOnNeedAuthConfirm(const Value: TOnNeedAuthConfirm); 734 | begin 735 | FOnNeedAuthConfirm := Value; 736 | end; 737 | 738 | procedure TTelegramClientCustom.SetOnNeedAuthPassword(const Value: TNotifyEvent); 739 | begin 740 | FOnNeedAuthPassword := Value; 741 | end; 742 | 743 | procedure TTelegramClientCustom.SetOnReceive(const Value: TOnReceiveRaw); 744 | begin 745 | FOnReceive := Value; 746 | end; 747 | 748 | procedure TTelegramClientCustom.SetOnRegistration(const Value: TOnNeedRegistration); 749 | begin 750 | FOnRegistration := Value; 751 | end; 752 | 753 | procedure TTelegramClientCustom.SetPhoneNumber(const Value: string); 754 | begin 755 | FPhoneNumber := Value; 756 | end; 757 | 758 | procedure TTelegramClientCustom.SetRegisterUser(const FirstName, LastName: string); 759 | begin 760 | Send('registerUser', [ 761 | TPair.Create('first_name', TJSONString.Create(FirstName)), 762 | TPair.Create('last_name', TJSONString.Create(LastName)) 763 | ]); 764 | end; 765 | 766 | procedure TTelegramClientCustom.SetSyncEvents(const Value: Boolean); 767 | begin 768 | FSyncEvents := Value; 769 | end; 770 | 771 | procedure TTelegramClientCustom.SetSyncMethodsCallback(const Value: Boolean); 772 | begin 773 | FMethods.SyncCallback := Value; 774 | end; 775 | 776 | procedure TTelegramClientCustom.SetTimeout(const Value: Double); 777 | begin 778 | FTimeout := Value; 779 | end; 780 | 781 | procedure TTelegramClientCustom.SetUseTestDC(const Value: Boolean); 782 | begin 783 | FUseTestDC := Value; 784 | end; 785 | 786 | { TTDLibParameters } 787 | 788 | procedure TTDLibParameters.SetApplicationVersion(const Value: string); 789 | begin 790 | FApplicationVersion := Value; 791 | end; 792 | 793 | procedure TTDLibParameters.SetDatabaseDirectory(const Value: string); 794 | begin 795 | FDatabaseDirectory := Value; 796 | end; 797 | 798 | procedure TTDLibParameters.SetDatabaseEncryptionKey(const Value: string); 799 | begin 800 | FDatabaseEncryptionKey := Value; 801 | end; 802 | 803 | procedure TTDLibParameters.SetDeviceModel(const Value: string); 804 | begin 805 | FDeviceModel := Value; 806 | end; 807 | 808 | procedure TTDLibParameters.SetEnableStorageOptimizer(const Value: Boolean); 809 | begin 810 | FEnableStorageOptimizer := Value; 811 | end; 812 | 813 | procedure TTDLibParameters.SetFilesDirectory(const Value: string); 814 | begin 815 | FFilesDirectory := Value; 816 | end; 817 | 818 | procedure TTDLibParameters.SetIgnoreFileNames(const Value: Boolean); 819 | begin 820 | FIgnoreFileNames := Value; 821 | end; 822 | 823 | procedure TTDLibParameters.SetSystemLanguageCode(const Value: string); 824 | begin 825 | FSystemLanguageCode := Value; 826 | end; 827 | 828 | procedure TTDLibParameters.SetSystemVersion(const Value: string); 829 | begin 830 | FSystemVersion := Value; 831 | end; 832 | 833 | procedure TTDLibParameters.SetUseChatInfoDatabase(const Value: Boolean); 834 | begin 835 | FUseChatInfoDatabase := Value; 836 | end; 837 | 838 | procedure TTDLibParameters.SetUseFileDatabase(const Value: Boolean); 839 | begin 840 | FUseFileDatabase := Value; 841 | end; 842 | 843 | procedure TTDLibParameters.SetUseMessageDatabase(const Value: Boolean); 844 | begin 845 | FUseMessageDatabase := Value; 846 | end; 847 | 848 | procedure TTDLibParameters.SetUseSecretChats(const Value: Boolean); 849 | begin 850 | FUseSecretChats := Value; 851 | end; 852 | 853 | { TDLibMethods } 854 | 855 | procedure TDLibMethods.Clear; 856 | begin 857 | FPoll.Clear; 858 | end; 859 | 860 | constructor TDLibMethods.Create(Client: TTelegramClientCustom); 861 | begin 862 | inherited Create; 863 | FSync := False; 864 | FClient := Client; 865 | FPoll := TThreadDict>.Create; 866 | FRequestQueue := 0; 867 | end; 868 | 869 | destructor TDLibMethods.Destroy; 870 | begin 871 | FPoll.Free; 872 | inherited; 873 | end; 874 | 875 | procedure TDLibMethods.Execute(Query: TParam; FieldName: string; Callback: TProc); 876 | begin 877 | try 878 | var RequestId := NewRequestId; 879 | Query.Extra(RequestId); 880 | if Assigned(Callback) then 881 | FPoll.Add(RequestId, 882 | procedure(JSON: TJSONObject) 883 | begin 884 | if not FSync then 885 | Callback(JSON) 886 | else 887 | begin 888 | var JO := TJSONObject(JSON.Clone); 889 | Sync( 890 | procedure 891 | begin 892 | try 893 | Callback(JO); 894 | finally 895 | JO.Free; 896 | end; 897 | end); 898 | end; 899 | end) 900 | else 901 | FPoll.Add(RequestId, nil); 902 | FClient.Send(Query.JSON, False); 903 | finally 904 | Query.Free; 905 | end; 906 | end; 907 | 908 | procedure TDLibMethods.Execute(Query: TParam; FieldName: string; Callback: TProc); 909 | begin 910 | try 911 | var RequestId := NewRequestId; 912 | Query.Extra(RequestId); 913 | if Assigned(Callback) then 914 | FPoll.Add(RequestId, 915 | procedure(JSON: TJSONObject) 916 | var 917 | JO: TJSONObject; 918 | Obj: T; 919 | begin 920 | if FieldName.IsEmpty then 921 | JO := JSON 922 | else 923 | JO := JSON.GetValue(FieldName, nil); 924 | if Assigned(JO) then 925 | begin 926 | Obj := TJson.JsonToObject(JO); 927 | if not FSync then 928 | try 929 | Callback(Obj); 930 | finally 931 | Obj.Free; 932 | end 933 | else 934 | Sync( 935 | procedure 936 | begin 937 | try 938 | Callback(Obj); 939 | finally 940 | Obj.Free; 941 | end; 942 | end); 943 | end; 944 | end) 945 | else 946 | FPoll.Add(RequestId, nil); 947 | FClient.Send(Query.JSON, False); 948 | finally 949 | Query.Free; 950 | end; 951 | end; 952 | 953 | procedure TDLibMethods.GetMe(Callback: TProc); 954 | begin 955 | Execute(TGetMe.Create, '', Callback); 956 | end; 957 | 958 | procedure TDLibMethods.GetUser(UserId: Int64; Callback: TProc); 959 | begin 960 | Execute(TGetUser.Create.UserId(UserId), '', Callback); 961 | end; 962 | 963 | procedure TDLibMethods.GetUserFullInfo(UserId: Int64; Callback: TProc); 964 | begin 965 | Execute(TGetUserFullInfo.Create.UserId(UserId), '', Callback); 966 | end; 967 | 968 | function TDLibMethods.NewRequestId: TRequestId; 969 | begin 970 | Inc(FRequestQueue); 971 | Result := FRequestQueue; 972 | end; 973 | 974 | function TDLibMethods.Proc(const RequestId: TRequestId; JSON: TJSONObject): Boolean; 975 | var 976 | Callback: TProc; 977 | Dict: TSafeDictionary>; 978 | begin 979 | Dict := FPoll.Lock; 980 | try 981 | if Dict.TryGetValue(RequestId, Callback) then 982 | begin 983 | Dict.Remove(RequestId); 984 | if Assigned(Callback) then 985 | Callback(JSON); 986 | Exit(True); 987 | end; 988 | finally 989 | FPoll.Unlock; 990 | end; 991 | Result := False; 992 | end; 993 | 994 | procedure TDLibMethods.SendMessage(Params: TSendMessage; Callback: TProc); 995 | begin 996 | Execute(Params, '', Callback); 997 | end; 998 | 999 | procedure TDLibMethods.SendMessageAlbum(Params: TSendMessageAlbum; Callback: TProc); 1000 | begin 1001 | Execute(Params, '', Callback); 1002 | end; 1003 | 1004 | procedure TDLibMethods.SetSync(const Value: Boolean); 1005 | begin 1006 | FSync := Value; 1007 | end; 1008 | 1009 | procedure TDLibMethods.Sync(Proc: TProc); 1010 | begin 1011 | TThread.Queue(nil, 1012 | procedure 1013 | begin 1014 | Proc; 1015 | end); 1016 | end; 1017 | 1018 | end. 1019 | 1020 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.AObject.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.AObject; 2 | 3 | interface 4 | //'{"@type":"error","code":400,"message":"There are no messages to send","@extra":1}' 5 | 6 | uses 7 | REST.Json.Types; 8 | 9 | type 10 | TtgObject = class 11 | private 12 | [JSONName('@type')] 13 | FAType: string; 14 | FCode: Integer; 15 | FMessage: string; 16 | function GetIsError: Boolean; 17 | public 18 | property AType: string read FAType write FAType; 19 | property Code: Integer read FCode write FCode; 20 | property Message: string read FMessage write FMessage; 21 | property IsError: Boolean read GetIsError; 22 | end; 23 | 24 | implementation 25 | 26 | { TtgObject } 27 | 28 | function TtgObject.GetIsError: Boolean; 29 | begin 30 | Result := AType = 'error'; 31 | end; 32 | 33 | end. 34 | 35 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.AnimatedChatPhoto.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.AnimatedChatPhoto; 2 | 3 | interface 4 | 5 | uses 6 | TGC.Entity.Files; 7 | 8 | type 9 | /// 10 | /// Animated variant of a chat photo in MPEG4 format. 11 | /// 12 | TtgAnimatedChatPhoto = class 13 | private 14 | FLength: Int32; 15 | FFile: TtgFile; 16 | FMain_frame_timestamp: Double; 17 | public 18 | /// 19 | /// Animation width and height. 20 | /// 21 | property Length: Int32 read FLength write FLength; 22 | /// 23 | /// Information about the animation file. 24 | /// 25 | property &File: TtgFile read FFile write FFile; 26 | /// 27 | /// Timestamp of the frame, used as a static chat photo. 28 | /// 29 | property MainFrameTimestamp_: Double read FMain_frame_timestamp write FMain_frame_timestamp; 30 | destructor Destroy; override; 31 | end; 32 | 33 | implementation 34 | 35 | { TtgAnimatedChatPhoto } 36 | 37 | destructor TtgAnimatedChatPhoto.Destroy; 38 | begin 39 | FFile.Free; 40 | inherited; 41 | end; 42 | 43 | end. 44 | 45 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.BotCommand.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.BotCommand; 2 | 3 | interface 4 | 5 | type 6 | /// 7 | /// Represents a command supported by a bot. 8 | /// 9 | TtgBotCommand = class 10 | private 11 | FCommand: string; 12 | FDescription: string; 13 | public 14 | /// 15 | /// Text of the bot command. 16 | /// 17 | property Command: string read FCommand write FCommand; 18 | /// 19 | /// Description of the bot command. 20 | /// 21 | property Description: string read FDescription write FDescription; 22 | end; 23 | 24 | implementation 25 | 26 | end. 27 | 28 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.ChatPhoto.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.ChatPhoto; 2 | 3 | interface 4 | 5 | uses 6 | TGC.Entity.AObject, REST.JsonReflect, REST.Json.Interceptors, 7 | TGC.Entity.MiniThumbnail, TGC.Entity.PhotoSize, TGC.Entity.AnimatedChatPhoto; 8 | 9 | type 10 | /// 11 | /// Describes a chat or user profile photo. 12 | /// 13 | TtgChatPhoto = class(TtgObject) 14 | private 15 | FId: Int64; 16 | [JsonReflect(ctString, rtString, TUnixDateTimeInterceptor)] 17 | FAdded_date: TDateTime; 18 | FMinithumbnail: TtgMiniThumbnail; 19 | FSizes: TArray; 20 | FAnimation: TtgAnimatedChatPhoto; 21 | public 22 | /// 23 | /// Unique photo identifier. 24 | /// 25 | property Id: Int64 read FId write FId; 26 | /// 27 | /// Point in time (Unix timestamp) when the photo has been added. 28 | /// 29 | property AddedDate: TDateTime read FAdded_date write FAdded_date; 30 | /// 31 | /// Photo minithumbnail; may be null. 32 | /// 33 | property MiniThumbnail: TtgMiniThumbnail read FMinithumbnail write FMinithumbnail; 34 | /// 35 | /// Available variants of the photo in JPEG format, in different size. 36 | /// 37 | property Sizes: TArray read FSizes write FSizes; 38 | /// 39 | /// Animated variant of the photo in MPEG4 format; may be null. 40 | /// 41 | property Animation: TtgAnimatedChatPhoto read FAnimation write FAnimation; 42 | destructor Destroy; override; 43 | end; 44 | 45 | implementation 46 | 47 | { TtgChatPhoto } 48 | 49 | destructor TtgChatPhoto.Destroy; 50 | begin 51 | FMinithumbnail.Free; 52 | FAnimation.Free; 53 | for var Item in FSizes do 54 | Item.Free; 55 | inherited; 56 | end; 57 | 58 | end. 59 | 60 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.Files.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.Files; 2 | 3 | interface 4 | 5 | type 6 | /// 7 | /// Represents a remote file. 8 | /// 9 | TTgRemoteFile = class 10 | private 11 | FId: string; 12 | FIs_uploading_active: Boolean; 13 | FIs_uploading_completed: Boolean; 14 | FUnique_id: string; 15 | FUploaded_size: Int64; 16 | public 17 | /// 18 | /// Remote file identifier; may be empty. Can be used by the current user across application restarts or 19 | /// even from other devices. Uniquely identifies a file, but a file can have a lot of different valid identifiers. 20 | /// If the ID starts with "http://" or "https://", it represents the HTTP URL of the file. 21 | /// TDLib is currently unable to download files if only their URL is known. If downloadFile is called on such a 22 | /// file or if it is sent to a secret chat, TDLib starts a file generation process by sending updateFileGenerationStart 23 | /// to the application with the HTTP URL in the original_path and "#url#" as the conversion string. Application must 24 | /// generate the file by downloading it to the specified location. 25 | /// 26 | property Id: string read FId write FId; 27 | /// 28 | /// True, if the file is currently being uploaded (or a remote copy is being generated by some other means). 29 | /// 30 | property IsUploadingActive: Boolean read FIs_uploading_active write FIs_uploading_active; 31 | /// 32 | /// True, if a remote copy is fully available. 33 | /// 34 | property IsUploadingCompleted: Boolean read FIs_uploading_completed write FIs_uploading_completed; 35 | /// 36 | /// Unique file identifier; may be empty if unknown. The unique file identifier which is the same for the same file even for different users and is persistent over time. 37 | /// 38 | property UniqueId: string read FUnique_id write FUnique_id; 39 | /// 40 | /// Size of the remote available part of the file, in bytes; 0 if unknown. 41 | /// 42 | property UploadedSize: Int64 read FUploaded_size write FUploaded_size; 43 | end; 44 | 45 | /// 46 | /// Represents a local file. 47 | /// 48 | TTgLocalFile = class 49 | private 50 | FCan_be_deleted: Boolean; 51 | FCan_be_downloaded: Boolean; 52 | FDownload_offset: Int64; 53 | FDownloaded_prefix_size: Int64; 54 | FDownloaded_size: Int64; 55 | FIs_downloading_active: Boolean; 56 | FIs_downloading_completed: Boolean; 57 | FPath: string; 58 | public 59 | /// 60 | /// True, if the file can be deleted. 61 | /// 62 | property CanBeDeleted: Boolean read FCan_be_deleted write FCan_be_deleted; 63 | /// 64 | /// True, if it is possible to download or generate the file. 65 | /// 66 | property CanBeDownloaded: Boolean read FCan_be_downloaded write FCan_be_downloaded; 67 | /// 68 | /// Download will be started from this offset. downloaded_prefix_size is calculated from this offset. 69 | /// 70 | property DownloadOffset: Int64 read FDownload_offset write FDownload_offset; 71 | /// 72 | /// If is_downloading_completed is false, then only some prefix of the file starting from download_offset is ready to be read. downloaded_prefix_size is the size of that prefix in bytes. 73 | /// 74 | property DownloadedPrefixSize: Int64 read FDownloaded_prefix_size write FDownloaded_prefix_size; 75 | /// 76 | /// Total downloaded file size, in bytes. Can be used only for calculating download progress. The actual file size may be bigger, and some parts of it may contain garbage. 77 | /// 78 | property DownloadedSize: Int64 read FDownloaded_size write FDownloaded_size; 79 | /// 80 | /// True, if the file is currently being downloaded (or a local copy is being generated by some other means). 81 | /// 82 | property IsDownloadingActive: Boolean read FIs_downloading_active write FIs_downloading_active; 83 | /// 84 | /// True, if the local copy is fully available. 85 | /// 86 | property IsDownloadingCompleted: Boolean read FIs_downloading_completed write FIs_downloading_completed; 87 | /// 88 | /// Local path to the locally available file part; may be empty. 89 | /// 90 | property Path: string read FPath write FPath; 91 | end; 92 | 93 | /// 94 | /// Represents a file. 95 | /// 96 | TtgFile = class 97 | private 98 | FExpected_size: Int64; 99 | FId: Int64; 100 | FLocal: TTgLocalFile; 101 | FRemote: TTgRemoteFile; 102 | FSize: Int64; 103 | public 104 | /// 105 | /// Approximate file size in bytes in case the exact file size is unknown. Can be used to show download/upload progress. 106 | /// 107 | property ExpectedSize: Int64 read FExpected_size write FExpected_size; 108 | /// 109 | /// Unique file identifier. 110 | /// 111 | property Id: Int64 read FId write FId; 112 | /// 113 | /// Information about the local copy of the file. 114 | /// 115 | property Local: TTgLocalFile read FLocal write FLocal; 116 | /// 117 | /// Information about the remote copy of the file. 118 | /// 119 | property Remote: TTgRemoteFile read FRemote write FRemote; 120 | /// 121 | /// File size, in bytes; 0 if unknown. 122 | /// 123 | property Size: Int64 read FSize write FSize; 124 | destructor Destroy; override; 125 | end; 126 | 127 | implementation 128 | 129 | { TtgFile } 130 | 131 | destructor TtgFile.Destroy; 132 | begin 133 | if Assigned(FRemote) then 134 | FRemote.Free; 135 | if Assigned(FLocal) then 136 | FLocal.Free; 137 | inherited; 138 | end; 139 | 140 | end. 141 | 142 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.FormatedText.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.FormatedText; 2 | 3 | interface 4 | 5 | uses 6 | Rest.Json.Types; 7 | 8 | type 9 | TtgTextEntityType = class 10 | private 11 | [JSONName('@type')] 12 | FType: string; 13 | FLanguage: string; 14 | FMedia_timestamp: Integer; 15 | FUser_id: Int64; 16 | FUrl: string; 17 | public 18 | property AType: string read FType write FType; 19 | /// 20 | /// Programming language of the code; as defined by the sender. 21 | /// 22 | property Language: string read FLanguage write FLanguage; 23 | /// 24 | /// Timestamp from which a video/audio/video note/voice note playing must start, in seconds. The media can be in the content or the web page preview of the current message, or in the same places in the replied message. 25 | /// 26 | property MediaTimestamp: Integer read FMedia_timestamp write FMedia_timestamp; 27 | /// 28 | /// Identifier of the mentioned user. 29 | /// 30 | property UserId: Int64 read FUser_id write FUser_id; 31 | /// 32 | /// HTTP or tg:// URL to be opened when the link is clicked. 33 | /// 34 | property Url: string read FUrl write FUrl; 35 | end; 36 | 37 | TtgTextEntity = class 38 | private 39 | [JSONName('@type')] 40 | FType: string; 41 | FLength: Integer; 42 | FOffset: Integer; 43 | [JSONName('type')] 44 | FEntityType: TtgTextEntityType; 45 | public 46 | property AType: string read Ftype write Ftype; 47 | property Length: Integer read FLength write FLength; 48 | property Offset: Integer read FOffset write FOffset; 49 | property EntityType: TtgTextEntityType read FEntityType write FEntityType; 50 | destructor Destroy; override; 51 | end; 52 | 53 | TtgFormatedText = class 54 | private 55 | FEntities: TArray; 56 | FText: string; 57 | public 58 | property Entities: TArray read FEntities write FEntities; 59 | property Text: string read FText write FText; 60 | destructor Destroy; override; 61 | end; 62 | 63 | implementation 64 | 65 | { TtgFormatedText } 66 | 67 | destructor TtgFormatedText.Destroy; 68 | begin 69 | for var Item in FEntities do 70 | Item.Free; 71 | inherited; 72 | end; 73 | 74 | { TtgTextEntity } 75 | 76 | destructor TtgTextEntity.Destroy; 77 | begin 78 | FEntityType.Free; 79 | inherited; 80 | end; 81 | 82 | end. 83 | 84 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.Message.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.Message; 2 | 3 | interface 4 | 5 | uses 6 | TGC.Entity.Files, REST.JsonReflect, REST.Json.Interceptors, TGC.Entity.Sticker, 7 | REST.Json.Types, TGC.Entity.FormatedText, TGC.Entity.AObject; 8 | 9 | type 10 | /// 11 | /// Contains the content of a message 12 | /// 13 | TtgMessageContent = class 14 | private 15 | [JSONName('@type')] 16 | Ftype: string; 17 | FAnimated_emoji: TtgAnimatedEmoji; 18 | FEmoji: string; 19 | FText: TtgFormatedText; 20 | public 21 | property AType: string read Ftype write Ftype; 22 | /// 23 | /// The animated emoji. 24 | /// 25 | property AnimatedEmoji: TtgAnimatedEmoji read FAnimated_emoji write FAnimated_emoji; 26 | /// 27 | /// The corresponding emoji. 28 | /// 29 | property Emoji: string read FEmoji write FEmoji; 30 | /// 31 | /// A text message. 32 | /// 33 | property Text: TtgFormatedText read FText write FText; 34 | destructor Destroy; override; 35 | end; 36 | 37 | /// 38 | /// Contains information about the sender of a message 39 | /// 40 | TtgMessageSender = class 41 | private 42 | [JSONName('@type')] 43 | Ftype: string; 44 | FUser_id: Int64; 45 | FChat_id: Int64; 46 | public 47 | /// 48 | /// messageSenderChat, and messageSenderUser 49 | /// 50 | property AType: string read Ftype write Ftype; 51 | /// 52 | /// Identifier of the user that sent the message. 53 | /// 54 | property UserId: Int64 read FUser_id write FUser_id; 55 | /// 56 | /// Identifier of the chat that sent the message. 57 | /// 58 | property ChatId: Int64 read FChat_id write FChat_id; 59 | end; 60 | 61 | /// 62 | /// Describes a message. 63 | /// 64 | TtgMessage = class(TtgObject) 65 | private 66 | FAuthor_signature: string; 67 | FAuto_delete_in: Extended; 68 | FCan_be_deleted_for_all_users: Boolean; 69 | FCan_be_deleted_only_for_self: Boolean; 70 | FCan_be_edited: Boolean; 71 | FCan_be_forwarded: Boolean; 72 | FCan_be_saved: Boolean; 73 | FCan_get_added_reactions: Boolean; 74 | FCan_get_media_timestamp_links: Boolean; 75 | FCan_get_message_thread: Boolean; 76 | FCan_get_statistics: Boolean; 77 | FCan_get_viewers: Boolean; 78 | FCan_report_reactions: Boolean; 79 | FChat_id: Int64; 80 | FContains_unread_mention: Boolean; 81 | FContent: TtgMessageContent; 82 | [JsonReflect(ctString, rtString, TUnixDateTimeInterceptor)] 83 | FDate: TDateTime; 84 | [JsonReflect(ctString, rtString, TUnixDateTimeInterceptor)] 85 | FEdit_date: TDateTime; 86 | FHas_timestamped_media: Boolean; 87 | FId: Int64; 88 | FIs_channel_post: Boolean; 89 | FIs_outgoing: Boolean; 90 | FIs_pinned: Boolean; 91 | FIs_topic_message: Boolean; 92 | FMedia_album_id: string; 93 | FMessage_thread_id: Int64; 94 | FReply_in_chat_id: Int64; 95 | FReply_to_message_id: Int64; 96 | FRestriction_reason: string; 97 | FSelf_destruct_in: Extended; 98 | FSelf_destruct_time: Extended; 99 | FSender_id: TtgMessageSender; 100 | FUnread_reactions: TArray; 101 | FVia_bot_user_id: Int64; 102 | FTtl: Int64; 103 | FTtl_expires_in: Extended; 104 | public 105 | /// 106 | /// For channel posts and anonymous group messages, optional author signature. 107 | /// 108 | property AuthorSignature: string read FAuthor_signature write FAuthor_signature; 109 | property AutoDeleteIn: Extended read FAuto_delete_in write FAuto_delete_in; 110 | /// 111 | /// True, if the message can be deleted for all users. 112 | /// 113 | property CanBeDeletedForAllUsers: Boolean read FCan_be_deleted_for_all_users write FCan_be_deleted_for_all_users; 114 | /// 115 | /// True, if the message can be deleted only for the current user while other users will continue to see it. 116 | /// 117 | property CanBeDeletedOnlyForSelf: Boolean read FCan_be_deleted_only_for_self write FCan_be_deleted_only_for_self; 118 | /// 119 | /// True, if the message can be edited. For live location and poll messages this fields shows whether editMessageLiveLocation or stopPoll can be used with this message by the application. 120 | /// 121 | property CanBeEdited: Boolean read FCan_be_edited write FCan_be_edited; 122 | /// 123 | /// True, if the message can be forwarded. 124 | /// 125 | property CanBeForwarded: Boolean read FCan_be_forwarded write FCan_be_forwarded; 126 | /// 127 | /// True, if content of the message can be saved locally or copied. 128 | /// 129 | property CanBeSaved: Boolean read FCan_be_saved write FCan_be_saved; 130 | property CanFetAddedReactions: Boolean read FCan_get_added_reactions write FCan_get_added_reactions; 131 | /// 132 | /// True, if media timestamp links can be generated for media timestamp entities in the message text, caption or web page description. 133 | /// 134 | property CanGetMediaTimestampLinks: Boolean read FCan_get_media_timestamp_links write FCan_get_media_timestamp_links; 135 | /// 136 | /// True, if the message thread info is available. 137 | /// 138 | property CanGetMessageThread: Boolean read FCan_get_message_thread write FCan_get_message_thread; 139 | /// 140 | /// True, if the message statistics are available. 141 | /// 142 | property CanGetStatistics: Boolean read FCan_get_statistics write FCan_get_statistics; 143 | /// 144 | /// True, if chat members already viewed the message can be received through getMessageViewers. 145 | /// 146 | property CanGetViewers: Boolean read FCan_get_viewers write FCan_get_viewers; 147 | property CanReportReactions: Boolean read FCan_report_reactions write FCan_report_reactions; 148 | /// 149 | /// Chat identifier. 150 | /// 151 | property ChatId: Int64 read FChat_id write FChat_id; 152 | /// 153 | /// True, if the message contains an unread mention for the current user. 154 | /// 155 | property ContainsUnreadMention: Boolean read FContains_unread_mention write FContains_unread_mention; 156 | /// 157 | /// Content of the message. 158 | /// 159 | property Content: TtgMessageContent read FContent write FContent; 160 | /// 161 | /// Point in time (Unix timestamp) when the message was sent. 162 | /// 163 | property Date: TDateTime read FDate write FDate; 164 | /// 165 | /// Point in time (Unix timestamp) when the message was last edited. 166 | /// 167 | property EditDate: TDateTime read FEdit_date write FEdit_date; 168 | /// 169 | /// True, if media timestamp entities refers to a media in this message as opposed to a media in the replied message. 170 | /// 171 | property HasTimestampedMedia: Boolean read FHas_timestamped_media write FHas_timestamped_media; 172 | /// 173 | /// Message identifier; unique for the chat to which the message belongs. 174 | /// 175 | property Id: Int64 read FId write FId; 176 | /// 177 | /// True, if the message is a channel post. All messages to channels are channel posts, all other messages are not channel posts. 178 | /// 179 | property IsChannelPost: Boolean read FIs_channel_post write FIs_channel_post; 180 | /// 181 | /// True, if the message is outgoing. 182 | /// 183 | property IsOutgoing: Boolean read FIs_outgoing write FIs_outgoing; 184 | /// 185 | /// True, if the message is pinned. 186 | /// 187 | property IsPinned: Boolean read FIs_pinned write FIs_pinned; 188 | property IsTopicMessage: Boolean read FIs_topic_message write FIs_topic_message; 189 | /// 190 | /// Unique identifier of an album this message belongs to. Only audios, documents, photos and videos can be grouped together in albums. 191 | /// 192 | property MediaAlbumId: string read FMedia_album_id write FMedia_album_id; 193 | /// 194 | /// If non-zero, the identifier of the message thread the message belongs to; unique within the chat to which the message belongs. 195 | /// 196 | property MessageThreadId: Int64 read FMessage_thread_id write FMessage_thread_id; 197 | /// 198 | /// If non-zero, the identifier of the chat to which the replied message belongs; Currently, only messages in the Replies chat can have different reply_in_chat_id and chat_id. 199 | /// 200 | property ReplyInChatId: Int64 read FReply_in_chat_id write FReply_in_chat_id; 201 | /// 202 | /// If non-zero, the identifier of the message this message is replying to; can be the identifier of a deleted message. 203 | /// 204 | property ReplyToMessageId: Int64 read FReply_to_message_id write FReply_to_message_id; 205 | /// 206 | /// If non-empty, contains a human-readable description of the reason why access to this message must be restricted. 207 | /// 208 | property RestrictionReason: string read FRestriction_reason write FRestriction_reason; 209 | property SelfDestructIn: Extended read FSelf_destruct_in write FSelf_destruct_in; 210 | property SelfDestructRime: Extended read FSelf_destruct_time write FSelf_destruct_time; 211 | /// 212 | /// Identifier of the sender of the message. 213 | /// 214 | property SenderId: TtgMessageSender read FSender_id write FSender_id; 215 | property UnreadReactions: TArray read FUnread_reactions write FUnread_reactions; 216 | /// 217 | /// If non-zero, the user identifier of the bot through which this message was sent. 218 | /// 219 | property ViaBotUserId: Int64 read FVia_bot_user_id write FVia_bot_user_id; 220 | /// 221 | /// For self-destructing messages, the message's TTL (Time To Live), in seconds; 0 if none. TDLib will send updateDeleteMessages or updateMessageContent once the TTL expires. 222 | /// 223 | property TTL: Int64 read FTtl write FTtl; 224 | /// 225 | /// Time left before the message expires, in seconds. If the TTL timer isn't started yet, equals to the value of the ttl field. 226 | /// 227 | property TTLExpiresIn: Extended read FTtl_expires_in write FTtl_expires_in; 228 | destructor Destroy; override; 229 | end; 230 | 231 | implementation 232 | 233 | { TtgMessageContent } 234 | 235 | destructor TtgMessageContent.Destroy; 236 | begin 237 | FAnimated_emoji.Free; 238 | FText.Free; 239 | inherited; 240 | end; 241 | 242 | { TtgMessage } 243 | 244 | destructor TtgMessage.Destroy; 245 | begin 246 | FSender_id.free; 247 | FContent.free; 248 | inherited; 249 | end; 250 | 251 | end. 252 | 253 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.MiniThumbnail.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.MiniThumbnail; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils; 7 | 8 | type 9 | /// 10 | /// Thumbnail image of a very poor quality and low resolution. 11 | /// 12 | TtgMinithumbnail = class 13 | private 14 | FData: string; 15 | FHeight: Int64; 16 | FWidth: Int64; 17 | public 18 | /// 19 | /// The thumbnail in JPEG format. (base64) 20 | /// 21 | property Data: string read FData write FData; 22 | /// 23 | /// Thumbnail height, usually doesn't exceed 40. 24 | /// 25 | property Height: Int64 read FHeight write FHeight; 26 | /// 27 | /// Thumbnail width, usually doesn't exceed 40. 28 | /// 29 | property Width: Int64 read FWidth write FWidth; 30 | end; 31 | 32 | implementation 33 | 34 | end. 35 | 36 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.PhotoSize.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.PhotoSize; 2 | 3 | interface 4 | 5 | uses 6 | TGC.Entity.Files; 7 | 8 | type 9 | /// 10 | /// Describes an image in JPEG format. 11 | /// 12 | TtgPhotoSize = class 13 | private 14 | FType: string; 15 | FPhoto: TtgFile; 16 | FWidth: Int32; 17 | FHeight: Int32; 18 | FProgressive_sizes: TArray; 19 | public 20 | /// 21 | /// Image type (see https://core.telegram.org/constructor/photoSize). 22 | /// 23 | property &Type: string read FType write FType; 24 | /// 25 | /// Information about the image file. 26 | /// 27 | property Photo: TtgFile read FPhoto write FPhoto; 28 | /// 29 | /// Image width. 30 | /// 31 | property Width: Int32 read FWidth write FWidth; 32 | /// 33 | /// Image height. 34 | /// 35 | property Height: Int32 read FHeight write FHeight; 36 | /// 37 | /// Sizes of progressive JPEG file prefixes, which can be used to preliminarily show the image; in bytes. 38 | /// 39 | property ProgressiveSizes: TArray read FProgressive_sizes write FProgressive_sizes; 40 | destructor Destroy; override; 41 | end; 42 | 43 | implementation 44 | 45 | { TtgPhotoSize } 46 | 47 | destructor TtgPhotoSize.Destroy; 48 | begin 49 | FPhoto.Free; 50 | inherited; 51 | end; 52 | 53 | end. 54 | 55 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.ProfilePhoto.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.ProfilePhoto; 2 | 3 | interface 4 | 5 | uses 6 | TGC.Entity.Files, TGC.Entity.AObject, TGC.Entity.MiniThumbnail; 7 | 8 | type 9 | /// 10 | /// Describes a user profile photo. 11 | /// 12 | TTgProfilePhoto = class(TtgObject) 13 | private 14 | FBig: TtgFile; 15 | FHas_animation: Boolean; 16 | FId: string; 17 | FIs_personal: Boolean; 18 | FMinithumbnail: TTgMinithumbnail; 19 | FSmall: TtgFile; 20 | public 21 | /// 22 | /// A big (640x640) user profile photo. The file can be downloaded only before the photo is changed. 23 | /// 24 | property Big: TtgFile read FBig write FBig; 25 | /// 26 | /// True, if the photo has animated variant. 27 | /// 28 | property HasAnimation: Boolean read FHas_animation write FHas_animation; 29 | /// 30 | /// Photo identifier; 0 for an empty photo. Can be used to find a photo in a list of user profile photos. 31 | /// 32 | property Id: string read FId write FId; 33 | property IsPersonal: Boolean read FIs_personal write FIs_personal; 34 | /// 35 | /// User profile photo minithumbnail; may be null. 36 | /// 37 | property Minithumbnail: TTgMinithumbnail read FMinithumbnail write FMinithumbnail; 38 | /// 39 | /// A small (160x160) user profile photo. The file can be downloaded only before the photo is changed. 40 | /// 41 | property Small: TtgFile read FSmall write FSmall; 42 | destructor Destroy; override; 43 | end; 44 | 45 | implementation 46 | 47 | { TTgProfilePhoto } 48 | 49 | destructor TTgProfilePhoto.Destroy; 50 | begin 51 | if Assigned(FMinithumbnail) then 52 | FMinithumbnail.Free; 53 | if Assigned(FSmall) then 54 | FSmall.Free; 55 | if Assigned(FBig) then 56 | FBig.Free; 57 | inherited; 58 | end; 59 | 60 | end. 61 | 62 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.Sticker.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.Sticker; 2 | 3 | interface 4 | 5 | uses 6 | TGC.Entity.Files, REST.Json.Types, TGC.Entity.AObject; 7 | 8 | type 9 | /// 10 | /// Describes format of the thumbnail 11 | /// 12 | TtgThumbnailFormat = class 13 | private 14 | [JSONName('@type')] 15 | Ftype: string; 16 | public 17 | /// 18 | /// thumbnailFormatGif, thumbnailFormatJpeg, thumbnailFormatMpeg4, thumbnailFormatPng, thumbnailFormatTgs, and thumbnailFormatWebp 19 | /// 20 | property AType: string read Ftype write Ftype; 21 | end; 22 | 23 | /// 24 | /// Represents a thumbnail. 25 | /// 26 | TtgThumbnail = class 27 | private 28 | FFile: TtgFile; 29 | FFormat: TtgThumbnailFormat; 30 | FHeight: Int32; 31 | FWidth: Int32; 32 | public 33 | /// 34 | /// The thumbnail. 35 | /// 36 | property &File: TtgFile read FFile write FFile; 37 | /// 38 | /// Thumbnail format. 39 | /// 40 | property Format: TtgThumbnailFormat read FFormat write FFormat; 41 | /// 42 | /// Thumbnail height. 43 | /// 44 | property Height: Int32 read FHeight write FHeight; 45 | /// 46 | /// Thumbnail width. 47 | /// 48 | property Width: Int32 read FWidth write FWidth; 49 | destructor Destroy; override; 50 | end; 51 | 52 | /// 53 | /// A point on a Cartesian plane. 54 | /// 55 | TtgPoint = class 56 | private 57 | FX: Extended; 58 | FY: Extended; 59 | public 60 | /// 61 | /// The point's first coordinate. 62 | /// 63 | property X: Extended read FX write FX; 64 | /// 65 | /// The point's second coordinate. 66 | /// 67 | property Y: Extended read FY write FY; 68 | end; 69 | 70 | /// 71 | /// Represents a vector path command. 72 | /// 73 | TtgVectorPathCommand = class 74 | private 75 | [JSONName('@type')] 76 | Ftype: string; 77 | FEnd_control_point: TtgPoint; 78 | FEnd_point: TtgPoint; 79 | FStart_control_point: TtgPoint; 80 | public 81 | /// 82 | /// vectorPathCommandCubicBezierCurve, and vectorPathCommandLine. 83 | /// 84 | property AType: string read Ftype write Ftype; 85 | /// 86 | /// The end control point of the curve. 87 | /// 88 | property EndControlPoint: TtgPoint read FEnd_control_point write FEnd_control_point; 89 | /// 90 | /// The end point of the curve. 91 | /// 92 | property EndPoint: TtgPoint read FEnd_point write FEnd_point; 93 | /// 94 | /// The start control point of the curve. 95 | /// 96 | property StartControlPoint: TtgPoint read FStart_control_point write FStart_control_point; 97 | destructor Destroy; override; 98 | end; 99 | 100 | /// 101 | /// Represents a closed vector path. The path begins at the end point of the last command. 102 | /// 103 | TtgClosedVectorPath = class 104 | private 105 | FCommands: TArray; 106 | public 107 | /// 108 | /// List of vector path commands. 109 | /// 110 | property Commands: TArray read FCommands write FCommands; 111 | destructor Destroy; override; 112 | end; 113 | 114 | TtgStickerFullType = class 115 | private 116 | [JSONName('@type')] 117 | Ftype: string; 118 | public 119 | property AType: string read Ftype write Ftype; 120 | end; 121 | 122 | TtgStickerFormat = class 123 | private 124 | [JSONName('@type')] 125 | Ftype: string; 126 | public 127 | property AType: string read Ftype write Ftype; 128 | end; 129 | 130 | TTgMaskPosition = class 131 | end; 132 | 133 | TtgSticker = class(TtgObject) 134 | private 135 | FEmoji: string; 136 | FFormat: TtgStickerFormat; 137 | FFull_type: TtgStickerFullType; 138 | FHeight: Int32; 139 | FId: string; 140 | FOutline: TArray; 141 | FSet_id: string; 142 | FSticker: TtgFile; 143 | FThumbnail: TtgThumbnail; 144 | FWidth: Int32; 145 | FIs_animated: Boolean; 146 | FIs_mask: Boolean; 147 | FMask_position: TTgMaskPosition; 148 | public 149 | /// 150 | /// Emoji corresponding to the sticker. 151 | /// 152 | property Emoji: string read FEmoji write FEmoji; 153 | property Format: TtgStickerFormat read FFormat write FFormat; 154 | property FullType: TtgStickerFullType read FFull_type write FFull_type; 155 | /// 156 | /// True, if the sticker is an animated sticker in TGS format. 157 | /// 158 | property IsAnimated: Boolean read FIs_animated write FIs_animated; 159 | /// 160 | /// True, if the sticker is a mask. 161 | /// 162 | property IsMask: Boolean read FIs_mask write FIs_mask; 163 | /// 164 | /// Sticker height; as defined by the sender. 165 | /// 166 | property Height: Int32 read FHeight write FHeight; 167 | property Id: string read FId write FId; 168 | /// 169 | /// Sticker's outline represented as a list of closed vector paths; may be empty. The coordinate system origin is in the upper-left corner. 170 | /// 171 | property Outline: TArray read FOutline write FOutline; 172 | property MaskPosition: TTgMaskPosition read FMask_position write FMask_position; 173 | /// 174 | /// The identifier of the sticker set to which the sticker belongs; 0 if none. 175 | /// 176 | property SetId: string read FSet_id write FSet_id; 177 | /// 178 | /// File containing the sticker. 179 | /// 180 | property Sticker: TtgFile read FSticker write FSticker; 181 | /// 182 | /// Sticker thumbnail in WEBP or JPEG format; may be null. 183 | /// 184 | property Thumbnail: TtgThumbnail read FThumbnail write FThumbnail; 185 | /// 186 | /// Sticker width; as defined by the sender. 187 | /// 188 | property Width: Int32 read FWidth write FWidth; 189 | destructor Destroy; override; 190 | end; 191 | 192 | /// 193 | /// Describes an animated representation of an emoji. 194 | /// 195 | TtgAnimatedEmoji = class 196 | private 197 | FFitzpatrick_type: Int32; 198 | FSticker: TtgSticker; 199 | FSticker_height: Int32; 200 | FSticker_width: Int32; 201 | FSound: TtgFile; 202 | public 203 | /// 204 | /// Emoji modifier fitzpatrick type; 0-6; 0 if none. 205 | /// 206 | property FitzpatrickType: Int32 read FFitzpatrick_type write FFitzpatrick_type; 207 | /// 208 | /// Animated sticker for the emoji. 209 | /// 210 | property Sticker: TtgSticker read FSticker write FSticker; 211 | property StickerHeight: Int32 read FSticker_height write FSticker_height; 212 | property StickerWidth: Int32 read FSticker_width write FSticker_width; 213 | /// 214 | /// File containing the sound to be played when the animated emoji is clicked if any; may be null. The sound is encoded with the Opus codec, and stored inside an OGG container. 215 | /// 216 | property Sound: TtgFile read FSound write FSound; 217 | destructor Destroy; override; 218 | end; 219 | 220 | implementation 221 | 222 | { TtgThumbnail } 223 | 224 | destructor TtgThumbnail.Destroy; 225 | begin 226 | FFormat.free; 227 | FFile.free; 228 | inherited; 229 | end; 230 | 231 | { TtgVectorPathCommand } 232 | 233 | destructor TtgVectorPathCommand.Destroy; 234 | begin 235 | FStart_control_point.free; 236 | FEnd_control_point.free; 237 | FEnd_point.free; 238 | inherited; 239 | end; 240 | 241 | { TtgClosedVectorPath } 242 | 243 | destructor TtgClosedVectorPath.Destroy; 244 | var 245 | Item: TtgVectorPathCommand; 246 | begin 247 | for Item in FCommands do 248 | Item.Free; 249 | inherited; 250 | end; 251 | 252 | { TtgSticker } 253 | 254 | destructor TtgSticker.Destroy; 255 | var 256 | Item: TtgClosedVectorPath; 257 | begin 258 | for Item in FOutline do 259 | Item.Free; 260 | FFormat.Free; 261 | FFull_type.Free; 262 | FThumbnail.Free; 263 | FSticker.Free; 264 | FMask_position.Free; 265 | inherited; 266 | end; 267 | 268 | { TtgAnimatedEmoji } 269 | 270 | destructor TtgAnimatedEmoji.Destroy; 271 | begin 272 | FSticker.Free; 273 | inherited; 274 | end; 275 | 276 | end. 277 | 278 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.User.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.User; 2 | 3 | interface 4 | 5 | uses 6 | Rest.Json.Types, Rest.JsonReflect, Rest.Json.Interceptors, TGC.Entity.Files, TGC.Entity.ProfilePhoto, 7 | TGC.Entity.AObject; 8 | 9 | type 10 | /// 11 | /// Represents the type of a user. The following types are possible: regular users, deleted users and bots. 12 | /// 13 | TtgUserType = class 14 | private 15 | [JSONNameAttribute('@type')] 16 | FType: string; 17 | public 18 | /// 19 | /// userTypeBot, userTypeDeleted, userTypeRegular, and userTypeUnknown 20 | /// 21 | property AType: string read FType write FType; 22 | end; 23 | 24 | /// 25 | /// Describes the last time the user was online. 26 | /// 27 | TtgUserStatus = class 28 | private 29 | [JSONNameAttribute('@type')] 30 | Ftype: string; 31 | [JsonReflect(ctString, rtString, TUnixDateTimeInterceptor)] 32 | FWas_online: TDateTime; 33 | public 34 | /// 35 | /// userStatusEmpty, userStatusLastMonth, userStatusLastWeek, userStatusOffline, userStatusOnline, and userStatusRecently 36 | /// 37 | property AType: string read Ftype write Ftype; 38 | property WasOnline: TDateTime read FWas_online write FWas_online; 39 | end; 40 | 41 | /// 42 | /// User names 43 | /// 44 | TtgUserNames = class 45 | private 46 | FActive_usernames: TArray; 47 | FDisabled_usernames: TArray; 48 | FEditable_username: string; 49 | public 50 | property ActiveUsernames: TArray read FActive_usernames write FActive_usernames; 51 | property DisabledUsernames: TArray read FDisabled_usernames write FDisabled_usernames; 52 | property EditableUsername: string read FEditable_username write FEditable_username; 53 | end; 54 | 55 | /// 56 | /// Represents a user. 57 | /// 58 | TtgUser = class(TtgObject) 59 | private 60 | FAdded_to_attachment_menu: Boolean; 61 | FFirst_name: string; 62 | FHave_access: Boolean; 63 | FId: Int64; 64 | FIs_contact: Boolean; 65 | FIs_fake: Boolean; 66 | FIs_mutual_contact: Boolean; 67 | FIs_premium: Boolean; 68 | FIs_scam: Boolean; 69 | FIs_support: Boolean; 70 | FIs_verified: Boolean; 71 | FLanguage_code: string; 72 | FLast_name: string; 73 | FPhone_number: string; 74 | FRestriction_reason: string; 75 | FStatus: TtgUserStatus; 76 | FType: TtgUserType; 77 | FProfile_photo: TTgProfilePhoto; 78 | FUsernames: TtgUserNames; 79 | function GetType: string; 80 | public 81 | property AddedToAttachmentMenu: Boolean read FAdded_to_attachment_menu write FAdded_to_attachment_menu; 82 | /// 83 | /// First name of the user. 84 | /// 85 | property FirstName: string read FFirst_name write FFirst_name; 86 | /// 87 | /// If false, the user is inaccessible, and the only information known about the user is inside this class. It can't be passed to any method except GetUser. 88 | /// 89 | property HaveAccess: Boolean read FHave_access write FHave_access; 90 | /// 91 | /// User identifier. 92 | /// 93 | property Id: Int64 read FId write FId; 94 | /// 95 | /// The user is a contact of the current user. 96 | /// 97 | property IsContact: Boolean read FIs_contact write FIs_contact; 98 | /// 99 | /// True, if many users reported this user as a fake account. 100 | /// 101 | property IsFake: Boolean read FIs_fake write FIs_fake; 102 | /// 103 | /// The user is a contact of the current user and the current user is a contact of the user. 104 | /// 105 | property IsMutualContact: Boolean read FIs_mutual_contact write FIs_mutual_contact; 106 | /// 107 | /// /// The user have Premium 108 | /// 109 | property IsPremium: Boolean read FIs_premium write FIs_premium; 110 | /// 111 | /// True, if many users reported this user as a scam. 112 | /// 113 | property IsScam: Boolean read FIs_scam write FIs_scam; 114 | /// 115 | /// True, if the user is Telegram support account. 116 | /// 117 | property IsSupport: Boolean read FIs_support write FIs_support; 118 | /// 119 | /// True, if the user is verified. 120 | /// 121 | property IsVerified: Boolean read FIs_verified write FIs_verified; 122 | /// 123 | /// IETF language tag of the user's language; only available to bots. 124 | /// 125 | property LanguageCode: string read FLanguage_code write FLanguage_code; 126 | /// 127 | /// Last name of the user. 128 | /// 129 | property LastName: string read FLast_name write FLast_name; 130 | /// 131 | /// Phone number of the user. 132 | /// 133 | property PhoneNumber: string read FPhone_number write FPhone_number; 134 | /// 135 | /// Profile photo of the user; may be null. 136 | /// 137 | property ProfilePhoto: TTgProfilePhoto read FProfile_photo write FProfile_photo; 138 | /// 139 | /// If non-empty, it contains a human-readable description of the reason why access to this user must be restricted. 140 | /// 141 | property RestrictionReason: string read FRestriction_reason write FRestriction_reason; 142 | /// 143 | /// Current online status of the user. 144 | /// 145 | property Status: TtgUserStatus read FStatus write FStatus; 146 | /// 147 | /// Type of the user. userTypeBot, userTypeDeleted, userTypeRegular, and userTypeUnknown 148 | /// 149 | property UserType: string read GetType; 150 | /// 151 | /// Username of the user. 152 | /// 153 | property UserNames: TtgUserNames read FUsernames write FUsernames; 154 | destructor Destroy; override; 155 | end; 156 | 157 | implementation 158 | 159 | { TtgUser } 160 | 161 | destructor TtgUser.Destroy; 162 | begin 163 | if Assigned(FStatus) then 164 | FStatus.Free; 165 | if Assigned(FType) then 166 | FType.Free; 167 | if Assigned(FUsernames) then 168 | FUsernames.Free; 169 | if Assigned(FProfile_photo) then 170 | FProfile_photo.Free; 171 | inherited; 172 | end; 173 | 174 | function TtgUser.GetType: string; 175 | begin 176 | if Assigned(FType) then 177 | Result := FType.FType; 178 | end; 179 | 180 | end. 181 | 182 | -------------------------------------------------------------------------------- /Sources/TGC.Entity.UserFullInfo.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Entity.UserFullInfo; 2 | 3 | interface 4 | 5 | uses 6 | Rest.Json.Types, Rest.JsonReflect, Rest.Json.Interceptors, TGC.Entity.AObject, 7 | TGC.Entity.ChatPhoto, TGC.Entity.BotCommand; 8 | 9 | type 10 | /// 11 | /// Contains full information about a user. 12 | /// 13 | TtgUserFullInfo = class(TtgObject) 14 | private 15 | FPhoto: TtgChatPhoto; 16 | FIs_blocked: Boolean; 17 | FCan_be_called: Boolean; 18 | FSupports_video_calls: Boolean; 19 | FHas_private_calls: Boolean; 20 | FHas_private_forwards: Boolean; 21 | FNeed_phone_number_privacy_exception: Boolean; 22 | FBio: string; 23 | FShare_text: string; 24 | FDescription: string; 25 | FGroup_in_common_count: Int32; 26 | FCommands: TArray; 27 | public 28 | /// 29 | /// User profile photo; may be null. 30 | /// 31 | property Photo: TtgChatPhoto read FPhoto write FPhoto; 32 | /// 33 | /// True, if the user is blocked by the current user. 34 | /// 35 | property IsBlocked: Boolean read FIs_blocked write FIs_blocked; 36 | /// 37 | /// True, if the user can be called. 38 | /// 39 | property CanBeCalled: Boolean read FCan_be_called write FCan_be_called; 40 | /// 41 | /// True, if a video call can be created with the user. 42 | /// 43 | property SupportsVideoCalls: Boolean read FSupports_video_calls write FSupports_video_calls; 44 | /// 45 | /// True, if the user can't be called due to their privacy settings. 46 | /// 47 | property HasPrivateCalls: Boolean read FHas_private_calls write FHas_private_calls; 48 | /// 49 | /// True, if the user can't be linked in forwarded messages due to their privacy settings. 50 | /// 51 | property HasPrivateForwards: Boolean read FHas_private_forwards write FHas_private_forwards; 52 | /// 53 | /// True, if the current user needs to explicitly allow to share their phone number with the user when the method addContact is used. 54 | /// 55 | property NeedPhoneNumberPrivacyException: Boolean read FNeed_phone_number_privacy_exception write FNeed_phone_number_privacy_exception; 56 | /// 57 | /// A short user bio. 58 | /// 59 | property Bio: string read FBio write FBio; 60 | /// 61 | /// For bots, the text that is shown on the bot's profile page and is sent together with the link when users share the bot. 62 | /// 63 | property ShareText: string read FShare_text write FShare_text; 64 | /// 65 | /// For bots, the text shown in the chat with the bot if the chat is empty. 66 | /// 67 | property Description: string read FDescription write FDescription; 68 | /// 69 | /// Number of group chats where both the other user and the current user are a member; 0 for the current user. 70 | /// 71 | property GroupInCommonCount: Int32 read FGroup_in_common_count write FGroup_in_common_count; 72 | /// 73 | /// For bots, list of the bot commands. 74 | /// 75 | property Commands: TArray read FCommands write FCommands; 76 | destructor Destroy; override; 77 | end; 78 | 79 | implementation 80 | 81 | { TtgUserFullInfo } 82 | 83 | destructor TtgUserFullInfo.Destroy; 84 | begin 85 | FPhoto.Free; 86 | for var Item in FCommands do 87 | Item.Free; 88 | inherited; 89 | end; 90 | 91 | end. 92 | 93 | -------------------------------------------------------------------------------- /Sources/TGC.Errors.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Errors; 2 | 3 | interface 4 | 5 | const 6 | UPDATE_APP_TO_LOGIN = 406; 7 | 8 | implementation 9 | 10 | end. 11 | -------------------------------------------------------------------------------- /Sources/TGC.Handler.Error.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Handler.Error; 2 | 3 | interface 4 | 5 | uses 6 | System.Classes, System.SysUtils, System.JSON, TGC.Handler; 7 | 8 | type 9 | TError = class(THandler) 10 | public 11 | procedure Execute(JSON: TJSONObject); override; 12 | end; 13 | 14 | implementation 15 | 16 | uses 17 | TGC.Client; 18 | 19 | { TError } 20 | 21 | procedure TError.Execute(JSON: TJSONObject); 22 | begin 23 | inherited; 24 | TTelegramClientCustom(Client).Error(JSON.GetValue('code', -1), JSON.GetValue('message', '')); 25 | end; 26 | 27 | end. 28 | 29 | -------------------------------------------------------------------------------- /Sources/TGC.Handler.UpdateAuthorizationState.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Handler.UpdateAuthorizationState; 2 | 3 | interface 4 | 5 | uses 6 | System.Classes, System.SysUtils, System.JSON, TGC.Handler, HGM.JSONParams; 7 | 8 | type 9 | TSetTdlibParameters = class(TJSONParam) 10 | end; 11 | 12 | TTermsOfServiceText = class 13 | private 14 | FText: string; 15 | public 16 | property Text: string read FText write FText; 17 | end; 18 | 19 | TTermsOfService = class 20 | private 21 | FMin_user_age: Integer; 22 | FShow_popup: Boolean; 23 | FText: TTermsOfServiceText; 24 | public 25 | property MinUserAge: Integer read FMin_user_age write FMin_user_age; 26 | property ShowPopup: Boolean read FShow_popup write FShow_popup; 27 | property Text: TTermsOfServiceText read FText write FText; 28 | destructor Destroy; override; 29 | end; 30 | 31 | TUpdateAuthorizationState = class(THandler) 32 | private 33 | procedure SendSetParams; 34 | procedure DoNeedRegistration(JSON: TJSONObject); 35 | public 36 | procedure Execute(JSON: TJSONObject); override; 37 | end; 38 | 39 | implementation 40 | 41 | uses 42 | TGC.Client, REST.Json; 43 | 44 | { TUpdateAuthorizationState } 45 | 46 | procedure TUpdateAuthorizationState.Execute(JSON: TJSONObject); 47 | begin 48 | inherited; 49 | var JO: TJSONObject; 50 | if JSON.TryGetValue('authorization_state', JO) then 51 | begin 52 | var AType := JO.GetValue('@type', ''); 53 | if AType = 'authorizationStateWaitTdlibParameters' then 54 | SendSetParams 55 | else if AType = 'authorizationStateClosed' then 56 | TTelegramClientCustom(Client).Close 57 | else if AType = 'authorizationStateWaitEncryptionKey' then 58 | with TTelegramClientCustom(Client) do 59 | Send('checkDatabaseEncryptionKey', 'encryption_key', TJSONString.Create(Parameters.DatabaseEncryptionKey)) 60 | else if AType = 'authorizationStateWaitPhoneNumber' then 61 | with TTelegramClientCustom(Client) do 62 | Send('setAuthenticationPhoneNumber', 'phone_number', TJSONString.Create(PhoneNumber)) 63 | else if AType = 'authorizationStateWaitCode' then 64 | with TTelegramClientCustom(Client) do 65 | NeedAuthCode 66 | else if AType = 'authorizationStateWaitRegistration' then 67 | DoNeedRegistration(JO.GetValue('terms_of_service', nil)) 68 | else if AType = 'authorizationStateWaitPassword' then 69 | with TTelegramClientCustom(Client) do 70 | NeedAuthenticationPassword 71 | else if AType = 'authorizationStateWaitOtherDeviceConfirmation' then 72 | with TTelegramClientCustom(Client) do 73 | NeedOtherDeviceConfirmation(JO.GetValue('link', '')) 74 | else if AType = 'authorizationStateReady' then 75 | with TTelegramClientCustom(Client) do 76 | AuthReady; 77 | end; 78 | end; 79 | 80 | procedure TUpdateAuthorizationState.DoNeedRegistration(JSON: TJSONObject); 81 | var 82 | Terms: TTermsOfService; 83 | begin 84 | try 85 | Terms := TJson.JsonToObject(JSON); 86 | except 87 | Terms := nil; 88 | end; 89 | with TTelegramClientCustom(Client) do 90 | NeedRegistration(Terms); 91 | end; 92 | 93 | procedure TUpdateAuthorizationState.SendSetParams; 94 | var 95 | Params: TSetTdlibParameters; 96 | begin 97 | with TTelegramClientCustom(Client) do 98 | begin 99 | Params := TSetTdlibParameters.Create; 100 | try 101 | if UseTestDC then 102 | Params.Add('use_test_dc', True); 103 | Params.Add('database_directory', Parameters.DatabaseDirectory); 104 | Params.Add('files_directory', Parameters.FilesDirectory); 105 | Params.Add('use_file_database', Parameters.UseFileDatabase); 106 | Params.Add('use_chat_info_database', Parameters.UseChatInfoDatabase); 107 | Params.Add('use_message_database', Parameters.UseMessageDatabase); 108 | Params.Add('use_secret_chats', Parameters.UseSecretChats); 109 | Params.Add('api_id', ApiId); 110 | Params.Add('api_hash', ApiHash); 111 | if not BotToken.IsEmpty then 112 | Params.Add('token', BotToken); 113 | Params.Add('system_language_code', Parameters.SystemLanguageCode); 114 | Params.Add('device_model', Parameters.DeviceModel); 115 | Params.Add('system_version', Parameters.SystemVersion); 116 | Params.Add('application_version', Parameters.ApplicationVersion); 117 | Params.Add('enable_storage_optimizer', Parameters.EnableStorageOptimizer); 118 | Params.Add('ignore_file_names', Parameters.IgnoreFileNames); 119 | Send('setTdlibParameters', '', Params.Clone); 120 | finally 121 | Params.Free; 122 | end; 123 | end; 124 | end; 125 | 126 | { TTermsOfService } 127 | 128 | destructor TTermsOfService.Destroy; 129 | begin 130 | if Assigned(FText) then 131 | FText.Free; 132 | inherited; 133 | end; 134 | 135 | end. 136 | 137 | -------------------------------------------------------------------------------- /Sources/TGC.Handler.UpdateOption.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Handler.UpdateOption; 2 | 3 | interface 4 | 5 | uses 6 | System.Classes, System.SysUtils, System.JSON, TGC.Handler, TGC.Options; 7 | 8 | type 9 | TUpdateOption = class(THandler) 10 | private 11 | FOptions: TtgOptions; 12 | procedure UpdateOption(const FieldName, AType: string; Value: TJSONValue); 13 | public 14 | procedure Execute(JSON: TJSONObject); override; 15 | constructor Create(AClient: TObject); override; 16 | end; 17 | 18 | implementation 19 | 20 | uses 21 | TGC.Client, System.Rtti, System.Types; 22 | 23 | { TUpdateOption } 24 | 25 | constructor TUpdateOption.Create(AClient: TObject); 26 | begin 27 | inherited; 28 | FOptions := TTelegramClientCustom(Client).Options; 29 | end; 30 | 31 | procedure TUpdateOption.UpdateOption(const FieldName, AType: string; Value: TJSONValue); 32 | var 33 | T: TRttiType; 34 | F: TRttiField; 35 | SharedContext: TRttiContext; 36 | begin 37 | if FOptions <> nil then 38 | begin 39 | T := SharedContext.GetType(FOptions.ClassInfo); 40 | if T <> nil then 41 | begin 42 | F := T.GetField(FieldName); 43 | if (F <> nil) then 44 | begin 45 | var Val: TValue; 46 | if AType = 'optionValueString' then 47 | F.SetValue(FOptions, Value.AsType) 48 | else if AType = 'optionValueInteger' then 49 | F.SetValue(FOptions, Value.AsType) 50 | else if AType = 'optionValueBoolean' then 51 | F.SetValue(FOptions, Value.AsType) 52 | end; 53 | end; 54 | end; 55 | end; 56 | 57 | procedure TUpdateOption.Execute(JSON: TJSONObject); 58 | begin 59 | inherited; 60 | var FieldName := JSON.GetValue('name', ''); 61 | FieldName[1] := UpCase(FieldName[1]); 62 | FieldName := 'F' + FieldName; 63 | UpdateOption(FieldName, JSON.GetValue('value.@type', ''), JSON.GetValue('value.value')); 64 | end; 65 | 66 | end. 67 | 68 | -------------------------------------------------------------------------------- /Sources/TGC.Handler.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Handler; 2 | 3 | interface 4 | 5 | uses 6 | System.Classes, System.JSON; 7 | //{"@type":"updateOption","name":"version","value":{"@type":"optionValueString","value":"1.7.0"}} 8 | 9 | type 10 | THandler = class 11 | private 12 | FClient: TObject; 13 | public 14 | procedure Execute(JSON: TJSONObject); virtual; abstract; 15 | constructor Create(AClient: TObject); virtual; 16 | property Client: TObject read FClient; 17 | end; 18 | 19 | implementation 20 | 21 | { THandler } 22 | 23 | constructor THandler.Create(AClient: TObject); 24 | begin 25 | inherited Create; 26 | FClient := AClient; 27 | end; 28 | 29 | end. 30 | 31 | -------------------------------------------------------------------------------- /Sources/TGC.Options.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Options; 2 | 3 | interface 4 | 5 | type 6 | TtgOptions = class 7 | private 8 | FVersion: string; 9 | FCommit_hash: string; 10 | FUnix_time: Int64; 11 | FUtc_time_offset: Int64; 12 | FMessage_text_length_max: Int64; 13 | FMessage_caption_length_max: Int64; 14 | FBio_length_max: Int64; 15 | FSuggested_video_note_length: Int64; 16 | FSuggested_video_note_video_bitrate: Int64; 17 | FSuggested_video_note_audio_bitrate: Int64; 18 | FNotification_sound_duration_max: Int64; 19 | FNotification_sound_size_max: Int64; 20 | FNotification_sound_count_max: Int64; 21 | FChat_filter_count_max: Int64; 22 | FChat_filter_chosen_chat_count_max: Int64; 23 | FPinned_forum_topic_count_max: Int64; 24 | FTelegram_service_notifications_chat_id: Int64; 25 | FReplies_bot_chat_id: Int64; 26 | FGroup_anonymous_bot_user_id: Int64; 27 | FChannel_bot_user_id: Int64; 28 | FAnti_spam_bot_user_id: Int64; 29 | FIs_location_visible: Boolean; 30 | FFavorite_stickers_limit: Int64; 31 | FTest_mode: Boolean; 32 | FForwarded_message_count_max: Int64; 33 | FBasic_group_size_max: Int64; 34 | FSupergroup_size_max: Int64; 35 | FPinned_chat_count_max: Int64; 36 | FPinned_archived_chat_count_max: Int64; 37 | FExpect_blocking: Boolean; 38 | FT_me_url: string; 39 | FCalls_enabled: Boolean; 40 | FCall_connect_timeout_ms: Int64; 41 | FCall_packet_timeout_ms: Int64; 42 | FAnimation_search_bot_username: string; 43 | FVenue_search_bot_username: string; 44 | FPhoto_search_bot_username: string; 45 | FAuthorization_date: Int64; 46 | FMy_id: Int64; 47 | FArchive_and_mute_new_chats_from_unknown_users: Boolean; 48 | FIgnore_sensitive_content_restrictions: Boolean; 49 | FCan_ignore_sensitive_content_restrictions: Boolean; 50 | FIs_premium_available: Boolean; 51 | FAuthentication_token: string; 52 | public 53 | property Version: string read FVersion; 54 | property CommitHash: string read FCommit_hash; 55 | property UnixTime: Int64 read FUnix_time; 56 | property UtcTimeOffset: Int64 read FUtc_time_offset; 57 | property MessageTextLengthMax: Int64 read FMessage_text_length_max; 58 | property MessageCaptionLengthMax: Int64 read FMessage_caption_length_max; 59 | property BioLengthMax: Int64 read FBio_length_max; 60 | property SuggestedVideoNoteLength: Int64 read FSuggested_video_note_length; 61 | property SuggestedVideoNoteVideoBitrate: Int64 read FSuggested_video_note_video_bitrate; 62 | property SuggestedVideoNoteAudioBitrate: Int64 read FSuggested_video_note_audio_bitrate; 63 | property NotificationSoundDurationMax: Int64 read FNotification_sound_duration_max; 64 | property NotificationSoundSizeMax: Int64 read FNotification_sound_size_max; 65 | property NotificationSoundCountMax: Int64 read FNotification_sound_count_max; 66 | property ChatFilterCountMax: Int64 read FChat_filter_count_max; 67 | property ChatFilterChosenChatCountMax: Int64 read FChat_filter_chosen_chat_count_max; 68 | property PinnedForumTopicCountMax: Int64 read FPinned_forum_topic_count_max; 69 | property TelegramServiceNotificationsChatId: Int64 read FTelegram_service_notifications_chat_id; 70 | property RepliesBotChatId: Int64 read FReplies_bot_chat_id; 71 | property GroupAnonymousBotUserId: Int64 read FGroup_anonymous_bot_user_id; 72 | property ChannelBotUserId: Int64 read FChannel_bot_user_id; 73 | property AntiSpamBotUserId: Int64 read FAnti_spam_bot_user_id; 74 | property IsLocationVisible: Boolean read FIs_location_visible; 75 | property FavoriteStickersLimit: Int64 read FFavorite_stickers_limit; 76 | property TestMode: Boolean read FTest_mode; 77 | property ForwardedMessageCountMax: Int64 read FForwarded_message_count_max; 78 | property BasicGroupSizeMax: Int64 read FBasic_group_size_max; 79 | property SupergroupSizeMax: Int64 read FSupergroup_size_max; 80 | property PinnedChatCountMax: Int64 read FPinned_chat_count_max; 81 | property PinnedArchivedChatCountMax: Int64 read FPinned_archived_chat_count_max; 82 | property ExpectBlocking: Boolean read FExpect_blocking; 83 | property TMeUrl: string read FT_me_url; 84 | property CallsEnabled: Boolean read FCalls_enabled; 85 | property CallConnectTimeoutMs: Int64 read FCall_connect_timeout_ms; 86 | property CallPacketTimeoutMs: Int64 read FCall_packet_timeout_ms; 87 | property AnimationSearchBotUsername: string read FAnimation_search_bot_username; 88 | property VenueSearchBotUsername: string read FVenue_search_bot_username; 89 | property PhotoSearchBotUsername: string read FPhoto_search_bot_username; 90 | property AuthorizationDate: Int64 read FAuthorization_date; 91 | property MyId: Int64 read FMy_id; 92 | property ArchiveAndMuteNewChatsFromUnknownUsers: Boolean read FArchive_and_mute_new_chats_from_unknown_users; 93 | property IgnoreSensitiveContentRestrictions: Boolean read FIgnore_sensitive_content_restrictions; 94 | property CanIgnoreSensitiveContentRestrictions: Boolean read FCan_ignore_sensitive_content_restrictions; 95 | property IsPremiumAvailable: Boolean read FIs_premium_available; 96 | property AuthenticationToken: string read FAuthentication_token; 97 | end; 98 | 99 | implementation 100 | 101 | { TtgOptions } 102 | 103 | end. 104 | 105 | -------------------------------------------------------------------------------- /Sources/TGC.Wrapper.pas: -------------------------------------------------------------------------------- 1 | unit TGC.Wrapper; 2 | 3 | interface 4 | 5 | type 6 | TGChar = PAnsiChar; 7 | 8 | TVoid = IntPtr; 9 | 10 | const 11 | {$IFDEF MSWINDOWS} 12 | TDLibDLLName: string = 'tdjson.dll'; 13 | {$ELSE} 14 | TDLibDLLName: string = 'libtdjson.so'; 15 | {$ENDIF} 16 | 17 | type 18 | /// 19 | /// A type of callback function that will be called when a message is added to the internal TDLib log. 20 | /// 21 | TLogMessageCallback = procedure(ErrorMessage: TGChar); 22 | 23 | /// 24 | /// Creates a new instance of TDLib. 25 | /// 26 | /// Pointer to the created instance of TDLib. 27 | TJsonCreateClient = function(): TVoid; cdecl; 28 | 29 | /// 30 | /// Sends request to the TDLib client. May be called from any thread. 31 | /// 32 | /// The client. 33 | /// JSON-serialized null-terminated request to TDLib. 34 | TJsonClientSend = procedure(Client: TVoid; Request: TGChar); cdecl; 35 | 36 | /// 37 | /// Receives incoming updates and request responses from the TDLib client. May be called from any thread, but must not be called simultaneously from two different threads. Returned pointer will be deallocated by TDLib during next call to td_json_client_receive or td_json_client_execute in the same thread, so it can't be used after that. 38 | /// 39 | /// The client. 40 | /// The maximum number of seconds allowed for this function to wait for new data. 41 | /// JSON-serialized null-terminated incoming update or request response. May be NULL if the timeout expires. 42 | TJsonClientReceive = function(Client: TVoid; Timeout: Double): TGChar; cdecl; 43 | 44 | /// 45 | /// Synchronously executes TDLib request. May be called from any thread. Only a few requests can be executed synchronously. Returned pointer will be deallocated by TDLib during next call to td_json_client_receive or td_json_client_execute in the same thread, so it can't be used after that. 46 | /// 47 | /// The client. Currently ignored for all requests, so NULL can be passed. 48 | /// JSON-serialized null-terminated request to TDLib. 49 | /// JSON-serialized null-terminated request response. 50 | TJsonClientExecute = function(Client: TVoid; Request: TGChar): TGChar; cdecl; 51 | 52 | /// 53 | /// Destroys the TDLib client instance. After this is called the client instance must not be used anymore. 54 | /// 55 | /// The client. 56 | TJsonClientDestroy = procedure(Client: TVoid); cdecl; 57 | 58 | /// 59 | /// Sets the callback that will be called when a message is added to the internal TDLib log. None of the TDLib methods can be called from the callback. By default the callback is not set. 60 | /// 61 | /// The maximum verbosity level of messages for which the callback will be called. 62 | /// Callback that will be called when a message is added to the internal TDLib log. Pass nullptr to remove the callback. 63 | TSetLogMessageCallback = procedure(MaxVerbosityLevel: Integer; Callback: TLogMessageCallback); cdecl; 64 | 65 | var 66 | /// 67 | /// Creates a new instance of TDLib. 68 | /// 69 | /// Pointer to the created instance of TDLib. 70 | JsonCreateClient: TJsonCreateClient; 71 | /// 72 | /// Destroys the TDLib client instance. After this is called the client instance must not be used anymore. 73 | /// 74 | /// The client. 75 | JsonClientDestroy: TJsonClientDestroy; 76 | /// 77 | /// Sends request to the TDLib client. May be called from any thread. 78 | /// 79 | /// The client. 80 | /// JSON-serialized null-terminated request to TDLib. 81 | JsonClientSend: TJsonClientSend; 82 | /// 83 | /// Receives incoming updates and request responses from the TDLib client. May be called from any thread, but must not be called simultaneously from two different threads. Returned pointer will be deallocated by TDLib during next call to td_json_client_receive or td_json_client_execute in the same thread, so it can't be used after that. 84 | /// 85 | /// The client. 86 | /// The maximum number of seconds allowed for this function to wait for new data. 87 | /// JSON-serialized null-terminated incoming update or request response. May be NULL if the timeout expires. 88 | JsonClientReceive: TJsonClientReceive; 89 | /// 90 | /// Synchronously executes TDLib request. May be called from any thread. Only a few requests can be executed synchronously. Returned pointer will be deallocated by TDLib during next call to td_json_client_receive or td_json_client_execute in the same thread, so it can't be used after that. 91 | /// 92 | /// The client. Currently ignored for all requests, so NULL can be passed. 93 | /// JSON-serialized null-terminated request to TDLib. 94 | /// JSON-serialized null-terminated request response. 95 | JsonClientExecute: TJsonClientExecute; 96 | /// 97 | /// Sets the callback that will be called when a message is added to the internal TDLib log. None of the TDLib methods can be called from the callback. By default the callback is not set. 98 | /// 99 | /// The maximum verbosity level of messages for which the callback will be called. 100 | /// Callback that will be called when a message is added to the internal TDLib log. Pass nullptr to remove the callback. 101 | SetLogMessageCallback: TSetLogMessageCallback; 102 | 103 | var 104 | TDLib: NativeInt = 0; 105 | 106 | function TDLibInitialize: Boolean; 107 | 108 | procedure TDLibFinalize; 109 | 110 | function StringToTgChar(const Value: string): TGChar; 111 | 112 | function TgCharToString(const Value: TGChar): string; 113 | 114 | implementation 115 | 116 | uses 117 | {$IFDEF MSWINDOWS} 118 | Winapi.Windows, 119 | {$ENDIF} 120 | System.SysUtils; 121 | 122 | var 123 | TDLibRefCount: Integer = 0; 124 | 125 | function StringToTgChar(const Value: string): TGChar; 126 | begin 127 | Result := TGChar(UTF8Encode(Value)); 128 | end; 129 | 130 | function TgCharToString(const Value: TGChar): string; 131 | begin 132 | Result := UTF8ToString(Value); 133 | end; 134 | 135 | function TDLibInitialize: Boolean; 136 | var 137 | FilePath: string; 138 | begin 139 | FilePath := TDLibDLLName; 140 | if TDLib = 0 then 141 | TDLib := SafeLoadLibrary(FilePath); 142 | if TDLib <> 0 then 143 | begin 144 | @JsonCreateClient := GetProcAddress(TDLib, 'td_json_client_create'); 145 | @JsonClientDestroy := GetProcAddress(TDLib, 'td_json_client_destroy'); 146 | @JsonClientSend := GetProcAddress(TDLib, 'td_json_client_send'); 147 | @JsonClientReceive := GetProcAddress(TDLib, 'td_json_client_receive'); 148 | @JsonClientExecute := GetProcAddress(TDLib, 'td_json_client_execute'); 149 | @SetLogMessageCallback := GetProcAddress(TDLib, 'td_set_log_fatal_error_callback'); 150 | end; 151 | Result := TDLib <> 0; 152 | if Result then 153 | Inc(TDLibRefCount); 154 | end; 155 | 156 | procedure TDLibFinalize; 157 | begin 158 | Dec(TDLibRefCount); 159 | if TDLibRefCount <= 0 then 160 | if TDLib <> 0 then 161 | begin 162 | FreeLibrary(TDLib); 163 | TDLib := 0; 164 | end; 165 | end; 166 | 167 | end. 168 | 169 | -------------------------------------------------------------------------------- /TGC_API_Group.groupproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {C4297330-400C-4432-A3EC-A45060CF97D9} 4 | 5 | 6 | 7 | Package\TGC_API.dproj 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Default.Personality.12 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 | --------------------------------------------------------------------------------