@ihazz/bitrix24 1.0.3 → 1.1.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/README.md +236 -42
- package/package.json +1 -1
- package/src/access-control.ts +31 -8
- package/src/api.ts +76 -7
- package/src/channel.ts +1025 -137
- package/src/commands.ts +7 -7
- package/src/config-schema.ts +24 -1
- package/src/config.ts +4 -2
- package/src/group-access.ts +279 -0
- package/src/history-cache.ts +122 -0
- package/src/i18n.ts +140 -50
- package/src/inbound-handler.ts +91 -8
- package/src/polling-service.ts +4 -0
- package/src/send-service.ts +14 -5
- package/src/types.ts +67 -3
- package/tests/access-control.test.ts +43 -0
- package/tests/api.test.ts +131 -0
- package/tests/channel-flow.test.ts +1692 -0
- package/tests/channel.test.ts +88 -2
- package/tests/config.test.ts +120 -0
- package/tests/group-access.test.ts +340 -0
- package/tests/history-cache.test.ts +117 -0
- package/tests/i18n.test.ts +55 -12
- package/tests/inbound-handler.test.ts +388 -3
- package/tests/polling-service.test.ts +38 -0
- package/tests/send-service.test.ts +17 -0
|
@@ -74,4 +74,42 @@ describe('PollingService', () => {
|
|
|
74
74
|
expect(onEvent).toHaveBeenCalledTimes(2);
|
|
75
75
|
expect(state.offset).toBe(11);
|
|
76
76
|
});
|
|
77
|
+
|
|
78
|
+
it('passes withUserEvents through to fetch polling', async () => {
|
|
79
|
+
tempHome = mkdtempSync(join(tmpdir(), 'b24-polling-agent-'));
|
|
80
|
+
process.env.HOME = tempHome;
|
|
81
|
+
|
|
82
|
+
const abortController = new AbortController();
|
|
83
|
+
const fetchEvents = vi.fn().mockImplementation(async () => {
|
|
84
|
+
abortController.abort();
|
|
85
|
+
return {
|
|
86
|
+
events: [],
|
|
87
|
+
lastEventId: 0,
|
|
88
|
+
hasMore: false,
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const api = { fetchEvents } as unknown as Bitrix24Api;
|
|
93
|
+
const service = new PollingService({
|
|
94
|
+
api,
|
|
95
|
+
webhookUrl: 'https://test.bitrix24.com/rest/1/token/',
|
|
96
|
+
bot: { botId: 7, botToken: 'bot_token' },
|
|
97
|
+
accountId: 'default',
|
|
98
|
+
pollingIntervalMs: 1,
|
|
99
|
+
pollingFastIntervalMs: 1,
|
|
100
|
+
withUserEvents: true,
|
|
101
|
+
onEvent: vi.fn(),
|
|
102
|
+
abortSignal: abortController.signal,
|
|
103
|
+
logger: silentLogger,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await service.start();
|
|
107
|
+
|
|
108
|
+
expect(fetchEvents).toHaveBeenCalledOnce();
|
|
109
|
+
expect(fetchEvents).toHaveBeenCalledWith(
|
|
110
|
+
'https://test.bitrix24.com/rest/1/token/',
|
|
111
|
+
{ botId: 7, botToken: 'bot_token' },
|
|
112
|
+
{ offset: 0, limit: 100, withUserEvents: true },
|
|
113
|
+
);
|
|
114
|
+
});
|
|
77
115
|
});
|
|
@@ -142,4 +142,21 @@ describe('SendService', () => {
|
|
|
142
142
|
await expect(service.answerCommandText(commandCtx, longText)).rejects.toThrow('follow-up failed');
|
|
143
143
|
expect(silentLogger.error).toHaveBeenCalled();
|
|
144
144
|
});
|
|
145
|
+
|
|
146
|
+
it('passes forwardMessages to the first outbound chunk', async () => {
|
|
147
|
+
(api.sendMessage as ReturnType<typeof vi.fn>).mockResolvedValueOnce(777);
|
|
148
|
+
|
|
149
|
+
await service.sendText(ctx, 'Forward this', {
|
|
150
|
+
convertMarkdown: false,
|
|
151
|
+
forwardMessages: [101, 102],
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
expect(api.sendMessage).toHaveBeenCalledWith(
|
|
155
|
+
ctx.webhookUrl,
|
|
156
|
+
ctx.bot,
|
|
157
|
+
ctx.dialogId,
|
|
158
|
+
'Forward this',
|
|
159
|
+
{ forwardMessages: [101, 102] },
|
|
160
|
+
);
|
|
161
|
+
});
|
|
145
162
|
});
|