chz-telegram-bot 0.7.13 → 0.7.15
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/dist/dtos/propertyProviderSets.d.ts +0 -1
- package/dist/dtos/propertyProviderSets.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.d.ts +1 -1
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +2 -2
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/commandActionBuilder.js +2 -3
- package/package.json +4 -1
- package/eslint.config.ts +0 -62
- package/src/builtin/helpAction.ts +0 -17
- package/src/dtos/chatHistoryMessage.ts +0 -22
- package/src/dtos/chatInfo.ts +0 -12
- package/src/dtos/commandTriggerCheckResult.ts +0 -40
- package/src/dtos/cooldownInfo.ts +0 -10
- package/src/dtos/incomingMessage.ts +0 -71
- package/src/dtos/incomingQuery.ts +0 -14
- package/src/dtos/messageInfo.ts +0 -15
- package/src/dtos/propertyProviderSets.ts +0 -21
- package/src/dtos/replyInfo.ts +0 -9
- package/src/dtos/responses/delay.ts +0 -28
- package/src/dtos/responses/imageMessage.ts +0 -41
- package/src/dtos/responses/inlineQueryResponse.ts +0 -26
- package/src/dtos/responses/reaction.ts +0 -30
- package/src/dtos/responses/textMessage.ts +0 -44
- package/src/dtos/responses/unpin.ts +0 -27
- package/src/dtos/responses/videoMessage.ts +0 -41
- package/src/dtos/userInfo.ts +0 -8
- package/src/entities/actions/commandAction.ts +0 -275
- package/src/entities/actions/inlineQueryAction.ts +0 -83
- package/src/entities/actions/replyCaptureAction.ts +0 -110
- package/src/entities/actions/scheduledAction.ts +0 -182
- package/src/entities/botInstance.ts +0 -92
- package/src/entities/cachedStateFactory.ts +0 -14
- package/src/entities/context/baseContext.ts +0 -111
- package/src/entities/context/chatContext.ts +0 -135
- package/src/entities/context/inlineQueryContext.ts +0 -63
- package/src/entities/context/messageContext.ts +0 -250
- package/src/entities/context/replyContext.ts +0 -260
- package/src/entities/states/actionStateBase.ts +0 -6
- package/src/entities/taskRecord.ts +0 -11
- package/src/helpers/builders/commandActionBuilder.ts +0 -214
- package/src/helpers/builders/inlineQueryActionBuilder.ts +0 -71
- package/src/helpers/builders/scheduledActionBuilder.ts +0 -143
- package/src/helpers/mapUtils.ts +0 -28
- package/src/helpers/noop.ts +0 -20
- package/src/helpers/objectFromEntries.ts +0 -7
- package/src/helpers/timeConvertions.ts +0 -13
- package/src/helpers/toArray.ts +0 -3
- package/src/helpers/traceFactory.ts +0 -11
- package/src/index.ts +0 -33
- package/src/main.ts +0 -76
- package/src/services/actionProcessingService.ts +0 -125
- package/src/services/actionProcessors/baseProcessor.ts +0 -67
- package/src/services/actionProcessors/commandActionProcessor.ts +0 -231
- package/src/services/actionProcessors/inlineQueryActionProcessor.ts +0 -165
- package/src/services/actionProcessors/scheduledActionProcessor.ts +0 -136
- package/src/services/jsonFileStorage.ts +0 -181
- package/src/services/nodeTimeoutScheduler.ts +0 -79
- package/src/services/responseProcessingQueue.ts +0 -57
- package/src/services/telegramApi.ts +0 -278
- package/src/types/action.ts +0 -15
- package/src/types/actionState.ts +0 -4
- package/src/types/cachedValueAccessor.ts +0 -1
- package/src/types/capture.ts +0 -33
- package/src/types/commandCondition.ts +0 -9
- package/src/types/commandTrigger.ts +0 -1
- package/src/types/events.ts +0 -286
- package/src/types/externalAliases.ts +0 -18
- package/src/types/handlers.ts +0 -26
- package/src/types/inputFile.ts +0 -4
- package/src/types/messageSendingOptions.ts +0 -10
- package/src/types/messageTypes.ts +0 -21
- package/src/types/propertyProvider.ts +0 -14
- package/src/types/response.ts +0 -51
- package/src/types/scheduler.ts +0 -20
- package/src/types/storage.ts +0 -23
- package/src/types/timeValues.ts +0 -33
- package/src/types/trace.ts +0 -5
- package/tests/dtos/commandTriggerCheckResult.test.ts +0 -301
- package/tests/entities/actions/inlineQueryAction.test.ts +0 -359
- package/tests/entities/actions/replyCaptureAction.test.ts +0 -501
- package/tests/entities/cachedStateFactory.test.ts +0 -98
- package/tests/entities/context/chatContext.test.ts +0 -606
- package/tests/entities/context/messageContext.test.ts +0 -370
- package/tests/entities/states/actionStateBase.test.ts +0 -138
- package/tests/entities/taskRecord.test.ts +0 -195
- package/tests/helpers/mapUtils.test.ts +0 -163
- package/tests/helpers/timeConvertions.test.ts +0 -129
- package/tests/services/actionProcessors/baseActionProcessor.test.ts +0 -359
- package/tests/services/actionProcessors/commandActionProcessor.test.ts +0 -268
- package/tests/services/actionProcessors/inlineQueryActionProcessor.test.ts +0 -616
- package/tests/services/actionProcessors/processorTestHelpers.ts +0 -147
- package/tests/services/actionProcessors/scheduledActionProcessor.test.ts +0 -153
- package/tests/services/jsonFileStorage.test.ts +0 -927
- package/tests/services/nodeTimeoutScheduler.test.ts +0 -421
- package/tests/services/responseProcessingQueue.test.ts +0 -388
- package/tsconfig.build.json +0 -8
- package/tsconfig.json +0 -118
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { mock, type Mock } from 'bun:test';
|
|
2
|
-
import { IScheduler } from '../../../src/types/scheduler';
|
|
3
|
-
import { IStorageClient } from '../../../src/types/storage';
|
|
4
|
-
import { ActionKey, IAction } from '../../../src/types/action';
|
|
5
|
-
import { BotResponse } from '../../../src/types/response';
|
|
6
|
-
import { ChatInfo } from '../../../src/dtos/chatInfo';
|
|
7
|
-
import { TextMessage } from '../../../src/dtos/responses/textMessage';
|
|
8
|
-
import { TraceId } from '../../../src/types/trace';
|
|
9
|
-
import { Milliseconds } from '../../../src/types/timeValues';
|
|
10
|
-
import { TelegramApiService } from '../../../src/services/telegramApi';
|
|
11
|
-
|
|
12
|
-
// Re-export Mock type for use in tests
|
|
13
|
-
export type { Mock } from 'bun:test';
|
|
14
|
-
|
|
15
|
-
// Type-safe mock accessor - returns the mock function with proper typing
|
|
16
|
-
export function getMockFn<T extends (...args: never[]) => unknown>(
|
|
17
|
-
fn: T
|
|
18
|
-
): Mock<T> {
|
|
19
|
-
return fn as unknown as Mock<T>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function createMockStorage(): IStorageClient {
|
|
23
|
-
return {
|
|
24
|
-
load: mock(() => ({})) as IStorageClient['load'],
|
|
25
|
-
close: mock(() => Promise.resolve()),
|
|
26
|
-
getActionState: mock(() => ({
|
|
27
|
-
lastExecutedDate: 0,
|
|
28
|
-
pinnedMessages: []
|
|
29
|
-
})) as IStorageClient['getActionState'],
|
|
30
|
-
saveActionExecutionResult: mock(() => Promise.resolve()),
|
|
31
|
-
updateStateFor: mock(() => Promise.resolve())
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Extended scheduler type that exposes mock call tracking
|
|
36
|
-
export interface MockScheduler extends IScheduler {
|
|
37
|
-
createTaskCallCount: () => number;
|
|
38
|
-
createOnetimeTaskCallCount: () => number;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function createMockScheduler(): MockScheduler {
|
|
42
|
-
// Using arrow functions assigned to variables to avoid unbound-method ESLint errors
|
|
43
|
-
const createTaskMock = mock(
|
|
44
|
-
(
|
|
45
|
-
_name: string,
|
|
46
|
-
action: () => void,
|
|
47
|
-
_interval: Milliseconds,
|
|
48
|
-
executeRightAway: boolean,
|
|
49
|
-
_ownerName: string
|
|
50
|
-
): void => {
|
|
51
|
-
if (executeRightAway) {
|
|
52
|
-
setImmediate(() => {
|
|
53
|
-
action();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const createOnetimeTaskMock = mock(
|
|
60
|
-
(
|
|
61
|
-
_name: string,
|
|
62
|
-
action: () => void,
|
|
63
|
-
delay: Milliseconds,
|
|
64
|
-
_ownerName: string
|
|
65
|
-
): void => {
|
|
66
|
-
setTimeout(() => {
|
|
67
|
-
action();
|
|
68
|
-
}, delay as number);
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const stopAll = mock(() => {
|
|
73
|
-
/* no-op */
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
createTask: createTaskMock,
|
|
78
|
-
createOnetimeTask: createOnetimeTaskMock,
|
|
79
|
-
stopAll,
|
|
80
|
-
createTaskCallCount: () => createTaskMock.mock.calls.length,
|
|
81
|
-
createOnetimeTaskCallCount: () =>
|
|
82
|
-
createOnetimeTaskMock.mock.calls.length
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Extended action type that exposes mock call tracking
|
|
87
|
-
export interface MockAction extends IAction {
|
|
88
|
-
getExecCallCount: () => number;
|
|
89
|
-
getExecLastArgs: () => unknown[] | undefined;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function createMockAction(
|
|
93
|
-
key: string,
|
|
94
|
-
execResult: BotResponse[] = []
|
|
95
|
-
): MockAction {
|
|
96
|
-
const execMock = mock(() => Promise.resolve(execResult));
|
|
97
|
-
return {
|
|
98
|
-
key: key as ActionKey,
|
|
99
|
-
exec: execMock,
|
|
100
|
-
getExecCallCount: () => execMock.mock.calls.length,
|
|
101
|
-
getExecLastArgs: () => execMock.mock.calls.at(-1)
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Extended telegram api type that exposes mock call tracking
|
|
106
|
-
export interface MockTelegramApi extends TelegramApiService {
|
|
107
|
-
getEnqueueCallCount: () => number;
|
|
108
|
-
getEnqueueLastArgs: () => BotResponse[] | undefined;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function createMockTelegramApi(): MockTelegramApi {
|
|
112
|
-
const enqueueMock = mock((_responses: BotResponse[]) => {
|
|
113
|
-
/* no-op */
|
|
114
|
-
});
|
|
115
|
-
const flushMock = mock(() => {
|
|
116
|
-
/* no-op */
|
|
117
|
-
});
|
|
118
|
-
return {
|
|
119
|
-
enqueueBatchedResponses: enqueueMock,
|
|
120
|
-
flushResponses: flushMock,
|
|
121
|
-
getEnqueueCallCount: () => enqueueMock.mock.calls.length,
|
|
122
|
-
getEnqueueLastArgs: () => enqueueMock.mock.calls.at(-1)?.[0]
|
|
123
|
-
} as unknown as MockTelegramApi;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function createMockChatInfo(): ChatInfo {
|
|
127
|
-
return new ChatInfo(12345, 'Test Chat', []);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function createMockTraceId(): TraceId {
|
|
131
|
-
return 'trace-123' as TraceId;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function createMockTextResponse(
|
|
135
|
-
chatInfo: ChatInfo,
|
|
136
|
-
traceId: TraceId,
|
|
137
|
-
action: IAction
|
|
138
|
-
): TextMessage {
|
|
139
|
-
return new TextMessage(
|
|
140
|
-
'Hello',
|
|
141
|
-
chatInfo,
|
|
142
|
-
traceId,
|
|
143
|
-
action,
|
|
144
|
-
undefined,
|
|
145
|
-
undefined
|
|
146
|
-
);
|
|
147
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, beforeEach } from 'bun:test';
|
|
2
|
-
import { TypedEventEmitter } from '../../../src/types/events';
|
|
3
|
-
import { IStorageClient } from '../../../src/types/storage';
|
|
4
|
-
import { Seconds } from '../../../src/types/timeValues';
|
|
5
|
-
import { ScheduledActionProcessor } from '../../../src/services/actionProcessors/scheduledActionProcessor';
|
|
6
|
-
import {
|
|
7
|
-
createMockStorage,
|
|
8
|
-
createMockScheduler,
|
|
9
|
-
createMockTelegramApi,
|
|
10
|
-
type MockScheduler
|
|
11
|
-
} from './processorTestHelpers';
|
|
12
|
-
|
|
13
|
-
// =============================================================================
|
|
14
|
-
// ScheduledActionProcessor Tests
|
|
15
|
-
// =============================================================================
|
|
16
|
-
|
|
17
|
-
describe('ScheduledActionProcessor', () => {
|
|
18
|
-
let processor: ScheduledActionProcessor;
|
|
19
|
-
let eventEmitter: TypedEventEmitter;
|
|
20
|
-
let storage: IStorageClient;
|
|
21
|
-
let scheduler: MockScheduler;
|
|
22
|
-
const chats = { chat1: 111, chat2: 222 };
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
eventEmitter = new TypedEventEmitter();
|
|
26
|
-
storage = createMockStorage();
|
|
27
|
-
scheduler = createMockScheduler();
|
|
28
|
-
processor = new ScheduledActionProcessor(
|
|
29
|
-
'scheduled-bot',
|
|
30
|
-
chats,
|
|
31
|
-
storage,
|
|
32
|
-
scheduler,
|
|
33
|
-
eventEmitter
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('constructor', () => {
|
|
38
|
-
test('should create processor with chats', () => {
|
|
39
|
-
expect(processor).toBeDefined();
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('initialize', () => {
|
|
44
|
-
test('should store api reference', () => {
|
|
45
|
-
const mockApi = createMockTelegramApi();
|
|
46
|
-
processor.initialize(mockApi, [], 3600 as Seconds);
|
|
47
|
-
|
|
48
|
-
// If no scheduled actions, no tasks should be created
|
|
49
|
-
expect(scheduler.createTaskCallCount()).toBe(0);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('should call initializeDependencies with api when no actions', () => {
|
|
53
|
-
const mockApi = createMockTelegramApi();
|
|
54
|
-
|
|
55
|
-
processor.initialize(mockApi, [], 3600 as Seconds);
|
|
56
|
-
|
|
57
|
-
// After initialize, the processor should still be defined
|
|
58
|
-
expect(processor).toBeDefined();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('edge cases', () => {
|
|
63
|
-
test('should handle empty chats object', () => {
|
|
64
|
-
const localProcessor = new ScheduledActionProcessor(
|
|
65
|
-
'empty-chats-bot',
|
|
66
|
-
{}, // Empty chats
|
|
67
|
-
createMockStorage(),
|
|
68
|
-
createMockScheduler(),
|
|
69
|
-
new TypedEventEmitter()
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
expect(localProcessor).toBeDefined();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('should handle no scheduled actions', () => {
|
|
76
|
-
const localScheduler = createMockScheduler();
|
|
77
|
-
const localProcessor = new ScheduledActionProcessor(
|
|
78
|
-
'no-actions-bot',
|
|
79
|
-
{ test: 123 },
|
|
80
|
-
createMockStorage(),
|
|
81
|
-
localScheduler,
|
|
82
|
-
new TypedEventEmitter()
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const mockApi = createMockTelegramApi();
|
|
86
|
-
localProcessor.initialize(mockApi, [], 3600 as Seconds);
|
|
87
|
-
|
|
88
|
-
// Should not create any tasks
|
|
89
|
-
expect(localScheduler.createTaskCallCount()).toBe(0);
|
|
90
|
-
expect(localScheduler.createOnetimeTaskCallCount()).toBe(0);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe('multi-chat configuration', () => {
|
|
95
|
-
test('should accept multiple chats in configuration', () => {
|
|
96
|
-
const multiChats = {
|
|
97
|
-
general: 100,
|
|
98
|
-
random: 200,
|
|
99
|
-
dev: 300
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const localProcessor = new ScheduledActionProcessor(
|
|
103
|
-
'multi-chat-bot',
|
|
104
|
-
multiChats,
|
|
105
|
-
createMockStorage(),
|
|
106
|
-
createMockScheduler(),
|
|
107
|
-
new TypedEventEmitter()
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
// The processor should be properly instantiated with multiple chats
|
|
111
|
-
expect(localProcessor).toBeDefined();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('event emission', () => {
|
|
116
|
-
test('should emit scheduledProcessingStarted when processing begins', () => {
|
|
117
|
-
const localEventEmitter = new TypedEventEmitter();
|
|
118
|
-
|
|
119
|
-
const localProcessor = new ScheduledActionProcessor(
|
|
120
|
-
'event-bot',
|
|
121
|
-
chats,
|
|
122
|
-
storage,
|
|
123
|
-
scheduler,
|
|
124
|
-
localEventEmitter
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
const mockApi = createMockTelegramApi();
|
|
128
|
-
localProcessor.initialize(mockApi, [], 3600 as Seconds);
|
|
129
|
-
|
|
130
|
-
// When initialized with scheduled actions, processing started would be emitted
|
|
131
|
-
// when the periodic task runs
|
|
132
|
-
expect(localProcessor).toBeDefined();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('should emit scheduledProcessingFinished when processing completes', () => {
|
|
136
|
-
const localEventEmitter = new TypedEventEmitter();
|
|
137
|
-
|
|
138
|
-
const localProcessor = new ScheduledActionProcessor(
|
|
139
|
-
'finish-bot',
|
|
140
|
-
chats,
|
|
141
|
-
storage,
|
|
142
|
-
scheduler,
|
|
143
|
-
localEventEmitter
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
const mockApi = createMockTelegramApi();
|
|
147
|
-
localProcessor.initialize(mockApi, [], 3600 as Seconds);
|
|
148
|
-
|
|
149
|
-
// When processing completes, scheduledProcessingFinished event is emitted
|
|
150
|
-
expect(localProcessor).toBeDefined();
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
});
|