common-tg-service 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +201 -0
- package/dist/IMap/IMap.d.ts +13 -0
- package/dist/IMap/IMap.js +160 -0
- package/dist/IMap/IMap.js.map +1 -0
- package/dist/app.controller.d.ts +11 -0
- package/dist/app.controller.js +160 -0
- package/dist/app.controller.js.map +1 -0
- package/dist/app.module.d.ts +4 -0
- package/dist/app.module.js +79 -0
- package/dist/app.module.js.map +1 -0
- package/dist/app.service.d.ts +3 -0
- package/dist/app.service.js +20 -0
- package/dist/app.service.js.map +1 -0
- package/dist/cloudinary.d.ts +17 -0
- package/dist/cloudinary.js +207 -0
- package/dist/cloudinary.js.map +1 -0
- package/dist/components/ConfigurationInit/configuration.schema.d.ts +38 -0
- package/dist/components/ConfigurationInit/configuration.schema.js +31 -0
- package/dist/components/ConfigurationInit/configuration.schema.js.map +1 -0
- package/dist/components/ConfigurationInit/init.controller.d.ts +7 -0
- package/dist/components/ConfigurationInit/init.controller.js +52 -0
- package/dist/components/ConfigurationInit/init.controller.js.map +1 -0
- package/dist/components/ConfigurationInit/init.module.d.ts +34 -0
- package/dist/components/ConfigurationInit/init.module.js +65 -0
- package/dist/components/ConfigurationInit/init.module.js.map +1 -0
- package/dist/components/ConfigurationInit/init.service.d.ts +35 -0
- package/dist/components/ConfigurationInit/init.service.js +59 -0
- package/dist/components/ConfigurationInit/init.service.js.map +1 -0
- package/dist/components/Telegram/Telegram.controller.d.ts +356 -0
- package/dist/components/Telegram/Telegram.controller.js +1366 -0
- package/dist/components/Telegram/Telegram.controller.js.map +1 -0
- package/dist/components/Telegram/Telegram.module.d.ts +2 -0
- package/dist/components/Telegram/Telegram.module.js +47 -0
- package/dist/components/Telegram/Telegram.module.js.map +1 -0
- package/dist/components/Telegram/Telegram.service.d.ts +453 -0
- package/dist/components/Telegram/Telegram.service.js +679 -0
- package/dist/components/Telegram/Telegram.service.js.map +1 -0
- package/dist/components/Telegram/TelegramManager.d.ts +486 -0
- package/dist/components/Telegram/TelegramManager.js +2530 -0
- package/dist/components/Telegram/TelegramManager.js.map +1 -0
- package/dist/components/Telegram/config/telegram-validation.config.d.ts +15 -0
- package/dist/components/Telegram/config/telegram-validation.config.js +47 -0
- package/dist/components/Telegram/config/telegram-validation.config.js.map +1 -0
- package/dist/components/Telegram/dto/batch-operations.dto.d.ts +24 -0
- package/dist/components/Telegram/dto/batch-operations.dto.js +102 -0
- package/dist/components/Telegram/dto/batch-operations.dto.js.map +1 -0
- package/dist/components/Telegram/dto/channel-operation.dto.d.ts +5 -0
- package/dist/components/Telegram/dto/channel-operation.dto.js +35 -0
- package/dist/components/Telegram/dto/channel-operation.dto.js.map +1 -0
- package/dist/components/Telegram/dto/common-responses.dto.d.ts +18 -0
- package/dist/components/Telegram/dto/common-responses.dto.js +52 -0
- package/dist/components/Telegram/dto/common-responses.dto.js.map +1 -0
- package/dist/components/Telegram/dto/contact-block-list.dto.d.ts +4 -0
- package/dist/components/Telegram/dto/contact-block-list.dto.js +28 -0
- package/dist/components/Telegram/dto/contact-block-list.dto.js.map +1 -0
- package/dist/components/Telegram/dto/contact-management.dto.d.ts +25 -0
- package/dist/components/Telegram/dto/contact-management.dto.js +88 -0
- package/dist/components/Telegram/dto/contact-management.dto.js.map +1 -0
- package/dist/components/Telegram/dto/contact-operation.dto.d.ts +12 -0
- package/dist/components/Telegram/dto/contact-operation.dto.js +43 -0
- package/dist/components/Telegram/dto/contact-operation.dto.js.map +1 -0
- package/dist/components/Telegram/dto/create-chat-folder.dto.d.ts +13 -0
- package/dist/components/Telegram/dto/create-chat-folder.dto.js +84 -0
- package/dist/components/Telegram/dto/create-chat-folder.dto.js.map +1 -0
- package/dist/components/Telegram/dto/group-operations.dto.d.ts +77 -0
- package/dist/components/Telegram/dto/group-operations.dto.js +282 -0
- package/dist/components/Telegram/dto/group-operations.dto.js.map +1 -0
- package/dist/components/Telegram/dto/index.d.ts +12 -0
- package/dist/components/Telegram/dto/index.js +32 -0
- package/dist/components/Telegram/dto/index.js.map +1 -0
- package/dist/components/Telegram/dto/media-filter.dto.d.ts +14 -0
- package/dist/components/Telegram/dto/media-filter.dto.js +64 -0
- package/dist/components/Telegram/dto/media-filter.dto.js.map +1 -0
- package/dist/components/Telegram/dto/media-metadata.dto.d.ts +0 -0
- package/dist/components/Telegram/dto/media-metadata.dto.js +1 -0
- package/dist/components/Telegram/dto/media-metadata.dto.js.map +1 -0
- package/dist/components/Telegram/dto/media-operations.dto.d.ts +38 -0
- package/dist/components/Telegram/dto/media-operations.dto.js +152 -0
- package/dist/components/Telegram/dto/media-operations.dto.js.map +1 -0
- package/dist/components/Telegram/dto/message-operations.dto.d.ts +0 -0
- package/dist/components/Telegram/dto/message-operations.dto.js +1 -0
- package/dist/components/Telegram/dto/message-operations.dto.js.map +1 -0
- package/dist/components/Telegram/dto/message-search.dto.d.ts +15 -0
- package/dist/components/Telegram/dto/message-search.dto.js +60 -0
- package/dist/components/Telegram/dto/message-search.dto.js.map +1 -0
- package/dist/components/Telegram/dto/metadata-operations.dto.d.ts +20 -0
- package/dist/components/Telegram/dto/metadata-operations.dto.js +101 -0
- package/dist/components/Telegram/dto/metadata-operations.dto.js.map +1 -0
- package/dist/components/Telegram/dto/notification-settings.dto.d.ts +15 -0
- package/dist/components/Telegram/dto/notification-settings.dto.js +60 -0
- package/dist/components/Telegram/dto/notification-settings.dto.js.map +1 -0
- package/dist/components/Telegram/dto/profile-settings.dto.d.ts +20 -0
- package/dist/components/Telegram/dto/profile-settings.dto.js +91 -0
- package/dist/components/Telegram/dto/profile-settings.dto.js.map +1 -0
- package/dist/components/Telegram/dto/response-validation.dto.d.ts +7 -0
- package/dist/components/Telegram/dto/response-validation.dto.js +37 -0
- package/dist/components/Telegram/dto/response-validation.dto.js.map +1 -0
- package/dist/components/Telegram/dto/schedule-operations.dto.d.ts +22 -0
- package/dist/components/Telegram/dto/schedule-operations.dto.js +97 -0
- package/dist/components/Telegram/dto/schedule-operations.dto.js.map +1 -0
- package/dist/components/Telegram/dto/update-profile.dto.d.ts +4 -0
- package/dist/components/Telegram/dto/update-profile.dto.js +29 -0
- package/dist/components/Telegram/dto/update-profile.dto.js.map +1 -0
- package/dist/components/Telegram/index.d.ts +5 -0
- package/dist/components/Telegram/index.js +22 -0
- package/dist/components/Telegram/index.js.map +1 -0
- package/dist/components/Telegram/types/client-operations.d.ts +34 -0
- package/dist/components/Telegram/types/client-operations.js +3 -0
- package/dist/components/Telegram/types/client-operations.js.map +1 -0
- package/dist/components/Telegram/types/telegram-error.d.ts +15 -0
- package/dist/components/Telegram/types/telegram-error.js +23 -0
- package/dist/components/Telegram/types/telegram-error.js.map +1 -0
- package/dist/components/Telegram/types/telegram-responses.d.ts +7 -0
- package/dist/components/Telegram/types/telegram-responses.js +3 -0
- package/dist/components/Telegram/types/telegram-responses.js.map +1 -0
- package/dist/components/Telegram/types/telegram-types.d.ts +14 -0
- package/dist/components/Telegram/types/telegram-types.js +3 -0
- package/dist/components/Telegram/types/telegram-types.js.map +1 -0
- package/dist/components/Telegram/utils/client-metadata.d.ts +19 -0
- package/dist/components/Telegram/utils/client-metadata.js +71 -0
- package/dist/components/Telegram/utils/client-metadata.js.map +1 -0
- package/dist/components/Telegram/utils/connection-manager.d.ts +17 -0
- package/dist/components/Telegram/utils/connection-manager.js +75 -0
- package/dist/components/Telegram/utils/connection-manager.js.map +1 -0
- package/dist/components/Telegram/utils/rate-limiter.d.ts +9 -0
- package/dist/components/Telegram/utils/rate-limiter.js +31 -0
- package/dist/components/Telegram/utils/rate-limiter.js.map +1 -0
- package/dist/components/Telegram/utils/telegram-logger.d.ts +10 -0
- package/dist/components/Telegram/utils/telegram-logger.js +29 -0
- package/dist/components/Telegram/utils/telegram-logger.js.map +1 -0
- package/dist/components/TgSignup/TgSignup.module.d.ts +2 -0
- package/dist/components/TgSignup/TgSignup.module.js +25 -0
- package/dist/components/TgSignup/TgSignup.module.js.map +1 -0
- package/dist/components/TgSignup/TgSignup.service.d.ts +24 -0
- package/dist/components/TgSignup/TgSignup.service.js +351 -0
- package/dist/components/TgSignup/TgSignup.service.js.map +1 -0
- package/dist/components/TgSignup/dto/tg-signup.dto.d.ts +16 -0
- package/dist/components/TgSignup/dto/tg-signup.dto.js +111 -0
- package/dist/components/TgSignup/dto/tg-signup.dto.js.map +1 -0
- package/dist/components/TgSignup/tgSignup.controller.d.ts +9 -0
- package/dist/components/TgSignup/tgSignup.controller.js +142 -0
- package/dist/components/TgSignup/tgSignup.controller.js.map +1 -0
- package/dist/components/active-channels/active-channels.controller.d.ts +19 -0
- package/dist/components/active-channels/active-channels.controller.js +168 -0
- package/dist/components/active-channels/active-channels.controller.js.map +1 -0
- package/dist/components/active-channels/active-channels.module.d.ts +2 -0
- package/dist/components/active-channels/active-channels.module.js +32 -0
- package/dist/components/active-channels/active-channels.module.js.map +1 -0
- package/dist/components/active-channels/active-channels.service.d.ts +61 -0
- package/dist/components/active-channels/active-channels.service.js +229 -0
- package/dist/components/active-channels/active-channels.service.js.map +1 -0
- package/dist/components/active-channels/dto/add-reaction.dto.d.ts +3 -0
- package/dist/components/active-channels/dto/add-reaction.dto.js +21 -0
- package/dist/components/active-channels/dto/add-reaction.dto.js.map +1 -0
- package/dist/components/active-channels/dto/create-active-channel.dto.d.ts +19 -0
- package/dist/components/active-channels/dto/create-active-channel.dto.js +117 -0
- package/dist/components/active-channels/dto/create-active-channel.dto.js.map +1 -0
- package/dist/components/active-channels/dto/update-active-channel.dto.d.ts +5 -0
- package/dist/components/active-channels/dto/update-active-channel.dto.js +9 -0
- package/dist/components/active-channels/dto/update-active-channel.dto.js.map +1 -0
- package/dist/components/active-channels/schemas/active-channel.schema.d.ts +56 -0
- package/dist/components/active-channels/schemas/active-channel.schema.js +142 -0
- package/dist/components/active-channels/schemas/active-channel.schema.js.map +1 -0
- package/dist/components/archived-clients/archived-client.controller.d.ts +18 -0
- package/dist/components/archived-clients/archived-client.controller.js +137 -0
- package/dist/components/archived-clients/archived-client.controller.js.map +1 -0
- package/dist/components/archived-clients/archived-client.module.d.ts +2 -0
- package/dist/components/archived-clients/archived-client.module.js +34 -0
- package/dist/components/archived-clients/archived-client.module.js.map +1 -0
- package/dist/components/archived-clients/archived-client.service.d.ts +46 -0
- package/dist/components/archived-clients/archived-client.service.js +147 -0
- package/dist/components/archived-clients/archived-client.service.js.map +1 -0
- package/dist/components/buffer-clients/buffer-client.controller.d.ts +24 -0
- package/dist/components/buffer-clients/buffer-client.controller.js +174 -0
- package/dist/components/buffer-clients/buffer-client.controller.js.map +1 -0
- package/dist/components/buffer-clients/buffer-client.module.d.ts +2 -0
- package/dist/components/buffer-clients/buffer-client.module.js +42 -0
- package/dist/components/buffer-clients/buffer-client.module.js.map +1 -0
- package/dist/components/buffer-clients/buffer-client.service.d.ts +75 -0
- package/dist/components/buffer-clients/buffer-client.service.js +533 -0
- package/dist/components/buffer-clients/buffer-client.service.js.map +1 -0
- package/dist/components/buffer-clients/dto/create-buffer-client.dto.d.ts +7 -0
- package/dist/components/buffer-clients/dto/create-buffer-client.dto.js +59 -0
- package/dist/components/buffer-clients/dto/create-buffer-client.dto.js.map +1 -0
- package/dist/components/buffer-clients/dto/search-buffer- client.dto.d.ts +7 -0
- package/dist/components/buffer-clients/dto/search-buffer- client.dto.js +63 -0
- package/dist/components/buffer-clients/dto/search-buffer- client.dto.js.map +1 -0
- package/dist/components/buffer-clients/dto/update-buffer-client.dto.d.ts +5 -0
- package/dist/components/buffer-clients/dto/update-buffer-client.dto.js +9 -0
- package/dist/components/buffer-clients/dto/update-buffer-client.dto.js.map +1 -0
- package/dist/components/buffer-clients/schemas/buffer-client.schema.d.ts +43 -0
- package/dist/components/buffer-clients/schemas/buffer-client.schema.js +49 -0
- package/dist/components/buffer-clients/schemas/buffer-client.schema.js.map +1 -0
- package/dist/components/builds/build.controller.d.ts +7 -0
- package/dist/components/builds/build.controller.js +52 -0
- package/dist/components/builds/build.controller.js.map +1 -0
- package/dist/components/builds/build.module.d.ts +2 -0
- package/dist/components/builds/build.module.js +32 -0
- package/dist/components/builds/build.module.js.map +1 -0
- package/dist/components/builds/build.service.d.ts +36 -0
- package/dist/components/builds/build.service.js +58 -0
- package/dist/components/builds/build.service.js.map +1 -0
- package/dist/components/builds/builds.schema.d.ts +38 -0
- package/dist/components/builds/builds.schema.js +29 -0
- package/dist/components/builds/builds.schema.js.map +1 -0
- package/dist/components/channels/channels.controller.d.ts +16 -0
- package/dist/components/channels/channels.controller.js +112 -0
- package/dist/components/channels/channels.controller.js.map +1 -0
- package/dist/components/channels/channels.module.d.ts +2 -0
- package/dist/components/channels/channels.module.js +30 -0
- package/dist/components/channels/channels.module.js.map +1 -0
- package/dist/components/channels/channels.service.d.ts +43 -0
- package/dist/components/channels/channels.service.js +167 -0
- package/dist/components/channels/channels.service.js.map +1 -0
- package/dist/components/channels/dto/create-channel.dto.d.ts +13 -0
- package/dist/components/channels/dto/create-channel.dto.js +104 -0
- package/dist/components/channels/dto/create-channel.dto.js.map +1 -0
- package/dist/components/channels/dto/search-channel.dto.d.ts +9 -0
- package/dist/components/channels/dto/search-channel.dto.js +66 -0
- package/dist/components/channels/dto/search-channel.dto.js.map +1 -0
- package/dist/components/channels/dto/update-channel.dto.d.ts +5 -0
- package/dist/components/channels/dto/update-channel.dto.js +9 -0
- package/dist/components/channels/dto/update-channel.dto.js.map +1 -0
- package/dist/components/channels/schemas/channel.schema.d.ts +49 -0
- package/dist/components/channels/schemas/channel.schema.js +93 -0
- package/dist/components/channels/schemas/channel.schema.js.map +1 -0
- package/dist/components/clients/client.controller.d.ts +32 -0
- package/dist/components/clients/client.controller.js +230 -0
- package/dist/components/clients/client.controller.js.map +1 -0
- package/dist/components/clients/client.module.d.ts +2 -0
- package/dist/components/clients/client.module.js +40 -0
- package/dist/components/clients/client.module.js.map +1 -0
- package/dist/components/clients/client.service.d.ts +76 -0
- package/dist/components/clients/client.service.js +417 -0
- package/dist/components/clients/client.service.js.map +1 -0
- package/dist/components/clients/dto/create-client.dto.d.ts +17 -0
- package/dist/components/clients/dto/create-client.dto.js +77 -0
- package/dist/components/clients/dto/create-client.dto.js.map +1 -0
- package/dist/components/clients/dto/search-client.dto.d.ts +16 -0
- package/dist/components/clients/dto/search-client.dto.js +119 -0
- package/dist/components/clients/dto/search-client.dto.js.map +1 -0
- package/dist/components/clients/dto/setup-client.dto.d.ts +6 -0
- package/dist/components/clients/dto/setup-client.dto.js +66 -0
- package/dist/components/clients/dto/setup-client.dto.js.map +1 -0
- package/dist/components/clients/dto/update-client.dto.d.ts +5 -0
- package/dist/components/clients/dto/update-client.dto.js +9 -0
- package/dist/components/clients/dto/update-client.dto.js.map +1 -0
- package/dist/components/clients/schemas/client.schema.d.ts +53 -0
- package/dist/components/clients/schemas/client.schema.js +105 -0
- package/dist/components/clients/schemas/client.schema.js.map +1 -0
- package/dist/components/n-point/npoint.controller.d.ts +9 -0
- package/dist/components/n-point/npoint.controller.js +134 -0
- package/dist/components/n-point/npoint.controller.js.map +1 -0
- package/dist/components/n-point/npoint.module.d.ts +2 -0
- package/dist/components/n-point/npoint.module.js +23 -0
- package/dist/components/n-point/npoint.module.js.map +1 -0
- package/dist/components/n-point/npoint.service.d.ts +14 -0
- package/dist/components/n-point/npoint.service.js +158 -0
- package/dist/components/n-point/npoint.service.js.map +1 -0
- package/dist/components/promote-clients/dto/create-promote-client.dto.d.ts +7 -0
- package/dist/components/promote-clients/dto/create-promote-client.dto.js +59 -0
- package/dist/components/promote-clients/dto/create-promote-client.dto.js.map +1 -0
- package/dist/components/promote-clients/dto/search-promote-client.dto.d.ts +6 -0
- package/dist/components/promote-clients/dto/search-promote-client.dto.js +54 -0
- package/dist/components/promote-clients/dto/search-promote-client.dto.js.map +1 -0
- package/dist/components/promote-clients/dto/update-promote-client.dto.d.ts +5 -0
- package/dist/components/promote-clients/dto/update-promote-client.dto.js +9 -0
- package/dist/components/promote-clients/dto/update-promote-client.dto.js.map +1 -0
- package/dist/components/promote-clients/promote-client.controller.d.ts +24 -0
- package/dist/components/promote-clients/promote-client.controller.js +174 -0
- package/dist/components/promote-clients/promote-client.controller.js.map +1 -0
- package/dist/components/promote-clients/promote-client.module.d.ts +2 -0
- package/dist/components/promote-clients/promote-client.module.js +42 -0
- package/dist/components/promote-clients/promote-client.module.js.map +1 -0
- package/dist/components/promote-clients/promote-client.service.d.ts +73 -0
- package/dist/components/promote-clients/promote-client.service.js +564 -0
- package/dist/components/promote-clients/promote-client.service.js.map +1 -0
- package/dist/components/promote-clients/schemas/promote-client.schema.d.ts +43 -0
- package/dist/components/promote-clients/schemas/promote-client.schema.js +49 -0
- package/dist/components/promote-clients/schemas/promote-client.schema.js.map +1 -0
- package/dist/components/promote-msgs/promote-msgs.controller.d.ts +7 -0
- package/dist/components/promote-msgs/promote-msgs.controller.js +52 -0
- package/dist/components/promote-msgs/promote-msgs.controller.js.map +1 -0
- package/dist/components/promote-msgs/promote-msgs.module.d.ts +2 -0
- package/dist/components/promote-msgs/promote-msgs.module.js +30 -0
- package/dist/components/promote-msgs/promote-msgs.module.js.map +1 -0
- package/dist/components/promote-msgs/promote-msgs.schema.d.ts +38 -0
- package/dist/components/promote-msgs/promote-msgs.schema.js +29 -0
- package/dist/components/promote-msgs/promote-msgs.schema.js.map +1 -0
- package/dist/components/promote-msgs/promote-msgs.service.d.ts +34 -0
- package/dist/components/promote-msgs/promote-msgs.service.js +48 -0
- package/dist/components/promote-msgs/promote-msgs.service.js.map +1 -0
- package/dist/components/promote-stats/dto/create-promote-stat.dto.d.ts +10 -0
- package/dist/components/promote-stats/dto/create-promote-stat.dto.js +49 -0
- package/dist/components/promote-stats/dto/create-promote-stat.dto.js.map +1 -0
- package/dist/components/promote-stats/dto/update-promote-stat.dto.d.ts +5 -0
- package/dist/components/promote-stats/dto/update-promote-stat.dto.js +9 -0
- package/dist/components/promote-stats/dto/update-promote-stat.dto.js.map +1 -0
- package/dist/components/promote-stats/promote-stat.controller.d.ts +12 -0
- package/dist/components/promote-stats/promote-stat.controller.js +82 -0
- package/dist/components/promote-stats/promote-stat.controller.js.map +1 -0
- package/dist/components/promote-stats/promote-stat.module.d.ts +2 -0
- package/dist/components/promote-stats/promote-stat.module.js +31 -0
- package/dist/components/promote-stats/promote-stat.module.js.map +1 -0
- package/dist/components/promote-stats/promote-stat.service.d.ts +42 -0
- package/dist/components/promote-stats/promote-stat.service.js +80 -0
- package/dist/components/promote-stats/promote-stat.service.js.map +1 -0
- package/dist/components/promote-stats/schemas/promote-stat.schema.d.ts +46 -0
- package/dist/components/promote-stats/schemas/promote-stat.schema.js +62 -0
- package/dist/components/promote-stats/schemas/promote-stat.schema.js.map +1 -0
- package/dist/components/shared/dto/execute-request.dto.d.ts +21 -0
- package/dist/components/shared/dto/execute-request.dto.js +86 -0
- package/dist/components/shared/dto/execute-request.dto.js.map +1 -0
- package/dist/components/stats/create-stat.dto.d.ts +14 -0
- package/dist/components/stats/create-stat.dto.js +65 -0
- package/dist/components/stats/create-stat.dto.js.map +1 -0
- package/dist/components/stats/stat.controller.d.ts +12 -0
- package/dist/components/stats/stat.controller.js +85 -0
- package/dist/components/stats/stat.controller.js.map +1 -0
- package/dist/components/stats/stat.module.d.ts +2 -0
- package/dist/components/stats/stat.module.js +30 -0
- package/dist/components/stats/stat.module.js.map +1 -0
- package/dist/components/stats/stat.schema.d.ts +50 -0
- package/dist/components/stats/stat.schema.js +83 -0
- package/dist/components/stats/stat.schema.js.map +1 -0
- package/dist/components/stats/stat.service.d.ts +39 -0
- package/dist/components/stats/stat.service.js +61 -0
- package/dist/components/stats/stat.service.js.map +1 -0
- package/dist/components/stats/update-stat.dto.d.ts +5 -0
- package/dist/components/stats/update-stat.dto.js +9 -0
- package/dist/components/stats/update-stat.dto.js.map +1 -0
- package/dist/components/stats2/create-stat2.dto.d.ts +14 -0
- package/dist/components/stats2/create-stat2.dto.js +65 -0
- package/dist/components/stats2/create-stat2.dto.js.map +1 -0
- package/dist/components/stats2/stat2.controller.d.ts +12 -0
- package/dist/components/stats2/stat2.controller.js +85 -0
- package/dist/components/stats2/stat2.controller.js.map +1 -0
- package/dist/components/stats2/stat2.module.d.ts +2 -0
- package/dist/components/stats2/stat2.module.js +30 -0
- package/dist/components/stats2/stat2.module.js.map +1 -0
- package/dist/components/stats2/stat2.schema.d.ts +50 -0
- package/dist/components/stats2/stat2.schema.js +83 -0
- package/dist/components/stats2/stat2.schema.js.map +1 -0
- package/dist/components/stats2/stat2.service.d.ts +39 -0
- package/dist/components/stats2/stat2.service.js +61 -0
- package/dist/components/stats2/stat2.service.js.map +1 -0
- package/dist/components/stats2/update-stat2.dto.d.ts +5 -0
- package/dist/components/stats2/update-stat2.dto.js +9 -0
- package/dist/components/stats2/update-stat2.dto.js.map +1 -0
- package/dist/components/transactions/dto/create-transaction.dto.d.ts +10 -0
- package/dist/components/transactions/dto/create-transaction.dto.js +49 -0
- package/dist/components/transactions/dto/create-transaction.dto.js.map +1 -0
- package/dist/components/transactions/dto/update-transaction.dto.d.ts +5 -0
- package/dist/components/transactions/dto/update-transaction.dto.js +9 -0
- package/dist/components/transactions/dto/update-transaction.dto.js.map +1 -0
- package/dist/components/transactions/schemas/transaction.schema.d.ts +45 -0
- package/dist/components/transactions/schemas/transaction.schema.js +54 -0
- package/dist/components/transactions/schemas/transaction.schema.js.map +1 -0
- package/dist/components/transactions/transaction.controller.d.ts +15 -0
- package/dist/components/transactions/transaction.controller.js +99 -0
- package/dist/components/transactions/transaction.controller.js.map +1 -0
- package/dist/components/transactions/transaction.module.d.ts +2 -0
- package/dist/components/transactions/transaction.module.js +30 -0
- package/dist/components/transactions/transaction.module.js.map +1 -0
- package/dist/components/transactions/transaction.service.d.ts +41 -0
- package/dist/components/transactions/transaction.service.js +77 -0
- package/dist/components/transactions/transaction.service.js.map +1 -0
- package/dist/components/upi-ids/upi-ids.controller.d.ts +7 -0
- package/dist/components/upi-ids/upi-ids.controller.js +52 -0
- package/dist/components/upi-ids/upi-ids.controller.js.map +1 -0
- package/dist/components/upi-ids/upi-ids.module.d.ts +2 -0
- package/dist/components/upi-ids/upi-ids.module.js +32 -0
- package/dist/components/upi-ids/upi-ids.module.js.map +1 -0
- package/dist/components/upi-ids/upi-ids.schema.d.ts +38 -0
- package/dist/components/upi-ids/upi-ids.schema.js +33 -0
- package/dist/components/upi-ids/upi-ids.schema.js.map +1 -0
- package/dist/components/upi-ids/upi-ids.service.d.ts +39 -0
- package/dist/components/upi-ids/upi-ids.service.js +83 -0
- package/dist/components/upi-ids/upi-ids.service.js.map +1 -0
- package/dist/components/user-data/dto/create-user-data.dto.d.ts +22 -0
- package/dist/components/user-data/dto/create-user-data.dto.js +97 -0
- package/dist/components/user-data/dto/create-user-data.dto.js.map +1 -0
- package/dist/components/user-data/dto/search-user-data.dto.d.ts +18 -0
- package/dist/components/user-data/dto/search-user-data.dto.js +83 -0
- package/dist/components/user-data/dto/search-user-data.dto.js.map +1 -0
- package/dist/components/user-data/dto/update-user-data.dto.d.ts +5 -0
- package/dist/components/user-data/dto/update-user-data.dto.js +9 -0
- package/dist/components/user-data/dto/update-user-data.dto.js.map +1 -0
- package/dist/components/user-data/schemas/user-data.schema.d.ts +59 -0
- package/dist/components/user-data/schemas/user-data.schema.js +113 -0
- package/dist/components/user-data/schemas/user-data.schema.js.map +1 -0
- package/dist/components/user-data/user-data.controller.d.ts +18 -0
- package/dist/components/user-data/user-data.controller.js +141 -0
- package/dist/components/user-data/user-data.controller.js.map +1 -0
- package/dist/components/user-data/user-data.module.d.ts +2 -0
- package/dist/components/user-data/user-data.module.js +30 -0
- package/dist/components/user-data/user-data.module.js.map +1 -0
- package/dist/components/user-data/user-data.service.d.ts +46 -0
- package/dist/components/user-data/user-data.service.js +131 -0
- package/dist/components/user-data/user-data.service.js.map +1 -0
- package/dist/components/users/dto/create-user.dto.d.ts +33 -0
- package/dist/components/users/dto/create-user.dto.js +142 -0
- package/dist/components/users/dto/create-user.dto.js.map +1 -0
- package/dist/components/users/dto/search-user.dto.d.ts +24 -0
- package/dist/components/users/dto/search-user.dto.js +152 -0
- package/dist/components/users/dto/search-user.dto.js.map +1 -0
- package/dist/components/users/dto/update-user.dto.d.ts +5 -0
- package/dist/components/users/dto/update-user.dto.js +9 -0
- package/dist/components/users/dto/update-user.dto.js.map +1 -0
- package/dist/components/users/schemas/user.schema.d.ts +70 -0
- package/dist/components/users/schemas/user.schema.js +179 -0
- package/dist/components/users/schemas/user.schema.js.map +1 -0
- package/dist/components/users/users.controller.d.ts +16 -0
- package/dist/components/users/users.controller.js +120 -0
- package/dist/components/users/users.controller.js.map +1 -0
- package/dist/components/users/users.module.d.ts +2 -0
- package/dist/components/users/users.module.js +34 -0
- package/dist/components/users/users.module.js.map +1 -0
- package/dist/components/users/users.service.d.ts +46 -0
- package/dist/components/users/users.service.js +117 -0
- package/dist/components/users/users.service.js.map +1 -0
- package/dist/features/clients/index.d.ts +14 -0
- package/dist/features/clients/index.js +31 -0
- package/dist/features/clients/index.js.map +1 -0
- package/dist/features/stats/index.d.ts +10 -0
- package/dist/features/stats/index.js +31 -0
- package/dist/features/stats/index.js.map +1 -0
- package/dist/features/telegram/index.d.ts +4 -0
- package/dist/features/telegram/index.js +26 -0
- package/dist/features/telegram/index.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/telegram.d.ts +86 -0
- package/dist/interfaces/telegram.js +10 -0
- package/dist/interfaces/telegram.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +81 -0
- package/dist/main.js.map +1 -0
- package/dist/middlewares/logger.middleware.d.ts +6 -0
- package/dist/middlewares/logger.middleware.js +60 -0
- package/dist/middlewares/logger.middleware.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/utils/fetchWithTimeout.d.ts +4 -0
- package/dist/utils/fetchWithTimeout.js +180 -0
- package/dist/utils/fetchWithTimeout.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +16 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logbots.d.ts +2 -0
- package/dist/utils/logbots.js +36 -0
- package/dist/utils/logbots.js.map +1 -0
- package/dist/utils/parseError.d.ts +6 -0
- package/dist/utils/parseError.js +115 -0
- package/dist/utils/parseError.js.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +87 -0
- package/dist/utils.js.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,2530 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const telegram_1 = require("telegram");
|
|
30
|
+
const sessions_1 = require("telegram/sessions");
|
|
31
|
+
const events_1 = require("telegram/events");
|
|
32
|
+
const axios_1 = __importDefault(require("axios"));
|
|
33
|
+
const fs = __importStar(require("fs"));
|
|
34
|
+
const uploads_1 = require("telegram/client/uploads");
|
|
35
|
+
const Helpers_1 = require("telegram/Helpers");
|
|
36
|
+
const Logger_1 = require("telegram/extensions/Logger");
|
|
37
|
+
const IMap_1 = require("../../IMap/IMap");
|
|
38
|
+
const big_integer_1 = __importDefault(require("big-integer"));
|
|
39
|
+
const utils_1 = require("../../utils");
|
|
40
|
+
const parseError_1 = require("../../utils/parseError");
|
|
41
|
+
const fetchWithTimeout_1 = require("../../utils/fetchWithTimeout");
|
|
42
|
+
const logbots_1 = require("../../utils/logbots");
|
|
43
|
+
class TelegramManager {
|
|
44
|
+
constructor(sessionString, phoneNumber) {
|
|
45
|
+
this.session = new sessions_1.StringSession(sessionString);
|
|
46
|
+
this.phoneNumber = phoneNumber;
|
|
47
|
+
this.client = null;
|
|
48
|
+
this.channelArray = [];
|
|
49
|
+
this.contentFilters = new Map();
|
|
50
|
+
}
|
|
51
|
+
static getActiveClientSetup() {
|
|
52
|
+
return TelegramManager.activeClientSetup;
|
|
53
|
+
}
|
|
54
|
+
static setActiveClientSetup(data) {
|
|
55
|
+
TelegramManager.activeClientSetup = data;
|
|
56
|
+
}
|
|
57
|
+
async createGroup() {
|
|
58
|
+
const groupName = "Saved Messages";
|
|
59
|
+
const groupDescription = this.phoneNumber;
|
|
60
|
+
const result = await this.client.invoke(new telegram_1.Api.channels.CreateChannel({
|
|
61
|
+
title: groupName,
|
|
62
|
+
about: groupDescription,
|
|
63
|
+
megagroup: true,
|
|
64
|
+
forImport: true,
|
|
65
|
+
}));
|
|
66
|
+
const { id, accessHash } = result.chats[0];
|
|
67
|
+
const folderId = 1;
|
|
68
|
+
await this.client.invoke(new telegram_1.Api.folders.EditPeerFolders({
|
|
69
|
+
folderPeers: [
|
|
70
|
+
new telegram_1.Api.InputFolderPeer({
|
|
71
|
+
peer: new telegram_1.Api.InputPeerChannel({
|
|
72
|
+
channelId: id,
|
|
73
|
+
accessHash: accessHash,
|
|
74
|
+
}),
|
|
75
|
+
folderId: folderId,
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
}));
|
|
79
|
+
const usersToAdd = ["fuckyoubabie"];
|
|
80
|
+
const addUsersResult = await this.client.invoke(new telegram_1.Api.channels.InviteToChannel({
|
|
81
|
+
channel: new telegram_1.Api.InputChannel({
|
|
82
|
+
channelId: id,
|
|
83
|
+
accessHash: accessHash,
|
|
84
|
+
}),
|
|
85
|
+
users: usersToAdd
|
|
86
|
+
}));
|
|
87
|
+
return { id, accessHash };
|
|
88
|
+
}
|
|
89
|
+
async createGroupAndForward(fromChatId) {
|
|
90
|
+
const { id, accessHash } = await this.createGroup();
|
|
91
|
+
await this.forwardSecretMsgs(fromChatId, id.toString());
|
|
92
|
+
}
|
|
93
|
+
async joinChannelAndForward(fromChatId, channel) {
|
|
94
|
+
const result = await this.joinChannel(channel);
|
|
95
|
+
const folderId = 1;
|
|
96
|
+
await this.client.invoke(new telegram_1.Api.folders.EditPeerFolders({
|
|
97
|
+
folderPeers: [
|
|
98
|
+
new telegram_1.Api.InputFolderPeer({
|
|
99
|
+
peer: new telegram_1.Api.InputPeerChannel({
|
|
100
|
+
channelId: result.chats[0].id,
|
|
101
|
+
accessHash: result.chats[0].accessHash,
|
|
102
|
+
}),
|
|
103
|
+
folderId: folderId,
|
|
104
|
+
}),
|
|
105
|
+
],
|
|
106
|
+
}));
|
|
107
|
+
await this.forwardSecretMsgs(fromChatId, channel);
|
|
108
|
+
}
|
|
109
|
+
async forwardSecretMsgs(fromChatId, toChatId) {
|
|
110
|
+
let offset = 0;
|
|
111
|
+
const limit = 100;
|
|
112
|
+
let totalMessages = 0;
|
|
113
|
+
let forwardedCount = 0;
|
|
114
|
+
let messages = [];
|
|
115
|
+
do {
|
|
116
|
+
messages = await this.client.getMessages(fromChatId, { offsetId: offset, limit });
|
|
117
|
+
totalMessages = messages.total;
|
|
118
|
+
const messageIds = messages.map((message) => {
|
|
119
|
+
offset = message.id;
|
|
120
|
+
if (message.id && message.media) {
|
|
121
|
+
return message.id;
|
|
122
|
+
}
|
|
123
|
+
return undefined;
|
|
124
|
+
}).filter(id => id !== undefined);
|
|
125
|
+
console.log(messageIds);
|
|
126
|
+
if (messageIds.length > 0) {
|
|
127
|
+
try {
|
|
128
|
+
const result = await this.client.forwardMessages(toChatId, {
|
|
129
|
+
messages: messageIds,
|
|
130
|
+
fromPeer: fromChatId,
|
|
131
|
+
});
|
|
132
|
+
forwardedCount += messageIds.length;
|
|
133
|
+
console.log(`Forwarded ${forwardedCount} / ${totalMessages} messages`);
|
|
134
|
+
await (0, Helpers_1.sleep)(5000);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error("Error occurred while forwarding messages:", error);
|
|
138
|
+
}
|
|
139
|
+
await (0, Helpers_1.sleep)(5000);
|
|
140
|
+
}
|
|
141
|
+
} while (messages.length > 0);
|
|
142
|
+
await this.leaveChannels([toChatId]);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
async forwardMessages(fromChatId, toChatId, messageIds) {
|
|
146
|
+
const chunkSize = 30;
|
|
147
|
+
const totalMessages = messageIds.length;
|
|
148
|
+
let forwardedCount = 0;
|
|
149
|
+
for (let i = 0; i < totalMessages; i += chunkSize) {
|
|
150
|
+
const chunk = messageIds.slice(i, i + chunkSize);
|
|
151
|
+
try {
|
|
152
|
+
await this.client.forwardMessages(toChatId, {
|
|
153
|
+
messages: chunk,
|
|
154
|
+
fromPeer: fromChatId,
|
|
155
|
+
});
|
|
156
|
+
forwardedCount += chunk.length;
|
|
157
|
+
console.log(`Forwarded ${forwardedCount} / ${totalMessages} messages`);
|
|
158
|
+
await (0, Helpers_1.sleep)(5000);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
console.error("Error occurred while forwarding messages:", error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return forwardedCount;
|
|
165
|
+
}
|
|
166
|
+
async disconnect() {
|
|
167
|
+
if (this.client) {
|
|
168
|
+
try {
|
|
169
|
+
console.log("Destroying Client: ", this.phoneNumber);
|
|
170
|
+
await this.cleanupClient();
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error("Error during disconnect:", error);
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async cleanupClient() {
|
|
179
|
+
try {
|
|
180
|
+
if (!this.client)
|
|
181
|
+
return;
|
|
182
|
+
const handlers = this.client.listEventHandlers();
|
|
183
|
+
for (const handler of handlers) {
|
|
184
|
+
this.client.removeEventHandler(handler[1], handler[0]);
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
if (this.client.connected) {
|
|
188
|
+
await this.client.disconnect();
|
|
189
|
+
}
|
|
190
|
+
await this.client.destroy();
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
(0, parseError_1.parseError)(error, `${this.phoneNumber}: Error during client cleanup`);
|
|
194
|
+
}
|
|
195
|
+
await this.client.destroy();
|
|
196
|
+
await this.client.disconnect();
|
|
197
|
+
this.client = null;
|
|
198
|
+
this.session.delete();
|
|
199
|
+
this.channelArray = [];
|
|
200
|
+
this.client = null;
|
|
201
|
+
await (0, Helpers_1.sleep)(2000);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
(0, parseError_1.parseError)(error, `${this.phoneNumber}: Error during client cleanup`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async getchatId(username) {
|
|
208
|
+
if (!this.client)
|
|
209
|
+
throw new Error('Client is not initialized');
|
|
210
|
+
const entity = await this.client.getInputEntity(username);
|
|
211
|
+
return entity;
|
|
212
|
+
}
|
|
213
|
+
async getMe() {
|
|
214
|
+
const me = await this.client.getMe();
|
|
215
|
+
return me;
|
|
216
|
+
}
|
|
217
|
+
async errorHandler(error) {
|
|
218
|
+
(0, parseError_1.parseError)(error);
|
|
219
|
+
if (error.message && error.message == 'TIMEOUT') {
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
console.error(`Error occurred for API ID ${this.phoneNumber}:`, error);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async createClient(handler = true, handlerFn) {
|
|
226
|
+
this.client = new telegram_1.TelegramClient(this.session, parseInt(process.env.API_ID), process.env.API_HASH, {
|
|
227
|
+
connectionRetries: 5,
|
|
228
|
+
});
|
|
229
|
+
this.client.setLogLevel(Logger_1.LogLevel.ERROR);
|
|
230
|
+
await this.client.connect();
|
|
231
|
+
const me = await this.client.getMe();
|
|
232
|
+
console.log("Connected Client : ", me.phone);
|
|
233
|
+
if (handler && this.client) {
|
|
234
|
+
console.log("Adding event Handler");
|
|
235
|
+
if (handlerFn) {
|
|
236
|
+
this.client.addEventHandler(async (event) => { await handlerFn(event); }, new events_1.NewMessage());
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
this.client.addEventHandler(async (event) => { await this.handleEvents(event); }, new events_1.NewMessage());
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return this.client;
|
|
243
|
+
}
|
|
244
|
+
async getGrpMembers(entity) {
|
|
245
|
+
try {
|
|
246
|
+
const result = [];
|
|
247
|
+
const chat = await this.client.getEntity(entity);
|
|
248
|
+
if (!(chat instanceof telegram_1.Api.Chat || chat instanceof telegram_1.Api.Channel)) {
|
|
249
|
+
console.log("Invalid group or channel!");
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
console.log(`Fetching members of ${chat.title || chat.username}...`);
|
|
253
|
+
const participants = await this.client.invoke(new telegram_1.Api.channels.GetParticipants({
|
|
254
|
+
channel: chat,
|
|
255
|
+
filter: new telegram_1.Api.ChannelParticipantsRecent(),
|
|
256
|
+
offset: 0,
|
|
257
|
+
limit: 200,
|
|
258
|
+
hash: (0, big_integer_1.default)(0),
|
|
259
|
+
}));
|
|
260
|
+
if (participants instanceof telegram_1.Api.channels.ChannelParticipants) {
|
|
261
|
+
const users = participants.participants;
|
|
262
|
+
console.log(`Members: ${users.length}`);
|
|
263
|
+
for (const user of users) {
|
|
264
|
+
const userInfo = user instanceof telegram_1.Api.ChannelParticipant ? user.userId : null;
|
|
265
|
+
if (userInfo) {
|
|
266
|
+
const userDetails = await this.client.getEntity(userInfo);
|
|
267
|
+
result.push({
|
|
268
|
+
tgId: userDetails.id,
|
|
269
|
+
name: `${userDetails.firstName || ""} ${userDetails.lastName || ""}`,
|
|
270
|
+
username: `${userDetails.username || ""}`,
|
|
271
|
+
});
|
|
272
|
+
if (userDetails.firstName == 'Deleted Account' && !userDetails.username) {
|
|
273
|
+
console.log(JSON.stringify(userDetails.id));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
console.log(JSON.stringify(user?.userId));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
console.log("No members found or invalid group.");
|
|
283
|
+
}
|
|
284
|
+
console.log(result.length);
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
catch (err) {
|
|
288
|
+
console.error("Error fetching group members:", err);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
async getMessages(entityLike, limit = 8) {
|
|
292
|
+
const messages = await this.client.getMessages(entityLike, { limit });
|
|
293
|
+
return messages;
|
|
294
|
+
}
|
|
295
|
+
async getDialogs(params) {
|
|
296
|
+
const chats = await this.client.getDialogs(params);
|
|
297
|
+
console.log("TotalChats:", chats.total);
|
|
298
|
+
return chats;
|
|
299
|
+
}
|
|
300
|
+
async getLastMsgs(limit) {
|
|
301
|
+
if (!this.client)
|
|
302
|
+
throw new Error('Client is not initialized');
|
|
303
|
+
const msgs = await this.client.getMessages("777000", { limit });
|
|
304
|
+
let resp = '';
|
|
305
|
+
msgs.forEach((msg) => {
|
|
306
|
+
console.log(msg.text);
|
|
307
|
+
resp += msg.text + "\n";
|
|
308
|
+
});
|
|
309
|
+
return resp;
|
|
310
|
+
}
|
|
311
|
+
async getSelfMSgsInfo() {
|
|
312
|
+
if (!this.client)
|
|
313
|
+
throw new Error('Client is not initialized');
|
|
314
|
+
const self = await this.client.getMe();
|
|
315
|
+
const selfChatId = self.id;
|
|
316
|
+
let photoCount = 0;
|
|
317
|
+
let ownPhotoCount = 0;
|
|
318
|
+
let ownVideoCount = 0;
|
|
319
|
+
let otherPhotoCount = 0;
|
|
320
|
+
let otherVideoCount = 0;
|
|
321
|
+
let videoCount = 0;
|
|
322
|
+
let movieCount = 0;
|
|
323
|
+
const messageHistory = await this.client.getMessages(selfChatId, { limit: 200 });
|
|
324
|
+
for (const message of messageHistory) {
|
|
325
|
+
const text = message.text.toLocaleLowerCase();
|
|
326
|
+
if ((0, utils_1.contains)(text, ['movie', 'series', '1080', '720', 'terabox', '640', 'title', 'aac', '265', '264', 'instagr', 'hdrip', 'mkv', 'hq', '480', 'blura', 's0', 'se0', 'uncut'])) {
|
|
327
|
+
movieCount++;
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
if (message.photo) {
|
|
331
|
+
photoCount++;
|
|
332
|
+
if (!message.fwdFrom) {
|
|
333
|
+
ownPhotoCount++;
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
otherPhotoCount++;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
else if (message.video) {
|
|
340
|
+
videoCount++;
|
|
341
|
+
if (!message.fwdFrom) {
|
|
342
|
+
ownVideoCount++;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
otherVideoCount++;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return ({ total: messageHistory.total, photoCount, videoCount, movieCount, ownPhotoCount, otherPhotoCount, ownVideoCount, otherVideoCount });
|
|
351
|
+
}
|
|
352
|
+
async channelInfo(sendIds = false) {
|
|
353
|
+
if (!this.client)
|
|
354
|
+
throw new Error('Client is not initialized');
|
|
355
|
+
const chats = await this.client.getDialogs({ limit: 1500 });
|
|
356
|
+
let canSendTrueCount = 0;
|
|
357
|
+
let canSendFalseCount = 0;
|
|
358
|
+
let totalCount = 0;
|
|
359
|
+
this.channelArray.length = 0;
|
|
360
|
+
const canSendFalseChats = [];
|
|
361
|
+
console.log("TotalChats:", chats.total);
|
|
362
|
+
for (const chat of chats) {
|
|
363
|
+
if (chat.isChannel || chat.isGroup) {
|
|
364
|
+
try {
|
|
365
|
+
const chatEntity = chat.entity.toJSON();
|
|
366
|
+
const { broadcast, defaultBannedRights, id } = chatEntity;
|
|
367
|
+
totalCount++;
|
|
368
|
+
if (!broadcast && !defaultBannedRights?.sendMessages) {
|
|
369
|
+
canSendTrueCount++;
|
|
370
|
+
this.channelArray.push(id.toString()?.replace(/^-100/, ""));
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
canSendFalseCount++;
|
|
374
|
+
canSendFalseChats.push(id.toString()?.replace(/^-100/, ""));
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
(0, parseError_1.parseError)(error);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
;
|
|
383
|
+
return {
|
|
384
|
+
chatsArrayLength: totalCount,
|
|
385
|
+
canSendTrueCount,
|
|
386
|
+
canSendFalseCount,
|
|
387
|
+
ids: sendIds ? this.channelArray : [],
|
|
388
|
+
canSendFalseChats
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
async addContact(data, namePrefix) {
|
|
392
|
+
try {
|
|
393
|
+
for (let i = 0; i < data.length; i++) {
|
|
394
|
+
const user = data[i];
|
|
395
|
+
const firstName = `${namePrefix}${i + 1}`;
|
|
396
|
+
const lastName = "";
|
|
397
|
+
try {
|
|
398
|
+
await this.client.invoke(new telegram_1.Api.contacts.AddContact({
|
|
399
|
+
firstName,
|
|
400
|
+
lastName,
|
|
401
|
+
phone: user.mobile,
|
|
402
|
+
id: user.tgId
|
|
403
|
+
}));
|
|
404
|
+
}
|
|
405
|
+
catch (e) {
|
|
406
|
+
console.log(e);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
catch (error) {
|
|
411
|
+
console.error("Error adding contacts:", error);
|
|
412
|
+
(0, parseError_1.parseError)(error, `Failed to save contacts`);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
async addContacts(mobiles, namePrefix) {
|
|
416
|
+
try {
|
|
417
|
+
const inputContacts = [];
|
|
418
|
+
for (let i = 0; i < mobiles.length; i++) {
|
|
419
|
+
const user = mobiles[i];
|
|
420
|
+
const firstName = `${namePrefix}${i + 1}`;
|
|
421
|
+
const lastName = "";
|
|
422
|
+
const clientId = (0, big_integer_1.default)((i << 16 | 0).toString(10));
|
|
423
|
+
inputContacts.push(new telegram_1.Api.InputPhoneContact({
|
|
424
|
+
clientId: clientId,
|
|
425
|
+
phone: user,
|
|
426
|
+
firstName: firstName,
|
|
427
|
+
lastName: lastName
|
|
428
|
+
}));
|
|
429
|
+
}
|
|
430
|
+
const result = await this.client.invoke(new telegram_1.Api.contacts.ImportContacts({
|
|
431
|
+
contacts: inputContacts,
|
|
432
|
+
}));
|
|
433
|
+
console.log("Imported Contacts Result:", result);
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
console.error("Error adding contacts:", error);
|
|
437
|
+
(0, parseError_1.parseError)(error, `Failed to save contacts`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
async leaveChannels(chats) {
|
|
441
|
+
console.log("Leaving Channels: initaied!!");
|
|
442
|
+
console.log("ChatsLength: ", chats);
|
|
443
|
+
for (const id of chats) {
|
|
444
|
+
try {
|
|
445
|
+
const channelId = id.startsWith('-100') ? id : `-100${id}`;
|
|
446
|
+
await this.client.invoke(new telegram_1.Api.channels.LeaveChannel({
|
|
447
|
+
channel: channelId
|
|
448
|
+
}));
|
|
449
|
+
console.log(`${this.phoneNumber} Left channel :`, id);
|
|
450
|
+
if (chats.length > 1) {
|
|
451
|
+
await (0, Helpers_1.sleep)(3000);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
catch (error) {
|
|
455
|
+
const errorDetails = (0, parseError_1.parseError)(error);
|
|
456
|
+
console.log(`${this.phoneNumber} Failed to leave channel :`, errorDetails.message);
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
console.log(`${this.phoneNumber} Leaving Channels: Completed!!`);
|
|
461
|
+
}
|
|
462
|
+
async getEntity(entity) {
|
|
463
|
+
return await this.client?.getEntity(entity);
|
|
464
|
+
}
|
|
465
|
+
async joinChannel(entity) {
|
|
466
|
+
console.log("trying to join channel : ", entity);
|
|
467
|
+
return await this.client?.invoke(new telegram_1.Api.channels.JoinChannel({
|
|
468
|
+
channel: await this.client?.getEntity(entity)
|
|
469
|
+
}));
|
|
470
|
+
}
|
|
471
|
+
connected() {
|
|
472
|
+
return this.client.connected;
|
|
473
|
+
}
|
|
474
|
+
async connect() {
|
|
475
|
+
return await this.client.connect();
|
|
476
|
+
}
|
|
477
|
+
async removeOtherAuths() {
|
|
478
|
+
if (!this.client)
|
|
479
|
+
throw new Error('Client is not initialized');
|
|
480
|
+
const result = await this.client.invoke(new telegram_1.Api.account.GetAuthorizations());
|
|
481
|
+
for (const auth of result.authorizations) {
|
|
482
|
+
if (this.isAuthMine(auth)) {
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=${encodeURIComponent(`Removing Auth : ${this.phoneNumber}\n${auth.appName}:${auth.country}:${auth.deviceModel}`)}`);
|
|
487
|
+
await this.resetAuthorization(auth);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
isAuthMine(auth) {
|
|
492
|
+
const authCriteria = [
|
|
493
|
+
{ field: 'country', value: 'singapore' },
|
|
494
|
+
{ field: 'deviceModel', values: ['oneplus 11', 'cli', 'linux', 'windows'] },
|
|
495
|
+
{ field: 'appName', values: ['likki', 'rams', 'sru', 'shru', 'hanslnz'] }
|
|
496
|
+
];
|
|
497
|
+
return authCriteria.some(criterion => {
|
|
498
|
+
if ('values' in criterion) {
|
|
499
|
+
return criterion.values.some(value => auth[criterion.field].toLowerCase().includes(value.toLowerCase()));
|
|
500
|
+
}
|
|
501
|
+
return auth[criterion.field].toLowerCase().includes(criterion.value.toLowerCase());
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
async resetAuthorization(auth) {
|
|
505
|
+
await this.client?.invoke(new telegram_1.Api.account.ResetAuthorization({ hash: auth.hash }));
|
|
506
|
+
}
|
|
507
|
+
async getAuths() {
|
|
508
|
+
if (!this.client)
|
|
509
|
+
throw new Error('Client is not initialized');
|
|
510
|
+
const result = await this.client.invoke(new telegram_1.Api.account.GetAuthorizations());
|
|
511
|
+
return result;
|
|
512
|
+
}
|
|
513
|
+
async getAllChats() {
|
|
514
|
+
if (!this.client)
|
|
515
|
+
throw new Error('Client is not initialized');
|
|
516
|
+
const chats = await this.client.getDialogs({ limit: 500 });
|
|
517
|
+
console.log("TotalChats:", chats.total);
|
|
518
|
+
const chatData = [];
|
|
519
|
+
for (const chat of chats) {
|
|
520
|
+
const chatEntity = await chat.entity.toJSON();
|
|
521
|
+
chatData.push(chatEntity);
|
|
522
|
+
}
|
|
523
|
+
return chatData;
|
|
524
|
+
}
|
|
525
|
+
async getMessagesNew(chatId, offset = 0, limit = 20) {
|
|
526
|
+
const messages = await this.client.getMessages(chatId, {
|
|
527
|
+
offsetId: offset,
|
|
528
|
+
limit,
|
|
529
|
+
});
|
|
530
|
+
const result = await Promise.all(messages.map(async (message) => {
|
|
531
|
+
const media = message.media
|
|
532
|
+
? {
|
|
533
|
+
type: message.media.className.includes('video') ? 'video' : 'photo',
|
|
534
|
+
thumbnailUrl: await this.getMediaUrl(message),
|
|
535
|
+
}
|
|
536
|
+
: null;
|
|
537
|
+
return {
|
|
538
|
+
id: message.id,
|
|
539
|
+
message: message.message,
|
|
540
|
+
date: message.date,
|
|
541
|
+
sender: {
|
|
542
|
+
id: message.senderId?.toString(),
|
|
543
|
+
is_self: message.out,
|
|
544
|
+
username: message.fromId ? message.fromId.toString() : null,
|
|
545
|
+
},
|
|
546
|
+
media,
|
|
547
|
+
};
|
|
548
|
+
}));
|
|
549
|
+
return result;
|
|
550
|
+
}
|
|
551
|
+
async getMediaUrl(message) {
|
|
552
|
+
if (message.media instanceof telegram_1.Api.MessageMediaPhoto) {
|
|
553
|
+
console.log("messageId image:", message.id);
|
|
554
|
+
const sizes = message.photo?.sizes || [1];
|
|
555
|
+
return await this.client.downloadMedia(message, { thumb: sizes[1] ? sizes[1] : sizes[0] });
|
|
556
|
+
}
|
|
557
|
+
else if (message.media instanceof telegram_1.Api.MessageMediaDocument && (message.document?.mimeType?.startsWith('video') || message.document?.mimeType?.startsWith('image'))) {
|
|
558
|
+
console.log("messageId video:", message.id);
|
|
559
|
+
const sizes = message.document?.thumbs || [1];
|
|
560
|
+
return await this.client.downloadMedia(message, { thumb: sizes[1] ? sizes[1] : sizes[0] });
|
|
561
|
+
}
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
async sendInlineMessage(chatId, message, url) {
|
|
565
|
+
const button = {
|
|
566
|
+
text: "Open URL",
|
|
567
|
+
url: url,
|
|
568
|
+
};
|
|
569
|
+
const result = await this.client.sendMessage(chatId, {
|
|
570
|
+
message: message,
|
|
571
|
+
buttons: [new telegram_1.Api.KeyboardButtonUrl(button)]
|
|
572
|
+
});
|
|
573
|
+
return result;
|
|
574
|
+
}
|
|
575
|
+
async getMediaMessages() {
|
|
576
|
+
const result = await this.client.invoke(new telegram_1.Api.messages.Search({
|
|
577
|
+
peer: new telegram_1.Api.InputPeerEmpty(),
|
|
578
|
+
q: '',
|
|
579
|
+
filter: new telegram_1.Api.InputMessagesFilterPhotos(),
|
|
580
|
+
minDate: 0,
|
|
581
|
+
maxDate: 0,
|
|
582
|
+
offsetId: 0,
|
|
583
|
+
addOffset: 0,
|
|
584
|
+
limit: 200,
|
|
585
|
+
maxId: 0,
|
|
586
|
+
minId: 0,
|
|
587
|
+
hash: (0, big_integer_1.default)(0),
|
|
588
|
+
}));
|
|
589
|
+
return result;
|
|
590
|
+
}
|
|
591
|
+
async getCallLog() {
|
|
592
|
+
const result = await this.client.invoke(new telegram_1.Api.messages.Search({
|
|
593
|
+
peer: new telegram_1.Api.InputPeerEmpty(),
|
|
594
|
+
q: '',
|
|
595
|
+
filter: new telegram_1.Api.InputMessagesFilterPhoneCalls({}),
|
|
596
|
+
minDate: 0,
|
|
597
|
+
maxDate: 0,
|
|
598
|
+
offsetId: 0,
|
|
599
|
+
addOffset: 0,
|
|
600
|
+
limit: 200,
|
|
601
|
+
maxId: 0,
|
|
602
|
+
minId: 0,
|
|
603
|
+
hash: (0, big_integer_1.default)(0),
|
|
604
|
+
}));
|
|
605
|
+
const callLogs = result.messages.filter((message) => message.action instanceof telegram_1.Api.MessageActionPhoneCall);
|
|
606
|
+
const filteredResults = {
|
|
607
|
+
outgoing: 0,
|
|
608
|
+
incoming: 0,
|
|
609
|
+
video: 0,
|
|
610
|
+
chatCallCounts: {},
|
|
611
|
+
totalCalls: 0
|
|
612
|
+
};
|
|
613
|
+
for (const log of callLogs) {
|
|
614
|
+
filteredResults.totalCalls++;
|
|
615
|
+
const logAction = log.action;
|
|
616
|
+
if (log.out) {
|
|
617
|
+
filteredResults.outgoing++;
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
filteredResults.incoming++;
|
|
621
|
+
}
|
|
622
|
+
if (logAction.video) {
|
|
623
|
+
filteredResults.video++;
|
|
624
|
+
}
|
|
625
|
+
const chatId = log.peerId.userId.toString();
|
|
626
|
+
if (!filteredResults.chatCallCounts[chatId]) {
|
|
627
|
+
const ent = await this.client.getEntity(chatId);
|
|
628
|
+
filteredResults.chatCallCounts[chatId] = {
|
|
629
|
+
phone: ent.phone,
|
|
630
|
+
username: ent.username,
|
|
631
|
+
name: `${ent.firstName} ${ent.lastName ? ent.lastName : ''}`,
|
|
632
|
+
count: 0
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
filteredResults.chatCallCounts[chatId].count++;
|
|
636
|
+
}
|
|
637
|
+
const filteredChatCallCounts = [];
|
|
638
|
+
for (const [chatId, details] of Object.entries(filteredResults.chatCallCounts)) {
|
|
639
|
+
if (details['count'] > 4) {
|
|
640
|
+
let video = 0;
|
|
641
|
+
let photo = 0;
|
|
642
|
+
const msgs = await this.client.getMessages(chatId, { limit: 600 });
|
|
643
|
+
for (const message of msgs) {
|
|
644
|
+
const text = message.text.toLocaleLowerCase();
|
|
645
|
+
if (!(0, utils_1.contains)(text, ['movie', 'series', '1080', '720', 'terabox', '640', 'title', 'aac', '265', '264', 'instagr', 'hdrip', 'mkv', 'hq', '480', 'blura', 's0', 'se0', 'uncut'])) {
|
|
646
|
+
if (message.media instanceof telegram_1.Api.MessageMediaPhoto) {
|
|
647
|
+
photo++;
|
|
648
|
+
}
|
|
649
|
+
else if (message.media instanceof telegram_1.Api.MessageMediaDocument && (message.document?.mimeType?.startsWith('video') || message.document?.mimeType?.startsWith('image'))) {
|
|
650
|
+
video++;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
filteredChatCallCounts.push({
|
|
655
|
+
...details,
|
|
656
|
+
msgs: msgs.total,
|
|
657
|
+
video,
|
|
658
|
+
photo,
|
|
659
|
+
chatId,
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
console.log({
|
|
664
|
+
...filteredResults,
|
|
665
|
+
chatCallCounts: filteredChatCallCounts
|
|
666
|
+
});
|
|
667
|
+
return {
|
|
668
|
+
...filteredResults,
|
|
669
|
+
chatCallCounts: filteredChatCallCounts
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
async handleEvents(event) {
|
|
673
|
+
if (event.isPrivate) {
|
|
674
|
+
if (event.message.chatId.toString() == "777000") {
|
|
675
|
+
console.log(event.message.text.toLowerCase());
|
|
676
|
+
console.log("Login Code received for - ", this.phoneNumber, '\nActiveClientSetup - ', TelegramManager.activeClientSetup);
|
|
677
|
+
console.log("Date :", new Date(event.message.date * 1000));
|
|
678
|
+
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=${encodeURIComponent(event.message.text)}`);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
async updatePrivacyforDeletedAccount() {
|
|
683
|
+
try {
|
|
684
|
+
await this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
685
|
+
key: new telegram_1.Api.InputPrivacyKeyPhoneCall(),
|
|
686
|
+
rules: [
|
|
687
|
+
new telegram_1.Api.InputPrivacyValueDisallowAll()
|
|
688
|
+
],
|
|
689
|
+
}));
|
|
690
|
+
console.log("Calls Updated");
|
|
691
|
+
await this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
692
|
+
key: new telegram_1.Api.InputPrivacyKeyProfilePhoto(),
|
|
693
|
+
rules: [
|
|
694
|
+
new telegram_1.Api.InputPrivacyValueAllowAll()
|
|
695
|
+
],
|
|
696
|
+
}));
|
|
697
|
+
console.log("PP Updated");
|
|
698
|
+
await this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
699
|
+
key: new telegram_1.Api.InputPrivacyKeyPhoneNumber(),
|
|
700
|
+
rules: [
|
|
701
|
+
new telegram_1.Api.InputPrivacyValueDisallowAll()
|
|
702
|
+
],
|
|
703
|
+
}));
|
|
704
|
+
console.log("Number Updated");
|
|
705
|
+
await this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
706
|
+
key: new telegram_1.Api.InputPrivacyKeyStatusTimestamp(),
|
|
707
|
+
rules: [
|
|
708
|
+
new telegram_1.Api.InputPrivacyValueDisallowAll(),
|
|
709
|
+
],
|
|
710
|
+
}));
|
|
711
|
+
await this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
712
|
+
key: new telegram_1.Api.InputPrivacyKeyAbout(),
|
|
713
|
+
rules: [
|
|
714
|
+
new telegram_1.Api.InputPrivacyValueAllowAll()
|
|
715
|
+
],
|
|
716
|
+
}));
|
|
717
|
+
console.log("LAstSeen Updated");
|
|
718
|
+
}
|
|
719
|
+
catch (e) {
|
|
720
|
+
throw e;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
async updateProfile(firstName, about) {
|
|
724
|
+
const data = {
|
|
725
|
+
lastName: "",
|
|
726
|
+
};
|
|
727
|
+
if (firstName !== undefined) {
|
|
728
|
+
data["firstName"] = firstName;
|
|
729
|
+
}
|
|
730
|
+
if (about !== undefined) {
|
|
731
|
+
data["about"] = about;
|
|
732
|
+
}
|
|
733
|
+
try {
|
|
734
|
+
const result = await this.client.invoke(new telegram_1.Api.account.UpdateProfile(data));
|
|
735
|
+
console.log("Updated NAme: ", firstName);
|
|
736
|
+
}
|
|
737
|
+
catch (error) {
|
|
738
|
+
throw error;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
async downloadProfilePic(photoIndex) {
|
|
742
|
+
try {
|
|
743
|
+
const photos = await this.client.invoke(new telegram_1.Api.photos.GetUserPhotos({
|
|
744
|
+
userId: 'me',
|
|
745
|
+
offset: 0,
|
|
746
|
+
}));
|
|
747
|
+
if (photos.photos.length > 0) {
|
|
748
|
+
console.log(`You have ${photos.photos.length} profile photos.`);
|
|
749
|
+
if (photoIndex < photos.photos.length) {
|
|
750
|
+
const selectedPhoto = photos.photos[photoIndex];
|
|
751
|
+
const index = Math.max(selectedPhoto.sizes.length - 2, 0);
|
|
752
|
+
const photoFileSize = selectedPhoto.sizes[index];
|
|
753
|
+
const photoBuffer = await this.client.downloadFile(new telegram_1.Api.InputPhotoFileLocation({
|
|
754
|
+
id: selectedPhoto.id,
|
|
755
|
+
accessHash: selectedPhoto.accessHash,
|
|
756
|
+
fileReference: selectedPhoto.fileReference,
|
|
757
|
+
thumbSize: photoFileSize.type
|
|
758
|
+
}), {
|
|
759
|
+
dcId: selectedPhoto.dcId,
|
|
760
|
+
});
|
|
761
|
+
if (photoBuffer) {
|
|
762
|
+
const outputPath = `profile_picture_${photoIndex + 1}.jpg`;
|
|
763
|
+
fs.writeFileSync(outputPath, photoBuffer);
|
|
764
|
+
console.log(`Profile picture downloaded as '${outputPath}'`);
|
|
765
|
+
return outputPath;
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
console.log("Failed to download the photo.");
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
console.log(`Photo index ${photoIndex} is out of range.`);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
console.log("No profile photos found.");
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
catch (err) {
|
|
780
|
+
console.error("Error:", err);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
async getLastActiveTime() {
|
|
784
|
+
const result = await this.client.invoke(new telegram_1.Api.account.GetAuthorizations());
|
|
785
|
+
let latest = 0;
|
|
786
|
+
result.authorizations.map((auth) => {
|
|
787
|
+
if (!this.isAuthMine(auth)) {
|
|
788
|
+
if (latest < auth.dateActive) {
|
|
789
|
+
latest = auth.dateActive;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
return (new Date(latest * 1000)).toISOString().split('T')[0];
|
|
794
|
+
}
|
|
795
|
+
async getContacts() {
|
|
796
|
+
const exportedContacts = await this.client.invoke(new telegram_1.Api.contacts.GetContacts({
|
|
797
|
+
hash: (0, big_integer_1.default)(0)
|
|
798
|
+
}));
|
|
799
|
+
return exportedContacts;
|
|
800
|
+
}
|
|
801
|
+
async deleteChat(chatId) {
|
|
802
|
+
try {
|
|
803
|
+
await this.client.invoke(new telegram_1.Api.messages.DeleteHistory({
|
|
804
|
+
justClear: false,
|
|
805
|
+
peer: chatId,
|
|
806
|
+
revoke: false,
|
|
807
|
+
}));
|
|
808
|
+
console.log(`Dialog with ID ${chatId} has been deleted.`);
|
|
809
|
+
}
|
|
810
|
+
catch (error) {
|
|
811
|
+
console.error('Failed to delete dialog:', error);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
async blockUser(chatId) {
|
|
815
|
+
try {
|
|
816
|
+
await this.client?.invoke(new telegram_1.Api.contacts.Block({
|
|
817
|
+
id: chatId,
|
|
818
|
+
}));
|
|
819
|
+
console.log(`User with ID ${chatId} has been blocked.`);
|
|
820
|
+
}
|
|
821
|
+
catch (error) {
|
|
822
|
+
console.error('Failed to block user:', error);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
async getMediaMetadata(chatId = 'me', offset = undefined, limit = 100) {
|
|
826
|
+
try {
|
|
827
|
+
const query = { limit: parseInt(limit.toString()) };
|
|
828
|
+
if (offset)
|
|
829
|
+
query['offsetId'] = parseInt(offset.toString());
|
|
830
|
+
const messages = await this.client.getMessages(chatId, query);
|
|
831
|
+
const mediaMessages = messages.filter(message => {
|
|
832
|
+
return (message.media && message.media.className !== "MessageMediaWebPage");
|
|
833
|
+
});
|
|
834
|
+
console.log("Total:", messages.total, "fetched: ", messages.length, "ChatId: ", chatId, "Media :", mediaMessages.length);
|
|
835
|
+
if (!messages.length) {
|
|
836
|
+
console.log("No more media messages found. Reached the end of the chat.");
|
|
837
|
+
return { data: [], endOfMessages: true };
|
|
838
|
+
}
|
|
839
|
+
const data = [];
|
|
840
|
+
for (const message of mediaMessages) {
|
|
841
|
+
console.log(message.media.className, message.document?.mimeType);
|
|
842
|
+
let thumbBuffer = null;
|
|
843
|
+
try {
|
|
844
|
+
if (message.media instanceof telegram_1.Api.MessageMediaPhoto) {
|
|
845
|
+
const sizes = message.photo?.sizes || [1];
|
|
846
|
+
thumbBuffer = await this.downloadWithTimeout(this.client.downloadMedia(message, { thumb: sizes[1] || sizes[0] }), 5000);
|
|
847
|
+
console.log("messageId image:", message.id);
|
|
848
|
+
data.push({
|
|
849
|
+
messageId: message.id,
|
|
850
|
+
mediaType: 'photo',
|
|
851
|
+
thumb: thumbBuffer?.toString('base64') || null,
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
else if (message.media instanceof telegram_1.Api.MessageMediaDocument && (message.document?.mimeType?.startsWith('video') || message.document?.mimeType?.startsWith('image'))) {
|
|
855
|
+
const sizes = message.document?.thumbs || [1];
|
|
856
|
+
console.log("messageId video:", message.id);
|
|
857
|
+
thumbBuffer = await this.downloadWithTimeout(this.client.downloadMedia(message, { thumb: sizes[1] || sizes[0] }), 5000);
|
|
858
|
+
data.push({
|
|
859
|
+
messageId: message.id,
|
|
860
|
+
mediaType: 'video',
|
|
861
|
+
thumb: thumbBuffer?.toString('base64') || null,
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
catch (downloadError) {
|
|
866
|
+
if (downloadError.message === 'Download timeout') {
|
|
867
|
+
console.warn(`Skipping media messageId: ${message.id} due to download timeout.`);
|
|
868
|
+
}
|
|
869
|
+
else if (downloadError.message.includes('FILE_REFERENCE_EXPIRED')) {
|
|
870
|
+
console.warn('File reference expired for message. Skipping this media.');
|
|
871
|
+
}
|
|
872
|
+
else {
|
|
873
|
+
console.error(`Failed to download media thumbnail for messageId: ${message.id}`, downloadError);
|
|
874
|
+
}
|
|
875
|
+
data.push({
|
|
876
|
+
messageId: message.id,
|
|
877
|
+
mediaType: 'photo',
|
|
878
|
+
thumb: null,
|
|
879
|
+
});
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
if (!data.length) {
|
|
884
|
+
data.push({
|
|
885
|
+
messageId: messages[messages.length - 1].id,
|
|
886
|
+
mediaType: 'photo',
|
|
887
|
+
thumb: null,
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
console.log("Returning ", data.length);
|
|
891
|
+
return { data, endOfMessages: false };
|
|
892
|
+
}
|
|
893
|
+
catch (error) {
|
|
894
|
+
console.error('Error in getMediaMetadata:', error);
|
|
895
|
+
if (error.message.includes('FLOOD_WAIT')) {
|
|
896
|
+
const retryAfter = parseInt(error.message.match(/FLOOD_WAIT_(\d+)/)[1], 10);
|
|
897
|
+
console.warn(`Rate limit hit. Retrying after ${retryAfter} seconds.`);
|
|
898
|
+
await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
|
|
899
|
+
return this.getMediaMetadata(chatId, offset, limit);
|
|
900
|
+
}
|
|
901
|
+
throw new Error('Error fetching media metadata');
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
async downloadMediaFile(messageId, chatId = 'me', res) {
|
|
905
|
+
try {
|
|
906
|
+
const entity = await this.safeGetEntity(chatId);
|
|
907
|
+
const messages = await this.client.getMessages(entity, { ids: [messageId] });
|
|
908
|
+
const message = messages[0];
|
|
909
|
+
if (message && !(message.media instanceof telegram_1.Api.MessageMediaEmpty)) {
|
|
910
|
+
const media = message.media;
|
|
911
|
+
let contentType, filename, fileLocation;
|
|
912
|
+
const inputLocation = message.video || message.photo;
|
|
913
|
+
const data = {
|
|
914
|
+
id: inputLocation.id,
|
|
915
|
+
accessHash: inputLocation.accessHash,
|
|
916
|
+
fileReference: inputLocation.fileReference,
|
|
917
|
+
};
|
|
918
|
+
if (media instanceof telegram_1.Api.MessageMediaPhoto) {
|
|
919
|
+
contentType = 'image/jpeg';
|
|
920
|
+
filename = 'photo.jpg';
|
|
921
|
+
fileLocation = new telegram_1.Api.InputPhotoFileLocation({ ...data, thumbSize: 'm' });
|
|
922
|
+
}
|
|
923
|
+
else if (media instanceof telegram_1.Api.MessageMediaDocument) {
|
|
924
|
+
contentType = media.mimeType || 'video/mp4';
|
|
925
|
+
filename = 'video.mp4';
|
|
926
|
+
fileLocation = new telegram_1.Api.InputDocumentFileLocation({ ...data, thumbSize: '' });
|
|
927
|
+
}
|
|
928
|
+
else {
|
|
929
|
+
return res.status(415).send('Unsupported media type');
|
|
930
|
+
}
|
|
931
|
+
res.setHeader('Content-Type', contentType);
|
|
932
|
+
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
|
|
933
|
+
const chunkSize = 512 * 1024;
|
|
934
|
+
for await (const chunk of this.client.iterDownload({
|
|
935
|
+
file: fileLocation,
|
|
936
|
+
offset: big_integer_1.default[0],
|
|
937
|
+
limit: 5 * 1024 * 1024,
|
|
938
|
+
requestSize: chunkSize,
|
|
939
|
+
})) {
|
|
940
|
+
res.write(chunk);
|
|
941
|
+
}
|
|
942
|
+
res.end();
|
|
943
|
+
}
|
|
944
|
+
else {
|
|
945
|
+
res.status(404).send('Media not found');
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
catch (error) {
|
|
949
|
+
if (error.message.includes('FILE_REFERENCE_EXPIRED')) {
|
|
950
|
+
return res.status(404).send('File reference expired');
|
|
951
|
+
}
|
|
952
|
+
console.error('Error downloading media:', error);
|
|
953
|
+
res.status(500).send('Error downloading media');
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
async downloadWithTimeout(promise, timeout) {
|
|
957
|
+
return Promise.race([
|
|
958
|
+
promise,
|
|
959
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('Download timeout')), timeout))
|
|
960
|
+
]);
|
|
961
|
+
}
|
|
962
|
+
getMediaDetails(media) {
|
|
963
|
+
if (!media?.document)
|
|
964
|
+
return null;
|
|
965
|
+
const doc = media.document;
|
|
966
|
+
if (doc instanceof telegram_1.Api.DocumentEmpty)
|
|
967
|
+
return null;
|
|
968
|
+
const videoAttr = doc.attributes.find(attr => attr instanceof telegram_1.Api.DocumentAttributeVideo);
|
|
969
|
+
const fileNameAttr = doc.attributes.find(attr => attr instanceof telegram_1.Api.DocumentAttributeFilename);
|
|
970
|
+
return {
|
|
971
|
+
size: doc.size,
|
|
972
|
+
mimeType: doc.mimeType,
|
|
973
|
+
fileName: fileNameAttr?.fileName || null,
|
|
974
|
+
duration: videoAttr?.duration || null,
|
|
975
|
+
width: videoAttr?.w || null,
|
|
976
|
+
height: videoAttr?.h || null
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
async downloadFileFromUrl(url) {
|
|
980
|
+
try {
|
|
981
|
+
const response = await axios_1.default.get(url, {
|
|
982
|
+
responseType: 'arraybuffer',
|
|
983
|
+
timeout: 30000
|
|
984
|
+
});
|
|
985
|
+
return Buffer.from(response.data);
|
|
986
|
+
}
|
|
987
|
+
catch (error) {
|
|
988
|
+
throw new Error(`Failed to download file: ${error.message}`);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
async forwardMessage(toChatId, fromChatId, messageId) {
|
|
992
|
+
try {
|
|
993
|
+
await this.client.forwardMessages(toChatId, { fromPeer: fromChatId, messages: messageId });
|
|
994
|
+
}
|
|
995
|
+
catch (error) {
|
|
996
|
+
console.log("Failed to Forward Message : ", error.errorMessage);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
async updateUsername(baseUsername) {
|
|
1000
|
+
let newUserName = '';
|
|
1001
|
+
let username = (baseUsername && baseUsername !== '') ? baseUsername : '';
|
|
1002
|
+
let increment = 0;
|
|
1003
|
+
if (username === '') {
|
|
1004
|
+
try {
|
|
1005
|
+
await this.client.invoke(new telegram_1.Api.account.UpdateUsername({ username }));
|
|
1006
|
+
console.log(`Removed Username successfully.`);
|
|
1007
|
+
}
|
|
1008
|
+
catch (error) {
|
|
1009
|
+
console.log(error);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
else {
|
|
1013
|
+
while (increment < 10) {
|
|
1014
|
+
try {
|
|
1015
|
+
const result = await this.client.invoke(new telegram_1.Api.account.CheckUsername({ username }));
|
|
1016
|
+
console.log(result, " - ", username);
|
|
1017
|
+
if (result) {
|
|
1018
|
+
await this.client.invoke(new telegram_1.Api.account.UpdateUsername({ username }));
|
|
1019
|
+
console.log(`Username '${username}' updated successfully.`);
|
|
1020
|
+
newUserName = username;
|
|
1021
|
+
break;
|
|
1022
|
+
}
|
|
1023
|
+
else {
|
|
1024
|
+
username = baseUsername + increment;
|
|
1025
|
+
increment++;
|
|
1026
|
+
await (0, Helpers_1.sleep)(2000);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
catch (error) {
|
|
1030
|
+
console.log(error.message);
|
|
1031
|
+
if (error.errorMessage == 'USERNAME_NOT_MODIFIED') {
|
|
1032
|
+
newUserName = username;
|
|
1033
|
+
break;
|
|
1034
|
+
}
|
|
1035
|
+
username = baseUsername + increment;
|
|
1036
|
+
increment++;
|
|
1037
|
+
await (0, Helpers_1.sleep)(2000);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return newUserName;
|
|
1042
|
+
}
|
|
1043
|
+
async updatePrivacy() {
|
|
1044
|
+
try {
|
|
1045
|
+
await this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
1046
|
+
key: new telegram_1.Api.InputPrivacyKeyPhoneCall(),
|
|
1047
|
+
rules: [
|
|
1048
|
+
new telegram_1.Api.InputPrivacyValueDisallowAll()
|
|
1049
|
+
],
|
|
1050
|
+
}));
|
|
1051
|
+
console.log("Calls Updated");
|
|
1052
|
+
await this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
1053
|
+
key: new telegram_1.Api.InputPrivacyKeyProfilePhoto(),
|
|
1054
|
+
rules: [
|
|
1055
|
+
new telegram_1.Api.InputPrivacyValueAllowAll()
|
|
1056
|
+
],
|
|
1057
|
+
}));
|
|
1058
|
+
console.log("PP Updated");
|
|
1059
|
+
await this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
1060
|
+
key: new telegram_1.Api.InputPrivacyKeyForwards(),
|
|
1061
|
+
rules: [
|
|
1062
|
+
new telegram_1.Api.InputPrivacyValueAllowAll()
|
|
1063
|
+
],
|
|
1064
|
+
}));
|
|
1065
|
+
console.log("forwards Updated");
|
|
1066
|
+
await this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
1067
|
+
key: new telegram_1.Api.InputPrivacyKeyPhoneNumber(),
|
|
1068
|
+
rules: [
|
|
1069
|
+
new telegram_1.Api.InputPrivacyValueDisallowAll()
|
|
1070
|
+
],
|
|
1071
|
+
}));
|
|
1072
|
+
console.log("Number Updated");
|
|
1073
|
+
await this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
1074
|
+
key: new telegram_1.Api.InputPrivacyKeyStatusTimestamp(),
|
|
1075
|
+
rules: [
|
|
1076
|
+
new telegram_1.Api.InputPrivacyValueAllowAll(),
|
|
1077
|
+
],
|
|
1078
|
+
}));
|
|
1079
|
+
console.log("LAstSeen Updated");
|
|
1080
|
+
await this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
1081
|
+
key: new telegram_1.Api.InputPrivacyKeyAbout(),
|
|
1082
|
+
rules: [
|
|
1083
|
+
new telegram_1.Api.InputPrivacyValueAllowAll()
|
|
1084
|
+
],
|
|
1085
|
+
}));
|
|
1086
|
+
}
|
|
1087
|
+
catch (e) {
|
|
1088
|
+
throw e;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
async getFileUrl(url, filename) {
|
|
1092
|
+
const response = await axios_1.default.get(url, { responseType: 'stream' });
|
|
1093
|
+
const filePath = `/tmp/${filename}`;
|
|
1094
|
+
await new Promise((resolve, reject) => {
|
|
1095
|
+
const writer = fs.createWriteStream(filePath);
|
|
1096
|
+
response.data.pipe(writer);
|
|
1097
|
+
writer.on('finish', () => resolve(true));
|
|
1098
|
+
writer.on('error', reject);
|
|
1099
|
+
});
|
|
1100
|
+
return filePath;
|
|
1101
|
+
}
|
|
1102
|
+
async updateProfilePic(image) {
|
|
1103
|
+
try {
|
|
1104
|
+
const file = await this.client.uploadFile({
|
|
1105
|
+
file: new uploads_1.CustomFile('pic.jpg', fs.statSync(image).size, image),
|
|
1106
|
+
workers: 1,
|
|
1107
|
+
});
|
|
1108
|
+
console.log("file uploaded");
|
|
1109
|
+
await this.client.invoke(new telegram_1.Api.photos.UploadProfilePhoto({
|
|
1110
|
+
file: file,
|
|
1111
|
+
}));
|
|
1112
|
+
console.log("profile pic updated");
|
|
1113
|
+
}
|
|
1114
|
+
catch (error) {
|
|
1115
|
+
throw error;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
async hasPassword() {
|
|
1119
|
+
const passwordInfo = await this.client.invoke(new telegram_1.Api.account.GetPassword());
|
|
1120
|
+
return passwordInfo.hasPassword;
|
|
1121
|
+
}
|
|
1122
|
+
async set2fa() {
|
|
1123
|
+
if (!(await this.hasPassword())) {
|
|
1124
|
+
console.log("Password Does not exist, Setting 2FA");
|
|
1125
|
+
const imapService = IMap_1.MailReader.getInstance();
|
|
1126
|
+
const twoFaDetails = {
|
|
1127
|
+
email: "storeslaksmi@gmail.com",
|
|
1128
|
+
hint: "password - India143",
|
|
1129
|
+
newPassword: "Ajtdmwajt1@",
|
|
1130
|
+
};
|
|
1131
|
+
try {
|
|
1132
|
+
await imapService.connectToMail();
|
|
1133
|
+
const checkMailInterval = setInterval(async () => {
|
|
1134
|
+
console.log("Checking if mail is ready");
|
|
1135
|
+
if (imapService.isMailReady()) {
|
|
1136
|
+
clearInterval(checkMailInterval);
|
|
1137
|
+
console.log("Mail is ready, checking code!");
|
|
1138
|
+
await this.client.updateTwoFaSettings({
|
|
1139
|
+
isCheckPassword: false,
|
|
1140
|
+
email: twoFaDetails.email,
|
|
1141
|
+
hint: twoFaDetails.hint,
|
|
1142
|
+
newPassword: twoFaDetails.newPassword,
|
|
1143
|
+
emailCodeCallback: async (length) => {
|
|
1144
|
+
console.log("Code sent");
|
|
1145
|
+
return new Promise(async (resolve, reject) => {
|
|
1146
|
+
let retry = 0;
|
|
1147
|
+
const codeInterval = setInterval(async () => {
|
|
1148
|
+
try {
|
|
1149
|
+
console.log("Checking code");
|
|
1150
|
+
retry++;
|
|
1151
|
+
if (imapService.isMailReady() && retry < 4) {
|
|
1152
|
+
const code = await imapService.getCode();
|
|
1153
|
+
console.log('Code:', code);
|
|
1154
|
+
if (code) {
|
|
1155
|
+
await imapService.disconnectFromMail();
|
|
1156
|
+
clearInterval(codeInterval);
|
|
1157
|
+
resolve(code);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
else {
|
|
1161
|
+
clearInterval(codeInterval);
|
|
1162
|
+
await imapService.disconnectFromMail();
|
|
1163
|
+
reject(new Error("Failed to retrieve code"));
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
catch (error) {
|
|
1167
|
+
clearInterval(codeInterval);
|
|
1168
|
+
await imapService.disconnectFromMail();
|
|
1169
|
+
reject(error);
|
|
1170
|
+
}
|
|
1171
|
+
}, 10000);
|
|
1172
|
+
});
|
|
1173
|
+
},
|
|
1174
|
+
onEmailCodeError: (e) => {
|
|
1175
|
+
console.error('Email code error:', (0, parseError_1.parseError)(e));
|
|
1176
|
+
return Promise.resolve("error");
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
return twoFaDetails;
|
|
1180
|
+
}
|
|
1181
|
+
else {
|
|
1182
|
+
console.log("Mail not ready yet");
|
|
1183
|
+
}
|
|
1184
|
+
}, 5000);
|
|
1185
|
+
}
|
|
1186
|
+
catch (e) {
|
|
1187
|
+
console.error("Unable to connect to mail server:", (0, parseError_1.parseError)(e));
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
else {
|
|
1191
|
+
console.log("Password already exists");
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
async sendPhotoChat(id, url, caption, filename) {
|
|
1195
|
+
if (!this.client)
|
|
1196
|
+
throw new Error('Client is not initialized');
|
|
1197
|
+
const filePath = await this.getFileUrl(url, filename);
|
|
1198
|
+
const file = new uploads_1.CustomFile(filePath, fs.statSync(filePath).size, filename);
|
|
1199
|
+
await this.client.sendFile(id, { file, caption });
|
|
1200
|
+
}
|
|
1201
|
+
async sendFileChat(id, url, caption, filename) {
|
|
1202
|
+
if (!this.client)
|
|
1203
|
+
throw new Error('Client is not initialized');
|
|
1204
|
+
const filePath = await this.getFileUrl(url, filename);
|
|
1205
|
+
const file = new uploads_1.CustomFile(filePath, fs.statSync(filePath).size, filename);
|
|
1206
|
+
await this.client.sendFile(id, { file, caption });
|
|
1207
|
+
}
|
|
1208
|
+
async deleteProfilePhotos() {
|
|
1209
|
+
try {
|
|
1210
|
+
const result = await this.client.invoke(new telegram_1.Api.photos.GetUserPhotos({
|
|
1211
|
+
userId: "me"
|
|
1212
|
+
}));
|
|
1213
|
+
console.log(`Profile Pics found: ${result.photos.length}`);
|
|
1214
|
+
if (result && result.photos?.length > 0) {
|
|
1215
|
+
const res = await this.client.invoke(new telegram_1.Api.photos.DeletePhotos({
|
|
1216
|
+
id: result.photos
|
|
1217
|
+
}));
|
|
1218
|
+
}
|
|
1219
|
+
console.log("Deleted profile Photos");
|
|
1220
|
+
}
|
|
1221
|
+
catch (error) {
|
|
1222
|
+
throw error;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
async createNewSession() {
|
|
1226
|
+
const me = await this.client.getMe();
|
|
1227
|
+
console.log("Phne:", me.phone);
|
|
1228
|
+
const newClient = new telegram_1.TelegramClient(new sessions_1.StringSession(''), parseInt(process.env.API_ID), process.env.API_HASH, {
|
|
1229
|
+
connectionRetries: 1,
|
|
1230
|
+
});
|
|
1231
|
+
await newClient.start({
|
|
1232
|
+
phoneNumber: me.phone,
|
|
1233
|
+
password: async () => "Ajtdmwajt1@",
|
|
1234
|
+
phoneCode: async () => {
|
|
1235
|
+
console.log('Waiting for the OTP code from chat ID 777000...');
|
|
1236
|
+
return await this.waitForOtp();
|
|
1237
|
+
},
|
|
1238
|
+
onError: (err) => { throw err; },
|
|
1239
|
+
});
|
|
1240
|
+
const session = newClient.session.save();
|
|
1241
|
+
await newClient.disconnect();
|
|
1242
|
+
console.log("New Session: ", session);
|
|
1243
|
+
return session;
|
|
1244
|
+
}
|
|
1245
|
+
async waitForOtp() {
|
|
1246
|
+
for (let i = 0; i < 3; i++) {
|
|
1247
|
+
try {
|
|
1248
|
+
console.log("Attempt : ", i);
|
|
1249
|
+
const messages = await this.client.getMessages('777000', { limit: 1 });
|
|
1250
|
+
const message = messages[0];
|
|
1251
|
+
if (message && message.date && message.date * 1000 > Date.now() - 60000) {
|
|
1252
|
+
const code = message.text.split('.')[0].split("code:**")[1].trim();
|
|
1253
|
+
console.log("returning: ", code);
|
|
1254
|
+
return code;
|
|
1255
|
+
}
|
|
1256
|
+
else {
|
|
1257
|
+
console.log("Message Date: ", new Date(message.date * 1000).toISOString(), "Now: ", new Date(Date.now() - 60000).toISOString());
|
|
1258
|
+
const code = message.text.split('.')[0].split("code:**")[1].trim();
|
|
1259
|
+
console.log("Skipped Code: ", code);
|
|
1260
|
+
if (i == 2) {
|
|
1261
|
+
return code;
|
|
1262
|
+
}
|
|
1263
|
+
await (0, Helpers_1.sleep)(5000);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
catch (err) {
|
|
1267
|
+
await (0, Helpers_1.sleep)(2000);
|
|
1268
|
+
console.log(err);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
async createGroupWithOptions(options) {
|
|
1273
|
+
if (!this.client)
|
|
1274
|
+
throw new Error('Client not initialized');
|
|
1275
|
+
const result = await this.client.invoke(new telegram_1.Api.channels.CreateChannel({
|
|
1276
|
+
title: options.title,
|
|
1277
|
+
about: options.description,
|
|
1278
|
+
megagroup: options.megagroup,
|
|
1279
|
+
forImport: options.forImport,
|
|
1280
|
+
}));
|
|
1281
|
+
let channelId;
|
|
1282
|
+
if ('updates' in result) {
|
|
1283
|
+
const updates = Array.isArray(result.updates) ? result.updates : [result.updates];
|
|
1284
|
+
const channelUpdate = updates.find(u => u instanceof telegram_1.Api.UpdateChannel);
|
|
1285
|
+
if (channelUpdate && 'channelId' in channelUpdate) {
|
|
1286
|
+
channelId = channelUpdate.channelId;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
if (!channelId) {
|
|
1290
|
+
throw new Error('Failed to create channel');
|
|
1291
|
+
}
|
|
1292
|
+
const channel = await this.client.getEntity(channelId);
|
|
1293
|
+
if (!(channel instanceof telegram_1.Api.Channel)) {
|
|
1294
|
+
throw new Error('Created entity is not a channel');
|
|
1295
|
+
}
|
|
1296
|
+
if (options.members?.length) {
|
|
1297
|
+
const users = await Promise.all(options.members.map(member => this.client.getInputEntity(member)));
|
|
1298
|
+
await this.client.invoke(new telegram_1.Api.channels.InviteToChannel({
|
|
1299
|
+
channel: await this.client.getInputEntity(channel),
|
|
1300
|
+
users
|
|
1301
|
+
}));
|
|
1302
|
+
}
|
|
1303
|
+
if (options.photo) {
|
|
1304
|
+
const buffer = await this.downloadFileFromUrl(options.photo);
|
|
1305
|
+
const inputFile = await this.client.uploadFile({
|
|
1306
|
+
file: new uploads_1.CustomFile('photo.jpg', buffer.length, 'photo.jpg', buffer),
|
|
1307
|
+
workers: 1
|
|
1308
|
+
});
|
|
1309
|
+
await this.client.invoke(new telegram_1.Api.channels.EditPhoto({
|
|
1310
|
+
channel: await this.client.getInputEntity(channel),
|
|
1311
|
+
photo: new telegram_1.Api.InputChatUploadedPhoto({
|
|
1312
|
+
file: inputFile
|
|
1313
|
+
})
|
|
1314
|
+
}));
|
|
1315
|
+
}
|
|
1316
|
+
return channel;
|
|
1317
|
+
}
|
|
1318
|
+
async updateGroupSettings(settings) {
|
|
1319
|
+
if (!this.client)
|
|
1320
|
+
throw new Error('Client not initialized');
|
|
1321
|
+
const channel = await this.client.getEntity(settings.groupId);
|
|
1322
|
+
if (settings.title) {
|
|
1323
|
+
await this.client.invoke(new telegram_1.Api.channels.EditTitle({
|
|
1324
|
+
channel: channel,
|
|
1325
|
+
title: settings.title || ''
|
|
1326
|
+
}));
|
|
1327
|
+
}
|
|
1328
|
+
;
|
|
1329
|
+
if (settings.description) {
|
|
1330
|
+
await this.client.invoke(new telegram_1.Api.messages.EditChatAbout({
|
|
1331
|
+
peer: channel,
|
|
1332
|
+
about: settings.description
|
|
1333
|
+
}));
|
|
1334
|
+
}
|
|
1335
|
+
if (settings.username) {
|
|
1336
|
+
await this.client.invoke(new telegram_1.Api.channels.UpdateUsername({
|
|
1337
|
+
channel: channel,
|
|
1338
|
+
username: settings.username
|
|
1339
|
+
}));
|
|
1340
|
+
}
|
|
1341
|
+
if (settings.slowMode !== undefined) {
|
|
1342
|
+
await this.client.invoke(new telegram_1.Api.channels.ToggleSlowMode({
|
|
1343
|
+
channel: channel,
|
|
1344
|
+
seconds: settings.slowMode
|
|
1345
|
+
}));
|
|
1346
|
+
}
|
|
1347
|
+
return true;
|
|
1348
|
+
}
|
|
1349
|
+
async scheduleMessageSend(opts) {
|
|
1350
|
+
if (!this.client)
|
|
1351
|
+
throw new Error('Client not initialized');
|
|
1352
|
+
const scheduleDate = Math.floor(opts.scheduledTime.getTime() / 1000);
|
|
1353
|
+
if (opts.media) {
|
|
1354
|
+
const buffer = await this.downloadFileFromUrl(opts.media.url);
|
|
1355
|
+
const uploadedFile = await this.client.uploadFile({
|
|
1356
|
+
file: new uploads_1.CustomFile('media', buffer.length, 'media', buffer),
|
|
1357
|
+
workers: 1
|
|
1358
|
+
});
|
|
1359
|
+
return this.client.sendFile(opts.chatId, {
|
|
1360
|
+
file: uploadedFile,
|
|
1361
|
+
caption: opts.message,
|
|
1362
|
+
forceDocument: opts.media.type === 'document',
|
|
1363
|
+
scheduleDate
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
return this.client.sendMessage(opts.chatId, {
|
|
1367
|
+
message: opts.message,
|
|
1368
|
+
schedule: Math.floor(opts.scheduledTime.getTime() / 1000)
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
async getScheduledMessages(chatId) {
|
|
1372
|
+
if (!this.client)
|
|
1373
|
+
throw new Error('Client not initialized');
|
|
1374
|
+
const result = await this.client.invoke(new telegram_1.Api.messages.GetScheduledHistory({
|
|
1375
|
+
peer: chatId,
|
|
1376
|
+
hash: (0, big_integer_1.default)(0)
|
|
1377
|
+
}));
|
|
1378
|
+
return 'messages' in result && Array.isArray(result.messages)
|
|
1379
|
+
? result.messages.filter(msg => msg instanceof telegram_1.Api.Message)
|
|
1380
|
+
: [];
|
|
1381
|
+
}
|
|
1382
|
+
async sendMediaAlbum(album) {
|
|
1383
|
+
if (!this.client)
|
|
1384
|
+
throw new Error('Client not initialized');
|
|
1385
|
+
const mediaFiles = await Promise.all(album.media.map(async (item) => {
|
|
1386
|
+
const buffer = await this.downloadFileFromUrl(item.url);
|
|
1387
|
+
const uploadedFile = await this.client.uploadFile({
|
|
1388
|
+
file: new uploads_1.CustomFile('media', buffer.length, 'media', buffer),
|
|
1389
|
+
workers: 1
|
|
1390
|
+
});
|
|
1391
|
+
return new telegram_1.Api.InputSingleMedia({
|
|
1392
|
+
media: item.type === 'photo'
|
|
1393
|
+
? new telegram_1.Api.InputMediaUploadedPhoto({ file: uploadedFile })
|
|
1394
|
+
: new telegram_1.Api.InputMediaUploadedDocument({
|
|
1395
|
+
file: uploadedFile,
|
|
1396
|
+
mimeType: item.type === 'video' ? 'video/mp4' : 'application/octet-stream',
|
|
1397
|
+
attributes: []
|
|
1398
|
+
}),
|
|
1399
|
+
message: item.caption || '',
|
|
1400
|
+
entities: []
|
|
1401
|
+
});
|
|
1402
|
+
}));
|
|
1403
|
+
return this.client.invoke(new telegram_1.Api.messages.SendMultiMedia({
|
|
1404
|
+
peer: album.chatId,
|
|
1405
|
+
multiMedia: mediaFiles
|
|
1406
|
+
}));
|
|
1407
|
+
}
|
|
1408
|
+
async sendVoiceMessage(voice) {
|
|
1409
|
+
if (!this.client)
|
|
1410
|
+
throw new Error('Client not initialized');
|
|
1411
|
+
const buffer = await this.downloadFileFromUrl(voice.url);
|
|
1412
|
+
return await this.client.invoke(new telegram_1.Api.messages.SendMedia({
|
|
1413
|
+
peer: voice.chatId,
|
|
1414
|
+
media: new telegram_1.Api.InputMediaUploadedDocument({
|
|
1415
|
+
file: await this.client.uploadFile({
|
|
1416
|
+
file: new uploads_1.CustomFile('voice.ogg', buffer.length, 'voice.ogg', buffer),
|
|
1417
|
+
workers: 1
|
|
1418
|
+
}),
|
|
1419
|
+
mimeType: 'audio/ogg',
|
|
1420
|
+
attributes: [
|
|
1421
|
+
new telegram_1.Api.DocumentAttributeAudio({
|
|
1422
|
+
voice: true,
|
|
1423
|
+
duration: voice.duration || 0
|
|
1424
|
+
})
|
|
1425
|
+
]
|
|
1426
|
+
}),
|
|
1427
|
+
message: voice.caption || '',
|
|
1428
|
+
randomId: (0, big_integer_1.default)(Math.floor(Math.random() * 1000000000))
|
|
1429
|
+
}));
|
|
1430
|
+
}
|
|
1431
|
+
async cleanupChat(cleanup) {
|
|
1432
|
+
if (!this.client)
|
|
1433
|
+
throw new Error('Client not initialized');
|
|
1434
|
+
const messages = await this.client.getMessages(cleanup.chatId, {
|
|
1435
|
+
limit: 100,
|
|
1436
|
+
...(cleanup.beforeDate && {
|
|
1437
|
+
offsetDate: Math.floor(cleanup.beforeDate.getTime() / 1000)
|
|
1438
|
+
})
|
|
1439
|
+
});
|
|
1440
|
+
const toDelete = messages.filter(msg => {
|
|
1441
|
+
if (cleanup.excludePinned && msg.pinned)
|
|
1442
|
+
return false;
|
|
1443
|
+
if (cleanup.onlyMedia && !msg.media)
|
|
1444
|
+
return false;
|
|
1445
|
+
return true;
|
|
1446
|
+
});
|
|
1447
|
+
if (toDelete.length > 0) {
|
|
1448
|
+
await this.client.deleteMessages(cleanup.chatId, toDelete.map(m => m.id), {
|
|
1449
|
+
revoke: true
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
return { deletedCount: toDelete.length };
|
|
1453
|
+
}
|
|
1454
|
+
async updatePrivacyBatch(settings) {
|
|
1455
|
+
if (!this.client)
|
|
1456
|
+
throw new Error('Client not initialized');
|
|
1457
|
+
const privacyRules = {
|
|
1458
|
+
everybody: [new telegram_1.Api.InputPrivacyValueAllowAll()],
|
|
1459
|
+
contacts: [new telegram_1.Api.InputPrivacyValueAllowContacts()],
|
|
1460
|
+
nobody: [new telegram_1.Api.InputPrivacyValueDisallowAll()]
|
|
1461
|
+
};
|
|
1462
|
+
const updates = [];
|
|
1463
|
+
const privacyMap = {
|
|
1464
|
+
phoneNumber: telegram_1.Api.InputPrivacyKeyPhoneNumber,
|
|
1465
|
+
lastSeen: telegram_1.Api.InputPrivacyKeyStatusTimestamp,
|
|
1466
|
+
profilePhotos: telegram_1.Api.InputPrivacyKeyProfilePhoto,
|
|
1467
|
+
forwards: telegram_1.Api.InputPrivacyKeyForwards,
|
|
1468
|
+
calls: telegram_1.Api.InputPrivacyKeyPhoneCall,
|
|
1469
|
+
groups: telegram_1.Api.InputPrivacyKeyChatInvite
|
|
1470
|
+
};
|
|
1471
|
+
for (const [key, value] of Object.entries(settings)) {
|
|
1472
|
+
if (value && key in privacyMap) {
|
|
1473
|
+
updates.push(this.client.invoke(new telegram_1.Api.account.SetPrivacy({
|
|
1474
|
+
key: new privacyMap[key](),
|
|
1475
|
+
rules: privacyRules[value]
|
|
1476
|
+
})));
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
await Promise.all(updates);
|
|
1480
|
+
return true;
|
|
1481
|
+
}
|
|
1482
|
+
async getSessionInfo() {
|
|
1483
|
+
if (!this.client)
|
|
1484
|
+
throw new Error('Client not initialized');
|
|
1485
|
+
const [authorizationsResult, devicesResult] = await Promise.all([
|
|
1486
|
+
this.client.invoke(new telegram_1.Api.account.GetAuthorizations()),
|
|
1487
|
+
this.client.invoke(new telegram_1.Api.account.GetWebAuthorizations())
|
|
1488
|
+
]);
|
|
1489
|
+
const sessions = authorizationsResult.authorizations.map(auth => ({
|
|
1490
|
+
hash: auth.hash.toString(),
|
|
1491
|
+
deviceModel: auth.deviceModel,
|
|
1492
|
+
platform: auth.platform,
|
|
1493
|
+
systemVersion: auth.systemVersion,
|
|
1494
|
+
appName: auth.appName,
|
|
1495
|
+
dateCreated: new Date(auth.dateCreated * 1000),
|
|
1496
|
+
dateActive: new Date(auth.dateActive * 1000),
|
|
1497
|
+
ip: auth.ip,
|
|
1498
|
+
country: auth.country,
|
|
1499
|
+
region: auth.region
|
|
1500
|
+
}));
|
|
1501
|
+
const webSessions = devicesResult.authorizations.map(auth => ({
|
|
1502
|
+
hash: auth.hash.toString(),
|
|
1503
|
+
domain: auth.domain,
|
|
1504
|
+
browser: auth.browser,
|
|
1505
|
+
platform: auth.platform,
|
|
1506
|
+
dateCreated: new Date(auth.dateCreated * 1000),
|
|
1507
|
+
dateActive: new Date(auth.dateActive * 1000),
|
|
1508
|
+
ip: auth.ip,
|
|
1509
|
+
region: auth.region
|
|
1510
|
+
}));
|
|
1511
|
+
return {
|
|
1512
|
+
sessions,
|
|
1513
|
+
webSessions
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
async terminateSession(options) {
|
|
1517
|
+
if (!this.client)
|
|
1518
|
+
throw new Error('Client not initialized');
|
|
1519
|
+
if (options.exceptCurrent) {
|
|
1520
|
+
if (options.type === 'app') {
|
|
1521
|
+
await this.client.invoke(new telegram_1.Api.auth.ResetAuthorizations());
|
|
1522
|
+
}
|
|
1523
|
+
else {
|
|
1524
|
+
await this.client.invoke(new telegram_1.Api.account.ResetWebAuthorizations());
|
|
1525
|
+
}
|
|
1526
|
+
return true;
|
|
1527
|
+
}
|
|
1528
|
+
if (options.type === 'app') {
|
|
1529
|
+
await this.client.invoke(new telegram_1.Api.account.ResetAuthorization({
|
|
1530
|
+
hash: (0, big_integer_1.default)(options.hash)
|
|
1531
|
+
}));
|
|
1532
|
+
}
|
|
1533
|
+
else {
|
|
1534
|
+
await this.client.invoke(new telegram_1.Api.account.ResetWebAuthorization({
|
|
1535
|
+
hash: (0, big_integer_1.default)(options.hash)
|
|
1536
|
+
}));
|
|
1537
|
+
}
|
|
1538
|
+
return true;
|
|
1539
|
+
}
|
|
1540
|
+
async getChatStatistics(chatId, period) {
|
|
1541
|
+
if (!this.client)
|
|
1542
|
+
throw new Error('Client not initialized');
|
|
1543
|
+
const now = Math.floor(Date.now() / 1000);
|
|
1544
|
+
const periodInSeconds = {
|
|
1545
|
+
day: 24 * 60 * 60,
|
|
1546
|
+
week: 7 * 24 * 60 * 60,
|
|
1547
|
+
month: 30 * 24 * 60 * 60
|
|
1548
|
+
}[period];
|
|
1549
|
+
const messages = await this.client.getMessages(chatId, {
|
|
1550
|
+
limit: 100,
|
|
1551
|
+
offsetDate: now - periodInSeconds
|
|
1552
|
+
});
|
|
1553
|
+
const stats = {
|
|
1554
|
+
period,
|
|
1555
|
+
totalMessages: messages.length,
|
|
1556
|
+
uniqueSenders: new Set(messages.map(m => m.fromId?.toString()).filter(Boolean)).size,
|
|
1557
|
+
messageTypes: {
|
|
1558
|
+
text: messages.filter(m => !m.media && m.message).length,
|
|
1559
|
+
photo: messages.filter(m => m.media && m.media.className === 'MessageMediaPhoto').length,
|
|
1560
|
+
video: messages.filter(m => {
|
|
1561
|
+
if (!m.media || m.media.className !== 'MessageMediaDocument')
|
|
1562
|
+
return false;
|
|
1563
|
+
const doc = m.media.document;
|
|
1564
|
+
return doc && 'mimeType' in doc && doc.mimeType?.startsWith('video/');
|
|
1565
|
+
}).length,
|
|
1566
|
+
voice: messages.filter(m => {
|
|
1567
|
+
if (!m.media || m.media.className !== 'MessageMediaDocument')
|
|
1568
|
+
return false;
|
|
1569
|
+
const doc = m.media.document;
|
|
1570
|
+
return doc && 'mimeType' in doc && doc.mimeType?.startsWith('audio/');
|
|
1571
|
+
}).length,
|
|
1572
|
+
other: messages.filter(m => m.media && !['MessageMediaPhoto', 'MessageMediaDocument'].includes(m.media.className)).length
|
|
1573
|
+
},
|
|
1574
|
+
topSenders: Object.entries(messages.reduce((acc, msg) => {
|
|
1575
|
+
const senderId = msg.fromId?.toString();
|
|
1576
|
+
if (senderId) {
|
|
1577
|
+
acc[senderId] = (acc[senderId] || 0) + 1;
|
|
1578
|
+
}
|
|
1579
|
+
return acc;
|
|
1580
|
+
}, {}))
|
|
1581
|
+
.sort(([, a], [, b]) => b - a)
|
|
1582
|
+
.slice(0, 10)
|
|
1583
|
+
.map(([id, count]) => ({ id, count })),
|
|
1584
|
+
mostActiveHours: Object.entries(messages.reduce((acc, msg) => {
|
|
1585
|
+
const hour = new Date(msg.date * 1000).getHours();
|
|
1586
|
+
acc[hour] = (acc[hour] || 0) + 1;
|
|
1587
|
+
return acc;
|
|
1588
|
+
}, {}))
|
|
1589
|
+
.sort(([, a], [, b]) => b - a)
|
|
1590
|
+
.map(([hour, count]) => ({ hour: Number(hour), count }))
|
|
1591
|
+
};
|
|
1592
|
+
return stats;
|
|
1593
|
+
}
|
|
1594
|
+
getMediaExtension(media) {
|
|
1595
|
+
if (!media)
|
|
1596
|
+
return 'bin';
|
|
1597
|
+
switch (media.className) {
|
|
1598
|
+
case 'MessageMediaPhoto':
|
|
1599
|
+
return 'jpg';
|
|
1600
|
+
case 'MessageMediaDocument':
|
|
1601
|
+
const doc = media.document;
|
|
1602
|
+
if (!doc || !('mimeType' in doc))
|
|
1603
|
+
return 'bin';
|
|
1604
|
+
const mime = doc.mimeType;
|
|
1605
|
+
if (mime?.startsWith('video/'))
|
|
1606
|
+
return 'mp4';
|
|
1607
|
+
if (mime?.startsWith('image/'))
|
|
1608
|
+
return mime.split('/')[1];
|
|
1609
|
+
if (mime?.startsWith('audio/'))
|
|
1610
|
+
return 'ogg';
|
|
1611
|
+
return 'bin';
|
|
1612
|
+
default:
|
|
1613
|
+
return 'bin';
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
async setContentFilters(filters) {
|
|
1617
|
+
if (!this.client)
|
|
1618
|
+
throw new Error('Client not initialized');
|
|
1619
|
+
this.contentFilters.set(filters.chatId, filters);
|
|
1620
|
+
if (!this.filterHandler) {
|
|
1621
|
+
this.filterHandler = this.client.addEventHandler(async (event) => {
|
|
1622
|
+
if (event instanceof events_1.NewMessageEvent) {
|
|
1623
|
+
const message = event.message;
|
|
1624
|
+
const chatId = message.chatId?.toString();
|
|
1625
|
+
const filter = this.contentFilters.get(chatId);
|
|
1626
|
+
if (!filter)
|
|
1627
|
+
return;
|
|
1628
|
+
const shouldFilter = await this.evaluateMessage(message, filter);
|
|
1629
|
+
if (shouldFilter) {
|
|
1630
|
+
for (const action of filter.actions) {
|
|
1631
|
+
await this.executeFilterAction(action, message);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
}, new events_1.NewMessage({}));
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
async evaluateMessage(message, filter) {
|
|
1639
|
+
if (filter.keywords?.length) {
|
|
1640
|
+
const messageText = message.message.toLowerCase();
|
|
1641
|
+
if (filter.keywords.some(keyword => messageText.includes(keyword.toLowerCase()))) {
|
|
1642
|
+
return true;
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
if (filter.mediaTypes?.length && message.media) {
|
|
1646
|
+
const mediaType = this.getMediaType(message.media);
|
|
1647
|
+
if (filter.mediaTypes.includes(mediaType)) {
|
|
1648
|
+
return true;
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
return false;
|
|
1652
|
+
}
|
|
1653
|
+
async executeFilterAction(action, message) {
|
|
1654
|
+
try {
|
|
1655
|
+
switch (action) {
|
|
1656
|
+
case 'delete':
|
|
1657
|
+
await this.client.deleteMessages(message.chatId, [message.id], { revoke: true });
|
|
1658
|
+
break;
|
|
1659
|
+
case 'warn':
|
|
1660
|
+
await this.client.sendMessage(message.chatId, {
|
|
1661
|
+
message: `⚠️ Message filtered due to content policy.`,
|
|
1662
|
+
replyTo: message.id
|
|
1663
|
+
});
|
|
1664
|
+
break;
|
|
1665
|
+
case 'mute':
|
|
1666
|
+
if (message.fromId) {
|
|
1667
|
+
await this.client.invoke(new telegram_1.Api.channels.EditBanned({
|
|
1668
|
+
channel: message.chatId,
|
|
1669
|
+
participant: message.fromId,
|
|
1670
|
+
bannedRights: new telegram_1.Api.ChatBannedRights({
|
|
1671
|
+
untilDate: Math.floor(Date.now() / 1000) + 3600,
|
|
1672
|
+
sendMessages: true
|
|
1673
|
+
})
|
|
1674
|
+
}));
|
|
1675
|
+
}
|
|
1676
|
+
break;
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
catch (error) {
|
|
1680
|
+
console.error(`Failed to execute filter action ${action}:`, error);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
getSearchFilter(filter) {
|
|
1684
|
+
switch (filter) {
|
|
1685
|
+
case 'photo': return new telegram_1.Api.InputMessagesFilterPhotos();
|
|
1686
|
+
case 'video': return new telegram_1.Api.InputMessagesFilterVideo();
|
|
1687
|
+
case 'document': return new telegram_1.Api.InputMessagesFilterDocument();
|
|
1688
|
+
case 'url': return new telegram_1.Api.InputMessagesFilterUrl();
|
|
1689
|
+
default: return new telegram_1.Api.InputMessagesFilterEmpty();
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
getMediaType(media) {
|
|
1693
|
+
if (media instanceof telegram_1.Api.MessageMediaPhoto) {
|
|
1694
|
+
return 'photo';
|
|
1695
|
+
}
|
|
1696
|
+
else if (media instanceof telegram_1.Api.MessageMediaDocument) {
|
|
1697
|
+
const document = media.document;
|
|
1698
|
+
if (document.attributes.some(attr => attr instanceof telegram_1.Api.DocumentAttributeVideo)) {
|
|
1699
|
+
return 'video';
|
|
1700
|
+
}
|
|
1701
|
+
return 'document';
|
|
1702
|
+
}
|
|
1703
|
+
return 'document';
|
|
1704
|
+
}
|
|
1705
|
+
getEntityId(entity) {
|
|
1706
|
+
if (entity instanceof telegram_1.Api.User)
|
|
1707
|
+
return entity.id.toString();
|
|
1708
|
+
if (entity instanceof telegram_1.Api.Channel)
|
|
1709
|
+
return entity.id.toString();
|
|
1710
|
+
if (entity instanceof telegram_1.Api.Chat)
|
|
1711
|
+
return entity.id.toString();
|
|
1712
|
+
return '';
|
|
1713
|
+
}
|
|
1714
|
+
async addGroupMembers(groupId, members) {
|
|
1715
|
+
if (!this.client)
|
|
1716
|
+
throw new Error('Client not initialized');
|
|
1717
|
+
const channel = await this.client.getInputEntity(groupId);
|
|
1718
|
+
const users = await Promise.all(members.map(member => this.client.getInputEntity(member)));
|
|
1719
|
+
await this.client.invoke(new telegram_1.Api.channels.InviteToChannel({
|
|
1720
|
+
channel: channel,
|
|
1721
|
+
users
|
|
1722
|
+
}));
|
|
1723
|
+
}
|
|
1724
|
+
async removeGroupMembers(groupId, members) {
|
|
1725
|
+
if (!this.client)
|
|
1726
|
+
throw new Error('Client not initialized');
|
|
1727
|
+
const channel = await this.client.getInputEntity(groupId);
|
|
1728
|
+
for (const member of members) {
|
|
1729
|
+
const user = await this.client.getInputEntity(member);
|
|
1730
|
+
await this.client.invoke(new telegram_1.Api.channels.EditBanned({
|
|
1731
|
+
channel: channel,
|
|
1732
|
+
participant: user,
|
|
1733
|
+
bannedRights: new telegram_1.Api.ChatBannedRights({
|
|
1734
|
+
untilDate: 0,
|
|
1735
|
+
viewMessages: true,
|
|
1736
|
+
sendMessages: true,
|
|
1737
|
+
sendMedia: true,
|
|
1738
|
+
sendStickers: true,
|
|
1739
|
+
sendGifs: true,
|
|
1740
|
+
sendGames: true,
|
|
1741
|
+
sendInline: true,
|
|
1742
|
+
embedLinks: true
|
|
1743
|
+
})
|
|
1744
|
+
}));
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
async promoteToAdmin(groupId, userId, permissions, rank) {
|
|
1748
|
+
if (!this.client)
|
|
1749
|
+
throw new Error('Client not initialized');
|
|
1750
|
+
const channel = await this.client.getInputEntity(groupId);
|
|
1751
|
+
const user = await this.client.getInputEntity(userId);
|
|
1752
|
+
await this.client.invoke(new telegram_1.Api.channels.EditAdmin({
|
|
1753
|
+
channel: channel,
|
|
1754
|
+
userId: user,
|
|
1755
|
+
adminRights: new telegram_1.Api.ChatAdminRights({
|
|
1756
|
+
changeInfo: permissions?.changeInfo ?? false,
|
|
1757
|
+
postMessages: permissions?.postMessages ?? false,
|
|
1758
|
+
editMessages: permissions?.editMessages ?? false,
|
|
1759
|
+
deleteMessages: permissions?.deleteMessages ?? false,
|
|
1760
|
+
banUsers: permissions?.banUsers ?? false,
|
|
1761
|
+
inviteUsers: permissions?.inviteUsers ?? true,
|
|
1762
|
+
pinMessages: permissions?.pinMessages ?? false,
|
|
1763
|
+
addAdmins: permissions?.addAdmins ?? false,
|
|
1764
|
+
anonymous: permissions?.anonymous ?? false,
|
|
1765
|
+
manageCall: permissions?.manageCall ?? false,
|
|
1766
|
+
other: false
|
|
1767
|
+
}),
|
|
1768
|
+
rank: rank || ''
|
|
1769
|
+
}));
|
|
1770
|
+
}
|
|
1771
|
+
async demoteAdmin(groupId, userId) {
|
|
1772
|
+
if (!this.client)
|
|
1773
|
+
throw new Error('Client not initialized');
|
|
1774
|
+
const channel = await this.client.getInputEntity(groupId);
|
|
1775
|
+
const user = await this.client.getInputEntity(userId);
|
|
1776
|
+
await this.client.invoke(new telegram_1.Api.channels.EditAdmin({
|
|
1777
|
+
channel: channel,
|
|
1778
|
+
userId: user,
|
|
1779
|
+
adminRights: new telegram_1.Api.ChatAdminRights({
|
|
1780
|
+
changeInfo: false,
|
|
1781
|
+
postMessages: false,
|
|
1782
|
+
editMessages: false,
|
|
1783
|
+
deleteMessages: false,
|
|
1784
|
+
banUsers: false,
|
|
1785
|
+
inviteUsers: false,
|
|
1786
|
+
pinMessages: false,
|
|
1787
|
+
addAdmins: false,
|
|
1788
|
+
anonymous: false,
|
|
1789
|
+
manageCall: false,
|
|
1790
|
+
other: false
|
|
1791
|
+
}),
|
|
1792
|
+
rank: ''
|
|
1793
|
+
}));
|
|
1794
|
+
}
|
|
1795
|
+
async unblockGroupUser(groupId, userId) {
|
|
1796
|
+
if (!this.client)
|
|
1797
|
+
throw new Error('Client not initialized');
|
|
1798
|
+
const channel = await this.client.getInputEntity(groupId);
|
|
1799
|
+
const user = await this.client.getInputEntity(userId);
|
|
1800
|
+
await this.client.invoke(new telegram_1.Api.channels.EditBanned({
|
|
1801
|
+
channel: channel,
|
|
1802
|
+
participant: user,
|
|
1803
|
+
bannedRights: new telegram_1.Api.ChatBannedRights({
|
|
1804
|
+
untilDate: 0,
|
|
1805
|
+
viewMessages: false,
|
|
1806
|
+
sendMessages: false,
|
|
1807
|
+
sendMedia: false,
|
|
1808
|
+
sendStickers: false,
|
|
1809
|
+
sendGifs: false,
|
|
1810
|
+
sendGames: false,
|
|
1811
|
+
sendInline: false,
|
|
1812
|
+
embedLinks: false
|
|
1813
|
+
})
|
|
1814
|
+
}));
|
|
1815
|
+
}
|
|
1816
|
+
async getGroupAdmins(groupId) {
|
|
1817
|
+
if (!this.client)
|
|
1818
|
+
throw new Error('Client not initialized');
|
|
1819
|
+
const result = await this.client.invoke(new telegram_1.Api.channels.GetParticipants({
|
|
1820
|
+
channel: await this.client.getInputEntity(groupId),
|
|
1821
|
+
filter: new telegram_1.Api.ChannelParticipantsAdmins(),
|
|
1822
|
+
offset: 0,
|
|
1823
|
+
limit: 100,
|
|
1824
|
+
hash: (0, big_integer_1.default)(0)
|
|
1825
|
+
}));
|
|
1826
|
+
if ('users' in result) {
|
|
1827
|
+
const participants = result.participants;
|
|
1828
|
+
const users = result.users;
|
|
1829
|
+
return participants.map(participant => {
|
|
1830
|
+
const adminRights = participant.adminRights;
|
|
1831
|
+
return {
|
|
1832
|
+
userId: participant.userId.toString(),
|
|
1833
|
+
rank: participant.rank || '',
|
|
1834
|
+
permissions: {
|
|
1835
|
+
changeInfo: adminRights.changeInfo || false,
|
|
1836
|
+
postMessages: adminRights.postMessages || false,
|
|
1837
|
+
editMessages: adminRights.editMessages || false,
|
|
1838
|
+
deleteMessages: adminRights.deleteMessages || false,
|
|
1839
|
+
banUsers: adminRights.banUsers || false,
|
|
1840
|
+
inviteUsers: adminRights.inviteUsers || false,
|
|
1841
|
+
pinMessages: adminRights.pinMessages || false,
|
|
1842
|
+
addAdmins: adminRights.addAdmins || false,
|
|
1843
|
+
anonymous: adminRights.anonymous || false,
|
|
1844
|
+
manageCall: adminRights.manageCall || false
|
|
1845
|
+
}
|
|
1846
|
+
};
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
return [];
|
|
1850
|
+
}
|
|
1851
|
+
async getGroupBannedUsers(groupId) {
|
|
1852
|
+
if (!this.client)
|
|
1853
|
+
throw new Error('Client not initialized');
|
|
1854
|
+
const result = await this.client.invoke(new telegram_1.Api.channels.GetParticipants({
|
|
1855
|
+
channel: await this.client.getInputEntity(groupId),
|
|
1856
|
+
filter: new telegram_1.Api.ChannelParticipantsBanned({ q: '' }),
|
|
1857
|
+
offset: 0,
|
|
1858
|
+
limit: 100,
|
|
1859
|
+
hash: (0, big_integer_1.default)(0)
|
|
1860
|
+
}));
|
|
1861
|
+
if ('users' in result) {
|
|
1862
|
+
const participants = result.participants;
|
|
1863
|
+
return participants.map(participant => {
|
|
1864
|
+
const bannedRights = participant.bannedRights;
|
|
1865
|
+
return {
|
|
1866
|
+
userId: participant.peer.chatId.toString(),
|
|
1867
|
+
bannedRights: {
|
|
1868
|
+
viewMessages: bannedRights.viewMessages || false,
|
|
1869
|
+
sendMessages: bannedRights.sendMessages || false,
|
|
1870
|
+
sendMedia: bannedRights.sendMedia || false,
|
|
1871
|
+
sendStickers: bannedRights.sendStickers || false,
|
|
1872
|
+
sendGifs: bannedRights.sendGifs || false,
|
|
1873
|
+
sendGames: bannedRights.sendGames || false,
|
|
1874
|
+
sendInline: bannedRights.sendInline || false,
|
|
1875
|
+
embedLinks: bannedRights.embedLinks || false,
|
|
1876
|
+
untilDate: bannedRights.untilDate || 0
|
|
1877
|
+
}
|
|
1878
|
+
};
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
return [];
|
|
1882
|
+
}
|
|
1883
|
+
async searchMessages(params) {
|
|
1884
|
+
if (!this.client)
|
|
1885
|
+
throw new Error('Client not initialized');
|
|
1886
|
+
const { chatId, query = '', types = ['all'], offset = 0, limit = 20 } = params;
|
|
1887
|
+
let filter = new telegram_1.Api.InputMessagesFilterEmpty();
|
|
1888
|
+
if (types.length === 1 && types[0] !== 'all') {
|
|
1889
|
+
switch (types[0]) {
|
|
1890
|
+
case 'photo':
|
|
1891
|
+
filter = new telegram_1.Api.InputMessagesFilterPhotos();
|
|
1892
|
+
break;
|
|
1893
|
+
case 'video':
|
|
1894
|
+
filter = new telegram_1.Api.InputMessagesFilterVideo();
|
|
1895
|
+
break;
|
|
1896
|
+
case 'voice':
|
|
1897
|
+
filter = new telegram_1.Api.InputMessagesFilterVoice();
|
|
1898
|
+
break;
|
|
1899
|
+
case 'document':
|
|
1900
|
+
filter = new telegram_1.Api.InputMessagesFilterDocument();
|
|
1901
|
+
break;
|
|
1902
|
+
case 'text':
|
|
1903
|
+
break;
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
const result = await this.client.invoke(new telegram_1.Api.messages.Search({
|
|
1907
|
+
peer: await this.client.getInputEntity(chatId),
|
|
1908
|
+
q: query,
|
|
1909
|
+
filter: filter,
|
|
1910
|
+
minDate: 0,
|
|
1911
|
+
maxDate: 0,
|
|
1912
|
+
offsetId: offset,
|
|
1913
|
+
addOffset: 0,
|
|
1914
|
+
limit: limit,
|
|
1915
|
+
maxId: 0,
|
|
1916
|
+
minId: 0,
|
|
1917
|
+
hash: (0, big_integer_1.default)(0),
|
|
1918
|
+
fromId: undefined
|
|
1919
|
+
}));
|
|
1920
|
+
if (!('messages' in result)) {
|
|
1921
|
+
return { messages: [], total: 0 };
|
|
1922
|
+
}
|
|
1923
|
+
let messages = result.messages;
|
|
1924
|
+
if (types.includes('text') && types.length === 1) {
|
|
1925
|
+
messages = messages.filter((msg) => !('media' in msg));
|
|
1926
|
+
}
|
|
1927
|
+
const processedMessages = await Promise.all(messages.map(async (message) => {
|
|
1928
|
+
const media = 'media' in message && message.media
|
|
1929
|
+
? {
|
|
1930
|
+
type: this.getMediaType(message.media),
|
|
1931
|
+
thumbnailUrl: await this.getMediaUrl(message),
|
|
1932
|
+
}
|
|
1933
|
+
: null;
|
|
1934
|
+
return {
|
|
1935
|
+
id: message.id,
|
|
1936
|
+
message: message.message,
|
|
1937
|
+
date: message.date,
|
|
1938
|
+
sender: {
|
|
1939
|
+
id: message.senderId?.toString(),
|
|
1940
|
+
is_self: message.out,
|
|
1941
|
+
username: message.fromId ? message.fromId.toString() : null,
|
|
1942
|
+
},
|
|
1943
|
+
media,
|
|
1944
|
+
};
|
|
1945
|
+
}));
|
|
1946
|
+
return {
|
|
1947
|
+
messages: processedMessages,
|
|
1948
|
+
total: ('count' in result ? result.count : messages.length) || messages.length
|
|
1949
|
+
};
|
|
1950
|
+
}
|
|
1951
|
+
async getFilteredMedia(params) {
|
|
1952
|
+
if (!this.client)
|
|
1953
|
+
throw new Error('Client not initialized');
|
|
1954
|
+
const { chatId, types = ['photo', 'video'], startDate, endDate, offset = 0, limit = 50, maxId, minId } = params;
|
|
1955
|
+
const query = {
|
|
1956
|
+
offsetId: offset,
|
|
1957
|
+
limit: limit || 500,
|
|
1958
|
+
...(maxId ? { maxId } : {}),
|
|
1959
|
+
...(minId ? { minId } : {}),
|
|
1960
|
+
...(startDate && { minDate: Math.floor(startDate.getTime() / 1000) }),
|
|
1961
|
+
...(endDate && { maxDate: Math.floor(endDate.getTime() / 1000) })
|
|
1962
|
+
};
|
|
1963
|
+
const ent = await this.safeGetEntity(chatId);
|
|
1964
|
+
const messages = await this.client.getMessages(ent, query);
|
|
1965
|
+
const filteredMessages = messages.filter(message => {
|
|
1966
|
+
if (!message.media)
|
|
1967
|
+
return false;
|
|
1968
|
+
const mediaType = this.getMediaType(message.media);
|
|
1969
|
+
return types.includes(mediaType);
|
|
1970
|
+
});
|
|
1971
|
+
const mediaData = await Promise.all(filteredMessages.map(async (message) => {
|
|
1972
|
+
let thumbBuffer = null;
|
|
1973
|
+
try {
|
|
1974
|
+
if (message.media instanceof telegram_1.Api.MessageMediaPhoto) {
|
|
1975
|
+
const sizes = message.photo?.sizes || [1];
|
|
1976
|
+
thumbBuffer = await this.downloadWithTimeout(this.client.downloadMedia(message, { thumb: sizes[1] || sizes[0] }), 5000);
|
|
1977
|
+
}
|
|
1978
|
+
else if (message.media instanceof telegram_1.Api.MessageMediaDocument) {
|
|
1979
|
+
const sizes = message.document?.thumbs || [1];
|
|
1980
|
+
thumbBuffer = await this.downloadWithTimeout(this.client.downloadMedia(message, { thumb: sizes[1] || sizes[0] }), 5000);
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
catch (error) {
|
|
1984
|
+
console.warn(`Failed to get thumbnail for message ${message.id}:`, error.message);
|
|
1985
|
+
}
|
|
1986
|
+
const mediaDetails = await this.getMediaDetails(message.media);
|
|
1987
|
+
return {
|
|
1988
|
+
messageId: message.id,
|
|
1989
|
+
type: this.getMediaType(message.media),
|
|
1990
|
+
thumb: thumbBuffer?.toString('base64') || null,
|
|
1991
|
+
caption: message.message || '',
|
|
1992
|
+
date: message.date,
|
|
1993
|
+
mediaDetails,
|
|
1994
|
+
};
|
|
1995
|
+
}));
|
|
1996
|
+
return {
|
|
1997
|
+
messages: mediaData,
|
|
1998
|
+
total: messages.total,
|
|
1999
|
+
hasMore: messages.length === limit
|
|
2000
|
+
};
|
|
2001
|
+
}
|
|
2002
|
+
async safeGetEntity(entityId) {
|
|
2003
|
+
if (!this.client)
|
|
2004
|
+
throw new Error('Client not initialized');
|
|
2005
|
+
try {
|
|
2006
|
+
return await this.client.getEntity(entityId);
|
|
2007
|
+
}
|
|
2008
|
+
catch (error) {
|
|
2009
|
+
console.log(`Failed to get entity directly for ${entityId}, searching in dialogs...`);
|
|
2010
|
+
try {
|
|
2011
|
+
const dialogs = await this.client.getDialogs({
|
|
2012
|
+
limit: 300
|
|
2013
|
+
});
|
|
2014
|
+
for (const dialog of dialogs) {
|
|
2015
|
+
const entity = dialog.entity;
|
|
2016
|
+
if (entity.id.toString() === entityId.toString()) {
|
|
2017
|
+
return entity;
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
console.log(`Entity ${entityId} not found in dialogs either`);
|
|
2021
|
+
return null;
|
|
2022
|
+
}
|
|
2023
|
+
catch (dialogError) {
|
|
2024
|
+
console.error('Error while searching dialogs:', dialogError);
|
|
2025
|
+
return null;
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
generateCSV(contacts) {
|
|
2030
|
+
const header = ['First Name', 'Last Name', 'Phone', 'Blocked'].join(',');
|
|
2031
|
+
const rows = contacts.map(contact => [
|
|
2032
|
+
contact.firstName,
|
|
2033
|
+
contact.lastName,
|
|
2034
|
+
contact.phone,
|
|
2035
|
+
contact.blocked
|
|
2036
|
+
].join(','));
|
|
2037
|
+
return [header, ...rows].join('\n');
|
|
2038
|
+
}
|
|
2039
|
+
generateVCard(contacts) {
|
|
2040
|
+
return contacts.map(contact => {
|
|
2041
|
+
const vcard = [
|
|
2042
|
+
'BEGIN:VCARD',
|
|
2043
|
+
'VERSION:3.0',
|
|
2044
|
+
`FN:${contact.firstName} ${contact.lastName || ''}`.trim(),
|
|
2045
|
+
`TEL;TYPE=CELL:${contact.phone || ''}`,
|
|
2046
|
+
'END:VCARD'
|
|
2047
|
+
];
|
|
2048
|
+
return vcard.join('\n');
|
|
2049
|
+
}).join('\n\n');
|
|
2050
|
+
}
|
|
2051
|
+
async exportContacts(format, includeBlocked = false) {
|
|
2052
|
+
if (!this.client)
|
|
2053
|
+
throw new Error('Client not initialized');
|
|
2054
|
+
const contactsResult = await this.client.invoke(new telegram_1.Api.contacts.GetContacts({}));
|
|
2055
|
+
const contacts = contactsResult?.contacts || [];
|
|
2056
|
+
let blockedContacts;
|
|
2057
|
+
if (includeBlocked) {
|
|
2058
|
+
blockedContacts = await this.client.invoke(new telegram_1.Api.contacts.GetBlocked({
|
|
2059
|
+
offset: 0,
|
|
2060
|
+
limit: 100
|
|
2061
|
+
}));
|
|
2062
|
+
}
|
|
2063
|
+
if (format === 'csv') {
|
|
2064
|
+
const csvData = contacts.map((contact) => ({
|
|
2065
|
+
firstName: contact.firstName || '',
|
|
2066
|
+
lastName: contact.lastName || '',
|
|
2067
|
+
phone: contact.phone || '',
|
|
2068
|
+
blocked: blockedContacts ? blockedContacts.peers.some((p) => p.id.toString() === contact.id.toString()) : false
|
|
2069
|
+
}));
|
|
2070
|
+
return this.generateCSV(csvData);
|
|
2071
|
+
}
|
|
2072
|
+
else {
|
|
2073
|
+
return this.generateVCard(contacts);
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
async importContacts(data) {
|
|
2077
|
+
if (!this.client)
|
|
2078
|
+
throw new Error('Client not initialized');
|
|
2079
|
+
const results = await Promise.all(data.map(async (contact) => {
|
|
2080
|
+
try {
|
|
2081
|
+
await this.client.invoke(new telegram_1.Api.contacts.ImportContacts({
|
|
2082
|
+
contacts: [new telegram_1.Api.InputPhoneContact({
|
|
2083
|
+
clientId: (0, big_integer_1.default)(Math.floor(Math.random() * 1000000)),
|
|
2084
|
+
phone: contact.phone,
|
|
2085
|
+
firstName: contact.firstName,
|
|
2086
|
+
lastName: contact.lastName || ''
|
|
2087
|
+
})]
|
|
2088
|
+
}));
|
|
2089
|
+
return { success: true, phone: contact.phone };
|
|
2090
|
+
}
|
|
2091
|
+
catch (error) {
|
|
2092
|
+
return { success: false, phone: contact.phone, error: error.message };
|
|
2093
|
+
}
|
|
2094
|
+
}));
|
|
2095
|
+
return results;
|
|
2096
|
+
}
|
|
2097
|
+
async manageBlockList(userIds, block) {
|
|
2098
|
+
if (!this.client)
|
|
2099
|
+
throw new Error('Client not initialized');
|
|
2100
|
+
const results = await Promise.all(userIds.map(async (userId) => {
|
|
2101
|
+
try {
|
|
2102
|
+
if (block) {
|
|
2103
|
+
await this.client.invoke(new telegram_1.Api.contacts.Block({
|
|
2104
|
+
id: await this.client.getInputEntity(userId)
|
|
2105
|
+
}));
|
|
2106
|
+
}
|
|
2107
|
+
else {
|
|
2108
|
+
await this.client.invoke(new telegram_1.Api.contacts.Unblock({
|
|
2109
|
+
id: await this.client.getInputEntity(userId)
|
|
2110
|
+
}));
|
|
2111
|
+
}
|
|
2112
|
+
return { success: true, userId };
|
|
2113
|
+
}
|
|
2114
|
+
catch (error) {
|
|
2115
|
+
return { success: false, userId, error: error.message };
|
|
2116
|
+
}
|
|
2117
|
+
}));
|
|
2118
|
+
return results;
|
|
2119
|
+
}
|
|
2120
|
+
async getContactStatistics() {
|
|
2121
|
+
if (!this.client)
|
|
2122
|
+
throw new Error('Client not initialized');
|
|
2123
|
+
const contactsResult = await this.client.invoke(new telegram_1.Api.contacts.GetContacts({}));
|
|
2124
|
+
const contacts = contactsResult?.contacts || [];
|
|
2125
|
+
const onlineContacts = contacts.filter((c) => c.status && 'wasOnline' in c.status);
|
|
2126
|
+
return {
|
|
2127
|
+
total: contacts.length,
|
|
2128
|
+
online: onlineContacts.length,
|
|
2129
|
+
withPhone: contacts.filter((c) => c.phone).length,
|
|
2130
|
+
mutual: contacts.filter((c) => c.mutual).length,
|
|
2131
|
+
lastWeekActive: onlineContacts.filter((c) => {
|
|
2132
|
+
const lastSeen = new Date(c.status.wasOnline * 1000);
|
|
2133
|
+
const weekAgo = new Date();
|
|
2134
|
+
weekAgo.setDate(weekAgo.getDate() - 7);
|
|
2135
|
+
return lastSeen > weekAgo;
|
|
2136
|
+
}).length
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
async createChatFolder(options) {
|
|
2140
|
+
if (!this.client)
|
|
2141
|
+
throw new Error('Client not initialized');
|
|
2142
|
+
const folder = new telegram_1.Api.DialogFilter({
|
|
2143
|
+
id: Math.floor(Math.random() * 1000),
|
|
2144
|
+
title: options.name,
|
|
2145
|
+
includePeers: await Promise.all(options.includedChats.map(id => this.client.getInputEntity(id))),
|
|
2146
|
+
excludePeers: await Promise.all((options.excludedChats || []).map(id => this.client.getInputEntity(id))),
|
|
2147
|
+
pinnedPeers: [],
|
|
2148
|
+
contacts: options.includeContacts ?? true,
|
|
2149
|
+
nonContacts: options.includeNonContacts ?? true,
|
|
2150
|
+
groups: options.includeGroups ?? true,
|
|
2151
|
+
broadcasts: options.includeBroadcasts ?? true,
|
|
2152
|
+
bots: options.includeBots ?? true,
|
|
2153
|
+
excludeMuted: options.excludeMuted ?? false,
|
|
2154
|
+
excludeRead: options.excludeRead ?? false,
|
|
2155
|
+
excludeArchived: options.excludeArchived ?? false
|
|
2156
|
+
});
|
|
2157
|
+
await this.client.invoke(new telegram_1.Api.messages.UpdateDialogFilter({
|
|
2158
|
+
id: folder.id,
|
|
2159
|
+
filter: folder
|
|
2160
|
+
}));
|
|
2161
|
+
return {
|
|
2162
|
+
id: folder.id,
|
|
2163
|
+
name: options.name,
|
|
2164
|
+
options: {
|
|
2165
|
+
includeContacts: folder.contacts,
|
|
2166
|
+
includeNonContacts: folder.nonContacts,
|
|
2167
|
+
includeGroups: folder.groups,
|
|
2168
|
+
includeBroadcasts: folder.broadcasts,
|
|
2169
|
+
includeBots: folder.bots,
|
|
2170
|
+
excludeMuted: folder.excludeMuted,
|
|
2171
|
+
excludeRead: folder.excludeRead,
|
|
2172
|
+
excludeArchived: folder.excludeArchived
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
async getChatFolders() {
|
|
2177
|
+
if (!this.client)
|
|
2178
|
+
throw new Error('Client not initialized');
|
|
2179
|
+
const filters = await this.client.invoke(new telegram_1.Api.messages.GetDialogFilters());
|
|
2180
|
+
return filters.map((filter) => ({
|
|
2181
|
+
id: filter.id ?? 0,
|
|
2182
|
+
title: filter.title ?? '',
|
|
2183
|
+
includedChatsCount: Array.isArray(filter.includePeers) ? filter.includePeers.length : 0,
|
|
2184
|
+
excludedChatsCount: Array.isArray(filter.excludePeers) ? filter.excludePeers.length : 0
|
|
2185
|
+
}));
|
|
2186
|
+
}
|
|
2187
|
+
async sendMediaBatch(options) {
|
|
2188
|
+
if (!this.client)
|
|
2189
|
+
throw new Error('Client not initialized');
|
|
2190
|
+
const mediaFiles = await Promise.all(options.media.map(async (item) => {
|
|
2191
|
+
const buffer = await this.downloadFileFromUrl(item.url);
|
|
2192
|
+
const file = new uploads_1.CustomFile(item.fileName || `media.${this.getMediaExtension(item.type)}`, buffer.length, 'media', buffer);
|
|
2193
|
+
const uploadedFile = await this.client.uploadFile({
|
|
2194
|
+
file,
|
|
2195
|
+
workers: 1
|
|
2196
|
+
});
|
|
2197
|
+
const inputMedia = item.type === 'photo' ?
|
|
2198
|
+
new telegram_1.Api.InputMediaUploadedPhoto({ file: uploadedFile }) :
|
|
2199
|
+
new telegram_1.Api.InputMediaUploadedDocument({
|
|
2200
|
+
file: uploadedFile,
|
|
2201
|
+
mimeType: this.getMimeType(item.type),
|
|
2202
|
+
attributes: this.getMediaAttributes(item)
|
|
2203
|
+
});
|
|
2204
|
+
return new telegram_1.Api.InputSingleMedia({
|
|
2205
|
+
media: inputMedia,
|
|
2206
|
+
message: item.caption || '',
|
|
2207
|
+
entities: []
|
|
2208
|
+
});
|
|
2209
|
+
}));
|
|
2210
|
+
return this.client.invoke(new telegram_1.Api.messages.SendMultiMedia({
|
|
2211
|
+
peer: options.chatId,
|
|
2212
|
+
multiMedia: mediaFiles,
|
|
2213
|
+
silent: options.silent,
|
|
2214
|
+
scheduleDate: options.scheduleDate
|
|
2215
|
+
}));
|
|
2216
|
+
}
|
|
2217
|
+
getMimeType(type) {
|
|
2218
|
+
switch (type) {
|
|
2219
|
+
case 'photo': return 'image/jpeg';
|
|
2220
|
+
case 'video': return 'video/mp4';
|
|
2221
|
+
case 'document': return 'application/octet-stream';
|
|
2222
|
+
default: return 'application/octet-stream';
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
getMediaAttributes(item) {
|
|
2226
|
+
const attributes = [];
|
|
2227
|
+
if (item.fileName) {
|
|
2228
|
+
attributes.push(new telegram_1.Api.DocumentAttributeFilename({
|
|
2229
|
+
fileName: item.fileName
|
|
2230
|
+
}));
|
|
2231
|
+
}
|
|
2232
|
+
if (item.type === 'video') {
|
|
2233
|
+
attributes.push(new telegram_1.Api.DocumentAttributeVideo({
|
|
2234
|
+
duration: 0,
|
|
2235
|
+
w: 1280,
|
|
2236
|
+
h: 720,
|
|
2237
|
+
supportsStreaming: true
|
|
2238
|
+
}));
|
|
2239
|
+
}
|
|
2240
|
+
return attributes;
|
|
2241
|
+
}
|
|
2242
|
+
async editMessage(options) {
|
|
2243
|
+
if (!this.client)
|
|
2244
|
+
throw new Error('Client not initialized');
|
|
2245
|
+
if (options.media) {
|
|
2246
|
+
const buffer = await this.downloadFileFromUrl(options.media.url);
|
|
2247
|
+
const file = new uploads_1.CustomFile(`media.${this.getMediaExtension(options.media.type)}`, buffer.length, 'media', buffer);
|
|
2248
|
+
const uploadedFile = await this.client.uploadFile({
|
|
2249
|
+
file,
|
|
2250
|
+
workers: 1
|
|
2251
|
+
});
|
|
2252
|
+
const inputMedia = options.media.type === 'photo' ?
|
|
2253
|
+
new telegram_1.Api.InputMediaUploadedPhoto({ file: uploadedFile }) :
|
|
2254
|
+
new telegram_1.Api.InputMediaUploadedDocument({
|
|
2255
|
+
file: uploadedFile,
|
|
2256
|
+
mimeType: this.getMimeType(options.media.type),
|
|
2257
|
+
attributes: this.getMediaAttributes(options.media)
|
|
2258
|
+
});
|
|
2259
|
+
return this.client.invoke(new telegram_1.Api.messages.EditMessage({
|
|
2260
|
+
peer: options.chatId,
|
|
2261
|
+
id: options.messageId,
|
|
2262
|
+
media: inputMedia,
|
|
2263
|
+
message: options.text || ''
|
|
2264
|
+
}));
|
|
2265
|
+
}
|
|
2266
|
+
if (options.text) {
|
|
2267
|
+
return this.client.invoke(new telegram_1.Api.messages.EditMessage({
|
|
2268
|
+
peer: options.chatId,
|
|
2269
|
+
id: options.messageId,
|
|
2270
|
+
message: options.text
|
|
2271
|
+
}));
|
|
2272
|
+
}
|
|
2273
|
+
throw new Error('Either text or media must be provided');
|
|
2274
|
+
}
|
|
2275
|
+
async getChats(options) {
|
|
2276
|
+
if (!this.client)
|
|
2277
|
+
throw new Error('Client not initialized');
|
|
2278
|
+
const dialogs = await this.client.getDialogs({
|
|
2279
|
+
...options,
|
|
2280
|
+
limit: options.limit || 100
|
|
2281
|
+
});
|
|
2282
|
+
return Promise.all(dialogs.map(async (dialog) => {
|
|
2283
|
+
const entity = dialog.entity;
|
|
2284
|
+
return {
|
|
2285
|
+
id: entity.id.toString(),
|
|
2286
|
+
title: 'title' in entity ? entity.title : null,
|
|
2287
|
+
username: 'username' in entity ? entity.username : null,
|
|
2288
|
+
type: entity instanceof telegram_1.Api.User ? 'user' :
|
|
2289
|
+
entity instanceof telegram_1.Api.Chat ? 'group' :
|
|
2290
|
+
entity instanceof telegram_1.Api.Channel ? 'channel' : 'unknown',
|
|
2291
|
+
unreadCount: dialog.unreadCount,
|
|
2292
|
+
lastMessage: dialog.message ? {
|
|
2293
|
+
id: dialog.message.id,
|
|
2294
|
+
text: dialog.message.message,
|
|
2295
|
+
date: new Date(dialog.message.date * 1000)
|
|
2296
|
+
} : null
|
|
2297
|
+
};
|
|
2298
|
+
}));
|
|
2299
|
+
}
|
|
2300
|
+
async updateChatSettings(settings) {
|
|
2301
|
+
if (!this.client)
|
|
2302
|
+
throw new Error('Client not initialized');
|
|
2303
|
+
const chat = await this.client.getEntity(settings.chatId);
|
|
2304
|
+
const updates = [];
|
|
2305
|
+
if (settings.title) {
|
|
2306
|
+
updates.push(this.client.invoke(new telegram_1.Api.channels.EditTitle({
|
|
2307
|
+
channel: chat,
|
|
2308
|
+
title: settings.title
|
|
2309
|
+
})));
|
|
2310
|
+
}
|
|
2311
|
+
if (settings.about) {
|
|
2312
|
+
updates.push(this.client.invoke(new telegram_1.Api.messages.EditChatAbout({
|
|
2313
|
+
peer: chat,
|
|
2314
|
+
about: settings.about
|
|
2315
|
+
})));
|
|
2316
|
+
}
|
|
2317
|
+
if (settings.photo) {
|
|
2318
|
+
const buffer = await this.downloadFileFromUrl(settings.photo);
|
|
2319
|
+
const file = await this.client.uploadFile({
|
|
2320
|
+
file: new uploads_1.CustomFile('photo.jpg', buffer.length, 'photo.jpg', buffer),
|
|
2321
|
+
workers: 1
|
|
2322
|
+
});
|
|
2323
|
+
updates.push(this.client.invoke(new telegram_1.Api.channels.EditPhoto({
|
|
2324
|
+
channel: chat,
|
|
2325
|
+
photo: new telegram_1.Api.InputChatUploadedPhoto({
|
|
2326
|
+
file: file
|
|
2327
|
+
})
|
|
2328
|
+
})));
|
|
2329
|
+
}
|
|
2330
|
+
if (settings.slowMode !== undefined) {
|
|
2331
|
+
updates.push(this.client.invoke(new telegram_1.Api.channels.ToggleSlowMode({
|
|
2332
|
+
channel: chat,
|
|
2333
|
+
seconds: settings.slowMode
|
|
2334
|
+
})));
|
|
2335
|
+
}
|
|
2336
|
+
if (settings.linkedChat) {
|
|
2337
|
+
const linkedChannel = await this.client.getEntity(settings.linkedChat);
|
|
2338
|
+
updates.push(this.client.invoke(new telegram_1.Api.channels.SetDiscussionGroup({
|
|
2339
|
+
broadcast: chat,
|
|
2340
|
+
group: linkedChannel
|
|
2341
|
+
})));
|
|
2342
|
+
}
|
|
2343
|
+
if (settings.username) {
|
|
2344
|
+
updates.push(this.client.invoke(new telegram_1.Api.channels.UpdateUsername({
|
|
2345
|
+
channel: chat,
|
|
2346
|
+
username: settings.username
|
|
2347
|
+
})));
|
|
2348
|
+
}
|
|
2349
|
+
await Promise.all(updates);
|
|
2350
|
+
return true;
|
|
2351
|
+
}
|
|
2352
|
+
async getMessageStats(options) {
|
|
2353
|
+
if (!this.client)
|
|
2354
|
+
throw new Error('Client not initialized');
|
|
2355
|
+
const now = options.fromDate || new Date();
|
|
2356
|
+
const startDate = new Date(now);
|
|
2357
|
+
switch (options.period) {
|
|
2358
|
+
case 'day':
|
|
2359
|
+
startDate.setDate(startDate.getDate() - 1);
|
|
2360
|
+
break;
|
|
2361
|
+
case 'week':
|
|
2362
|
+
startDate.setDate(startDate.getDate() - 7);
|
|
2363
|
+
break;
|
|
2364
|
+
case 'month':
|
|
2365
|
+
startDate.setMonth(startDate.getMonth() - 1);
|
|
2366
|
+
break;
|
|
2367
|
+
}
|
|
2368
|
+
const messages = await this.client.getMessages(options.chatId, {
|
|
2369
|
+
limit: 100,
|
|
2370
|
+
offsetDate: Math.floor(now.getTime() / 1000),
|
|
2371
|
+
});
|
|
2372
|
+
const stats = {
|
|
2373
|
+
total: messages.length,
|
|
2374
|
+
withMedia: 0,
|
|
2375
|
+
withLinks: 0,
|
|
2376
|
+
withForwards: 0,
|
|
2377
|
+
byHour: new Array(24).fill(0),
|
|
2378
|
+
byType: {
|
|
2379
|
+
text: 0,
|
|
2380
|
+
photo: 0,
|
|
2381
|
+
video: 0,
|
|
2382
|
+
document: 0,
|
|
2383
|
+
other: 0
|
|
2384
|
+
}
|
|
2385
|
+
};
|
|
2386
|
+
for (const msg of messages) {
|
|
2387
|
+
const hour = new Date(msg.date * 1000).getHours();
|
|
2388
|
+
stats.byHour[hour]++;
|
|
2389
|
+
if (msg.media) {
|
|
2390
|
+
stats.withMedia++;
|
|
2391
|
+
const mediaType = this.getMediaType(msg.media);
|
|
2392
|
+
stats.byType[mediaType] = (stats.byType[mediaType] || 0) + 1;
|
|
2393
|
+
}
|
|
2394
|
+
else if (msg.message) {
|
|
2395
|
+
if (msg.message.match(/https?:\/\/[^\s]+/)) {
|
|
2396
|
+
stats.withLinks++;
|
|
2397
|
+
}
|
|
2398
|
+
stats.byType.text++;
|
|
2399
|
+
}
|
|
2400
|
+
if (msg.fwdFrom) {
|
|
2401
|
+
stats.withForwards++;
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
return stats;
|
|
2405
|
+
}
|
|
2406
|
+
async getTopPrivateChats() {
|
|
2407
|
+
if (!this.client)
|
|
2408
|
+
throw new Error('Client not initialized');
|
|
2409
|
+
console.log('Starting getTopPrivateChats analysis...');
|
|
2410
|
+
const startTime = Date.now();
|
|
2411
|
+
const weights = {
|
|
2412
|
+
videoCall: 15,
|
|
2413
|
+
audioCall: 8,
|
|
2414
|
+
sharedVideo: 6,
|
|
2415
|
+
sharedPhoto: 4,
|
|
2416
|
+
textMessage: 1,
|
|
2417
|
+
recentActivityBonus: 1.5
|
|
2418
|
+
};
|
|
2419
|
+
console.log('Fetching dialogs...');
|
|
2420
|
+
const dialogs = await this.client.getDialogs({
|
|
2421
|
+
limit: 200
|
|
2422
|
+
});
|
|
2423
|
+
console.log(`Found ${dialogs.length} total dialogs`);
|
|
2424
|
+
const privateChats = dialogs.filter(dialog => dialog.isUser &&
|
|
2425
|
+
dialog.entity instanceof telegram_1.Api.User &&
|
|
2426
|
+
!dialog.entity.bot &&
|
|
2427
|
+
!dialog.entity.deleted &&
|
|
2428
|
+
!dialog.entity.fake &&
|
|
2429
|
+
dialog.entity.id.toString() !== "777000" &&
|
|
2430
|
+
dialog.entity.id.toString() !== "42777");
|
|
2431
|
+
console.log(`Found ${privateChats.length} valid private chats after filtering`);
|
|
2432
|
+
const now = Math.floor(Date.now() / 1000);
|
|
2433
|
+
const batchSize = 10;
|
|
2434
|
+
const chatStats = [];
|
|
2435
|
+
for (let i = 0; i < privateChats.length; i += batchSize) {
|
|
2436
|
+
console.log(`Processing batch ${Math.floor(i / batchSize) + 1}/${Math.ceil(privateChats.length / batchSize)}`);
|
|
2437
|
+
const batch = privateChats.slice(i, i + batchSize);
|
|
2438
|
+
const batchResults = await Promise.all(batch.map(async (dialog) => {
|
|
2439
|
+
const processingStart = Date.now();
|
|
2440
|
+
const chatId = dialog.entity.id.toString();
|
|
2441
|
+
const user = dialog.entity;
|
|
2442
|
+
console.log(`Processing chat ${chatId} (${user.firstName || 'Unknown'})`);
|
|
2443
|
+
try {
|
|
2444
|
+
const messages = await this.client.getMessages(chatId, {
|
|
2445
|
+
limit: 500,
|
|
2446
|
+
});
|
|
2447
|
+
if (messages.length < 20) {
|
|
2448
|
+
console.log(`Skipping chat ${chatId} - insufficient messages (${messages.length})`);
|
|
2449
|
+
return null;
|
|
2450
|
+
}
|
|
2451
|
+
console.log(`Retrieved ${messages.length} messages for chat ${chatId}`);
|
|
2452
|
+
const callStats = {
|
|
2453
|
+
total: 0,
|
|
2454
|
+
incoming: { total: 0, audio: 0, video: 0 },
|
|
2455
|
+
outgoing: { total: 0, audio: 0, video: 0 }
|
|
2456
|
+
};
|
|
2457
|
+
const mediaStats = { photos: 0, videos: 0 };
|
|
2458
|
+
let recentActivityScore = 0;
|
|
2459
|
+
for (const message of messages) {
|
|
2460
|
+
const messageAge = now - message.date;
|
|
2461
|
+
const recencyMultiplier = 1 + (1 - messageAge / (30 * 24 * 60 * 60));
|
|
2462
|
+
if (message.action instanceof telegram_1.Api.MessageActionPhoneCall) {
|
|
2463
|
+
const call = message.action;
|
|
2464
|
+
callStats.total++;
|
|
2465
|
+
if (message.out) {
|
|
2466
|
+
callStats.outgoing.total++;
|
|
2467
|
+
call.video ? callStats.outgoing.video++ : callStats.outgoing.audio++;
|
|
2468
|
+
}
|
|
2469
|
+
else {
|
|
2470
|
+
callStats.incoming.total++;
|
|
2471
|
+
call.video ? callStats.incoming.video++ : callStats.incoming.audio++;
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
if (message.media) {
|
|
2475
|
+
if (message.media instanceof telegram_1.Api.MessageMediaPhoto) {
|
|
2476
|
+
mediaStats.photos++;
|
|
2477
|
+
}
|
|
2478
|
+
else if (message.media instanceof telegram_1.Api.MessageMediaDocument &&
|
|
2479
|
+
message.media.document instanceof telegram_1.Api.Document &&
|
|
2480
|
+
message.media.document.mimeType?.startsWith('video/')) {
|
|
2481
|
+
mediaStats.videos++;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
recentActivityScore += recencyMultiplier;
|
|
2485
|
+
}
|
|
2486
|
+
const interactionScore = ((callStats.incoming.video + callStats.outgoing.video) * weights.videoCall +
|
|
2487
|
+
(callStats.incoming.audio + callStats.outgoing.audio) * weights.audioCall +
|
|
2488
|
+
mediaStats.videos * weights.sharedVideo +
|
|
2489
|
+
mediaStats.photos * weights.sharedPhoto +
|
|
2490
|
+
messages.length * weights.textMessage) * (recentActivityScore * weights.recentActivityBonus);
|
|
2491
|
+
const activityBreakdown = {
|
|
2492
|
+
videoCalls: ((callStats.incoming.video + callStats.outgoing.video) * weights.videoCall) / interactionScore * 100,
|
|
2493
|
+
audioCalls: ((callStats.incoming.audio + callStats.outgoing.audio) * weights.audioCall) / interactionScore * 100,
|
|
2494
|
+
mediaSharing: ((mediaStats.videos * weights.sharedVideo + mediaStats.photos * weights.sharedPhoto)) / interactionScore * 100,
|
|
2495
|
+
textMessages: (messages.length * weights.textMessage) / interactionScore * 100
|
|
2496
|
+
};
|
|
2497
|
+
const processingTime = Date.now() - processingStart;
|
|
2498
|
+
console.log(`Finished processing chat ${chatId} in ${processingTime}ms with interaction score: ${interactionScore}`);
|
|
2499
|
+
return {
|
|
2500
|
+
chatId,
|
|
2501
|
+
username: user.username,
|
|
2502
|
+
firstName: user.firstName,
|
|
2503
|
+
lastName: user.lastName,
|
|
2504
|
+
totalMessages: messages.length,
|
|
2505
|
+
interactionScore: Math.round(interactionScore * 100) / 100,
|
|
2506
|
+
calls: callStats,
|
|
2507
|
+
media: mediaStats,
|
|
2508
|
+
activityBreakdown
|
|
2509
|
+
};
|
|
2510
|
+
}
|
|
2511
|
+
catch (error) {
|
|
2512
|
+
console.error(`Error processing chat ${chatId}:`, error);
|
|
2513
|
+
return null;
|
|
2514
|
+
}
|
|
2515
|
+
}));
|
|
2516
|
+
chatStats.push(...batchResults.filter(Boolean));
|
|
2517
|
+
}
|
|
2518
|
+
const topChats = chatStats
|
|
2519
|
+
.sort((a, b) => b.interactionScore - a.interactionScore)
|
|
2520
|
+
.slice(0, 5);
|
|
2521
|
+
const totalTime = Date.now() - startTime;
|
|
2522
|
+
console.log(`getTopPrivateChats completed in ${totalTime}ms. Found ${topChats.length} top chats`);
|
|
2523
|
+
topChats.forEach((chat, index) => {
|
|
2524
|
+
console.log(`Top ${index + 1}: ${chat.firstName} (${chat.username || 'no username'}) - Score: ${chat.interactionScore}`);
|
|
2525
|
+
});
|
|
2526
|
+
return topChats;
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
exports.default = TelegramManager;
|
|
2530
|
+
//# sourceMappingURL=TelegramManager.js.map
|