common-tg-service 1.3.153 → 1.3.155

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.
@@ -67,7 +67,7 @@ export declare class TelegramController {
67
67
  totalOperations: number;
68
68
  };
69
69
  }>;
70
- getCallLogStats(mobile: string, limit?: number, includeCallLog?: string): Promise<import("./manager").CallLogResult>;
70
+ getCallLogStats(mobile: string, limit?: number): Promise<Record<string, import("./manager").CallHistoryEntry[]>>;
71
71
  addContactsBulk(mobile: string, contactsDto: AddContactsDto): Promise<void>;
72
72
  getContacts(mobile: string): Promise<import("telegram").Api.contacts.TypeContacts>;
73
73
  sendMedia(mobile: string, sendMediaDto: SendMediaDto): Promise<void>;
@@ -90,6 +90,8 @@ export declare class TelegramController {
90
90
  cleanupChat(mobile: string, cleanup: ChatCleanupDto): Promise<{
91
91
  deletedCount: number;
92
92
  }>;
93
+ getChatMediaCounts(mobile: string, chatId: string): Promise<import("./manager").ChatMediaCounts>;
94
+ getChatCallHistory(mobile: string, chatId: string, limit?: number, includeCalls?: string): Promise<import("./manager").ChatCallHistory>;
93
95
  getChatStatistics(mobile: string, chatId: string, period?: 'day' | 'week' | 'month'): Promise<ChatStatistics>;
94
96
  scheduleMessage(mobile: string, schedule: ScheduleMessageDto): Promise<import("telegram").Api.Message | import("telegram").Api.TypeUpdates>;
95
97
  getScheduledMessages(mobile: string, chatId: string): Promise<import("./manager").ScheduledMessageItem[]>;
@@ -160,38 +162,7 @@ export declare class TelegramController {
160
162
  period: 'day' | 'week' | 'month';
161
163
  fromDate?: Date;
162
164
  }): Promise<import("./manager").MessageStats>;
163
- getTopPrivateChats(mobile: string, limit?: number): Promise<{
164
- chatId: string;
165
- username?: string;
166
- firstName?: string;
167
- lastName?: string;
168
- totalMessages: number;
169
- interactionScore: number;
170
- engagementLevel: "active" | "dormant";
171
- calls: {
172
- total: number;
173
- incoming: {
174
- total: number;
175
- audio: number;
176
- video: number;
177
- };
178
- outgoing: {
179
- total: number;
180
- audio: number;
181
- video: number;
182
- };
183
- };
184
- media: {
185
- photos: number;
186
- videos: number;
187
- };
188
- activityBreakdown: {
189
- videoCalls: number;
190
- audioCalls: number;
191
- mediaSharing: number;
192
- textMessages: number;
193
- };
194
- }[]>;
165
+ getTopPrivateChats(mobile: string, limit?: number, enrichMedia?: boolean, offsetDate?: number): Promise<import("./manager").TopPrivateChatsResult>;
195
166
  getSelfMsgsInfo(mobile: string, limit?: number): Promise<import("./manager").SelfMessagesInfo>;
196
167
  addBotsToChannel(mobile: string, body: {
197
168
  channelIds?: string[];
@@ -178,12 +178,11 @@ let TelegramController = class TelegramController {
178
178
  async getConnectionStatus() {
179
179
  return { status: await this.telegramService.getConnectionStatus() };
180
180
  }
181
- async getCallLogStats(mobile, limit, includeCallLog) {
181
+ async getCallLogStats(mobile, limit) {
182
182
  if (limit !== undefined && (limit < 1 || limit > 10000)) {
183
183
  throw new common_1.BadRequestException('Limit must be between 1 and 10000.');
184
184
  }
185
- const includeCallLogBool = includeCallLog === 'true' || includeCallLog === '1';
186
- return this.telegramService.getCallLog(mobile, limit, includeCallLogBool);
185
+ return this.telegramService.getCallLog(mobile, limit);
187
186
  }
188
187
  async addContactsBulk(mobile, contactsDto) {
189
188
  return this.telegramService.addContacts(mobile, contactsDto.phoneNumbers, contactsDto.prefix);
@@ -469,6 +468,22 @@ let TelegramController = class TelegramController {
469
468
  excludePinned: cleanup.excludePinned
470
469
  });
471
470
  }
471
+ async getChatMediaCounts(mobile, chatId) {
472
+ if (!chatId || chatId.trim().length === 0) {
473
+ throw new common_1.BadRequestException('chatId is required and cannot be empty');
474
+ }
475
+ return this.telegramService.getChatMediaCounts(mobile, chatId);
476
+ }
477
+ async getChatCallHistory(mobile, chatId, limit, includeCalls) {
478
+ if (!chatId || chatId.trim().length === 0) {
479
+ throw new common_1.BadRequestException('chatId is required and cannot be empty');
480
+ }
481
+ if (limit !== undefined && (limit < 1 || limit > 500)) {
482
+ throw new common_1.BadRequestException('Limit must be between 1 and 500');
483
+ }
484
+ const includeCallsBool = includeCalls === 'true' || includeCalls === '1';
485
+ return this.telegramService.getChatCallHistory(mobile, chatId, limit, includeCallsBool);
486
+ }
472
487
  async getChatStatistics(mobile, chatId, period = 'week') {
473
488
  return this.telegramService.getChatStatistics(mobile, chatId, period);
474
489
  }
@@ -579,8 +594,10 @@ let TelegramController = class TelegramController {
579
594
  async getMessageStats(mobile, options) {
580
595
  return this.telegramService.getMessageStats(mobile, options);
581
596
  }
582
- async getTopPrivateChats(mobile, limit) {
583
- return this.telegramService.getTopPrivateChats(mobile, limit);
597
+ async getTopPrivateChats(mobile, limit, enrichMedia, offsetDate) {
598
+ const enrich = enrichMedia === true || enrichMedia === 'true';
599
+ const offset = offsetDate ? Number(offsetDate) : undefined;
600
+ return this.telegramService.getTopPrivateChats(mobile, limit, enrich, offset);
584
601
  }
585
602
  async getSelfMsgsInfo(mobile, limit) {
586
603
  if (limit !== undefined && (limit < 1 || limit > 10000)) {
@@ -916,89 +933,16 @@ __decorate([
916
933
  __decorate([
917
934
  (0, common_1.Get)('monitoring/calllog/:mobile'),
918
935
  (0, swagger_1.ApiOperation)({
919
- summary: 'Get call log statistics with enhanced filtering',
920
- description: 'Retrieves comprehensive call statistics including incoming/outgoing calls, video/audio breakdown, ' +
921
- 'and per-chat call counts. Uses server-side filtering for optimal performance. ' +
922
- 'Supports pagination via limit parameter (default: 1000, max: 10000).'
936
+ summary: 'Get all call logs grouped by chat',
937
+ description: 'Returns all call logs as a Record<chatId, CallHistoryEntry[]>. Use chat/call-history for per-chat summary.'
923
938
  }),
924
939
  (0, swagger_1.ApiParam)({ name: 'mobile', description: 'Mobile number', required: true }),
925
- (0, swagger_1.ApiQuery)({
926
- name: 'limit',
927
- required: false,
928
- type: Number,
929
- description: 'Maximum number of calls to analyze (default: 1000, max: 10000)',
930
- example: 1000,
931
- minimum: 1,
932
- maximum: 10000
933
- }),
934
- (0, swagger_1.ApiQuery)({
935
- name: 'includeCallLog',
936
- required: false,
937
- type: Boolean,
938
- description: 'If true, each chat in the response includes a callLog array with per-call details (messageId, date, duration, video, outgoing). Default: false.',
939
- example: false
940
- }),
941
- (0, swagger_1.ApiResponse)({
942
- status: 200,
943
- description: 'Call log statistics retrieved successfully',
944
- schema: {
945
- type: 'object',
946
- properties: {
947
- totalCalls: { type: 'number', description: 'Total number of calls' },
948
- outgoing: { type: 'number', description: 'Total outgoing calls' },
949
- incoming: { type: 'number', description: 'Total incoming calls' },
950
- video: { type: 'number', description: 'Total video calls' },
951
- audio: { type: 'number', description: 'Total audio calls' },
952
- chats: {
953
- type: 'array',
954
- description: 'Per-chat call summary with identity, call stats, media counts, and call log',
955
- items: {
956
- type: 'object',
957
- properties: {
958
- chatId: { type: 'string' },
959
- phone: { type: 'string' },
960
- username: { type: 'string' },
961
- name: { type: 'string' },
962
- peerType: { type: 'string', enum: ['user', 'group', 'channel'] },
963
- calls: {
964
- type: 'object',
965
- properties: {
966
- total: { type: 'number' },
967
- outgoing: { type: 'number' },
968
- incoming: { type: 'number' },
969
- video: { type: 'number' },
970
- audio: { type: 'number' }
971
- }
972
- },
973
- totalMessages: { type: 'number' },
974
- photoCount: { type: 'number' },
975
- videoCount: { type: 'number' },
976
- callLog: {
977
- type: 'array',
978
- items: {
979
- type: 'object',
980
- properties: {
981
- messageId: { type: 'number' },
982
- date: { type: 'number' },
983
- durationSeconds: { type: 'number' },
984
- video: { type: 'boolean' },
985
- outgoing: { type: 'boolean' }
986
- }
987
- }
988
- }
989
- }
990
- }
991
- }
992
- }
993
- }
994
- }),
995
- (0, swagger_1.ApiResponse)({ status: 400, description: 'Bad Request - invalid limit parameter' }),
996
- (0, swagger_1.ApiResponse)({ status: 500, description: 'Internal Server Error' }),
940
+ (0, swagger_1.ApiQuery)({ name: 'limit', required: false, type: Number, description: 'Max calls to scan (default: 1000, max: 10000)' }),
941
+ (0, swagger_1.ApiResponse)({ status: 200, description: 'Call logs grouped by chatId' }),
997
942
  __param(0, (0, common_1.Param)('mobile')),
998
943
  __param(1, (0, common_1.Query)('limit')),
999
- __param(2, (0, common_1.Query)('includeCallLog')),
1000
944
  __metadata("design:type", Function),
1001
- __metadata("design:paramtypes", [String, Number, String]),
945
+ __metadata("design:paramtypes", [String, Number]),
1002
946
  __metadata("design:returntype", Promise)
1003
947
  ], TelegramController.prototype, "getCallLogStats", null);
1004
948
  __decorate([
@@ -1520,6 +1464,85 @@ __decorate([
1520
1464
  __metadata("design:paramtypes", [String, dto_1.ChatCleanupDto]),
1521
1465
  __metadata("design:returntype", Promise)
1522
1466
  ], TelegramController.prototype, "cleanupChat", null);
1467
+ __decorate([
1468
+ (0, common_1.Get)('chat/media-counts/:mobile'),
1469
+ (0, swagger_1.ApiOperation)({ summary: 'Get detailed media counts for a chat' }),
1470
+ (0, swagger_1.ApiParam)({ name: 'mobile', description: 'Mobile number', required: true }),
1471
+ (0, swagger_1.ApiQuery)({ name: 'chatId', description: 'Chat ID or username', required: true }),
1472
+ (0, swagger_1.ApiResponse)({
1473
+ status: 200,
1474
+ description: 'Media counts retrieved successfully',
1475
+ schema: {
1476
+ type: 'object',
1477
+ properties: {
1478
+ totalMessages: { type: 'number' },
1479
+ photo: { type: 'number' },
1480
+ video: { type: 'number' },
1481
+ roundVideo: { type: 'number', description: 'Video notes (round videos)' },
1482
+ document: { type: 'number' },
1483
+ voice: { type: 'number' },
1484
+ gif: { type: 'number' },
1485
+ audio: { type: 'number', description: 'Music files' },
1486
+ link: { type: 'number', description: 'Shared URLs' },
1487
+ totalMedia: { type: 'number', description: 'Total media count (excludes links)' },
1488
+ }
1489
+ }
1490
+ }),
1491
+ __param(0, (0, common_1.Param)('mobile')),
1492
+ __param(1, (0, common_1.Query)('chatId')),
1493
+ __metadata("design:type", Function),
1494
+ __metadata("design:paramtypes", [String, String]),
1495
+ __metadata("design:returntype", Promise)
1496
+ ], TelegramController.prototype, "getChatMediaCounts", null);
1497
+ __decorate([
1498
+ (0, common_1.Get)('chat/call-history/:mobile'),
1499
+ (0, swagger_1.ApiOperation)({ summary: 'Get call history with a specific chat' }),
1500
+ (0, swagger_1.ApiParam)({ name: 'mobile', description: 'Mobile number', required: true }),
1501
+ (0, swagger_1.ApiQuery)({ name: 'chatId', description: 'Chat ID or username', required: true }),
1502
+ (0, swagger_1.ApiQuery)({ name: 'limit', description: 'Maximum number of calls to return (1-500, default 100)', required: false, type: Number }),
1503
+ (0, swagger_1.ApiQuery)({ name: 'includeCalls', description: 'Include individual call entries in response (default: false)', required: false, type: Boolean }),
1504
+ (0, swagger_1.ApiResponse)({
1505
+ status: 200,
1506
+ description: 'Call history retrieved successfully',
1507
+ schema: {
1508
+ type: 'object',
1509
+ properties: {
1510
+ totalCalls: { type: 'number' },
1511
+ incoming: { type: 'number' },
1512
+ outgoing: { type: 'number' },
1513
+ missed: { type: 'number' },
1514
+ videoCalls: { type: 'number' },
1515
+ audioCalls: { type: 'number' },
1516
+ totalDuration: { type: 'number', description: 'Total duration in seconds' },
1517
+ averageDuration: { type: 'number', description: 'Average duration in seconds' },
1518
+ longestCall: { type: 'number', description: 'Longest call duration in seconds' },
1519
+ lastCallDate: { type: 'string', nullable: true, description: 'ISO 8601 date of most recent call' },
1520
+ calls: {
1521
+ type: 'array',
1522
+ description: 'Only present when includeCalls=true',
1523
+ items: {
1524
+ type: 'object',
1525
+ properties: {
1526
+ messageId: { type: 'number' },
1527
+ date: { type: 'string', description: 'ISO 8601 date' },
1528
+ durationSeconds: { type: 'number' },
1529
+ video: { type: 'boolean' },
1530
+ outgoing: { type: 'boolean' },
1531
+ reason: { type: 'string', enum: ['missed', 'busy', 'hangup', 'disconnect', 'unknown'] },
1532
+ }
1533
+ }
1534
+ }
1535
+ }
1536
+ }
1537
+ }),
1538
+ __param(0, (0, common_1.Param)('mobile')),
1539
+ __param(1, (0, common_1.Query)('chatId')),
1540
+ __param(2, (0, common_1.Query)('limit')),
1541
+ __param(3, (0, common_1.Query)('includeCalls')),
1542
+ __metadata("design:type", Function),
1543
+ __metadata("design:paramtypes", [String, String, Number, String]),
1544
+ __metadata("design:returntype", Promise)
1545
+ ], TelegramController.prototype, "getChatCallHistory", null);
1523
1546
  __decorate([
1524
1547
  (0, common_1.Get)('chat/statistics/:mobile'),
1525
1548
  (0, swagger_1.ApiOperation)({ summary: 'Get chat statistics' }),
@@ -1852,69 +1875,73 @@ __decorate([
1852
1875
  required: false,
1853
1876
  type: Number,
1854
1877
  description: 'Maximum number of top chats to return (default: 10, min: 1, max: 50)',
1855
- example: 10
1878
+ example: 45
1879
+ }),
1880
+ (0, swagger_1.ApiQuery)({
1881
+ name: 'enrichMedia',
1882
+ required: false,
1883
+ type: Boolean,
1884
+ description: 'Include detailed per-type media breakdown (photo, video, document, etc). Slower due to extra API calls per chat.',
1885
+ example: false
1886
+ }),
1887
+ (0, swagger_1.ApiQuery)({
1888
+ name: 'offsetDate',
1889
+ required: false,
1890
+ type: Number,
1891
+ description: 'Unix timestamp from pagination.nextOffsetDate of previous response. Omit for first page.',
1856
1892
  }),
1857
1893
  (0, swagger_1.ApiResponse)({
1858
1894
  status: 200,
1859
1895
  description: 'Top private chats retrieved successfully',
1860
1896
  schema: {
1861
- type: 'array',
1862
- items: {
1863
- type: 'object',
1864
- properties: {
1865
- chatId: { type: 'string', description: 'Chat/user ID' },
1866
- username: { type: 'string', description: 'Username (if available)' },
1867
- firstName: { type: 'string', description: 'First name' },
1868
- lastName: { type: 'string', description: 'Last name' },
1869
- totalMessages: { type: 'number', description: 'Total messages in conversation' },
1870
- interactionScore: {
1871
- type: 'number',
1872
- description: 'Calculated engagement score (higher = more active)'
1873
- },
1874
- engagementLevel: {
1875
- type: 'string',
1876
- enum: ['active', 'dormant'],
1877
- description: 'Active if engagement score > 0, else dormant'
1878
- },
1879
- calls: {
1897
+ type: 'object',
1898
+ properties: {
1899
+ items: {
1900
+ type: 'array',
1901
+ items: {
1880
1902
  type: 'object',
1881
1903
  properties: {
1882
- total: { type: 'number' },
1883
- incoming: {
1884
- type: 'object',
1904
+ chatId: { type: 'string' },
1905
+ name: { type: 'string', description: 'Display name' },
1906
+ username: { type: 'string', nullable: true },
1907
+ phone: { type: 'string', nullable: true },
1908
+ totalMessages: { type: 'number' },
1909
+ mediaCount: { type: 'number', description: 'Photo + video count (always present)' },
1910
+ interactionScore: { type: 'number', description: 'Engagement score (higher = more active)' },
1911
+ lastMessageDate: { type: 'string', nullable: true, description: 'ISO 8601 date of last message' },
1912
+ media: {
1913
+ type: 'object', nullable: true,
1914
+ description: 'Detailed media breakdown (null when enrichMedia=false)',
1885
1915
  properties: {
1886
- total: { type: 'number' },
1887
- audio: { type: 'number' },
1888
- video: { type: 'number' }
1916
+ photo: { type: 'number' }, video: { type: 'number' }, roundVideo: { type: 'number' },
1917
+ document: { type: 'number' }, voice: { type: 'number' }, gif: { type: 'number' },
1918
+ audio: { type: 'number' }, link: { type: 'number' }, totalMedia: { type: 'number' },
1889
1919
  }
1890
1920
  },
1891
- outgoing: {
1921
+ calls: {
1892
1922
  type: 'object',
1923
+ description: 'Call summary',
1893
1924
  properties: {
1894
- total: { type: 'number' },
1895
- audio: { type: 'number' },
1896
- video: { type: 'number' }
1925
+ totalCalls: { type: 'number' }, incomingCalls: { type: 'number' },
1926
+ outgoingCalls: { type: 'number' }, missedCalls: { type: 'number' },
1927
+ videoCalls: { type: 'number' }, audioCalls: { type: 'number' },
1928
+ totalDuration: { type: 'number', description: 'Seconds' },
1929
+ averageDuration: { type: 'number', description: 'Seconds' },
1930
+ longestCall: { type: 'number', description: 'Seconds' },
1931
+ lastCallDate: { type: 'string', nullable: true },
1897
1932
  }
1898
- }
1899
- }
1900
- },
1901
- media: {
1902
- type: 'object',
1903
- properties: {
1904
- photos: { type: 'number', description: 'Total photos shared' },
1905
- videos: { type: 'number', description: 'Total videos shared' }
1906
- }
1907
- },
1908
- activityBreakdown: {
1909
- type: 'object',
1910
- description: 'Percentage breakdown of interaction types',
1911
- properties: {
1912
- videoCalls: { type: 'number', description: 'Percentage from video calls' },
1913
- audioCalls: { type: 'number', description: 'Percentage from audio calls' },
1914
- mediaSharing: { type: 'number', description: 'Percentage from media sharing' },
1915
- textMessages: { type: 'number', description: 'Percentage from text messages' }
1933
+ },
1916
1934
  }
1917
1935
  }
1936
+ },
1937
+ pagination: {
1938
+ type: 'object',
1939
+ properties: {
1940
+ count: { type: 'number', description: 'Number of items returned' },
1941
+ hasMore: { type: 'boolean' },
1942
+ previousOffsetDate: { type: 'number', description: 'The offsetDate that was passed in (for prev button)' },
1943
+ nextOffsetDate: { type: 'number', description: 'Pass as offsetDate for next page' },
1944
+ }
1918
1945
  }
1919
1946
  }
1920
1947
  }
@@ -1922,8 +1949,10 @@ __decorate([
1922
1949
  (0, swagger_1.ApiResponse)({ status: 500, description: 'Internal Server Error' }),
1923
1950
  __param(0, (0, common_1.Param)('mobile')),
1924
1951
  __param(1, (0, common_1.Query)('limit')),
1952
+ __param(2, (0, common_1.Query)('enrichMedia')),
1953
+ __param(3, (0, common_1.Query)('offsetDate')),
1925
1954
  __metadata("design:type", Function),
1926
- __metadata("design:paramtypes", [String, Number]),
1955
+ __metadata("design:paramtypes", [String, Number, Boolean, Number]),
1927
1956
  __metadata("design:returntype", Promise)
1928
1957
  ], TelegramController.prototype, "getTopPrivateChats", null);
1929
1958
  __decorate([