From 091ecc51613d180d795ab7fa5fd295367ca2cb77 Mon Sep 17 00:00:00 2001 From: Danil Pismenny Date: Mon, 2 Nov 2026 21:08:39 +0300 Subject: [PATCH] fix: pass `schedule` Date to mtcute so --schedule really schedules mtcute's high-level sendText/sendMedia read `schedule` (Date, or a number in milliseconds). tgcli passed `scheduleDate`, which is ignored, so scheduled messages were delivered immediately while still returning a message id. resolveScheduleDate() yields unix seconds, so convert to a Date. The low-level messages.sendMedia request keeps `scheduleDate` (raw TL name). Tests asserted the wrong param name; fixed to `schedule: Date`. Co-Authored-By: Claude Sonnet 5.5 --- telegram-client.js | 8 ++++++-- tests/send-messages.test.js | 12 ++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/telegram-client.js b/telegram-client.js index 761db93..fc718bb 100644 --- a/telegram-client.js +++ b/telegram-client.js @@ -276,7 +276,9 @@ function buildTextSendParams(options = {}) { if (options.silent) params.silent = true; if (options.noForwards || options.noforwards) params.forbidForwards = true; const scheduleDate = resolveScheduleDate(options); - if (scheduleDate) params.scheduleDate = scheduleDate; + // mtcute's high-level send methods take `schedule` (Date, or a number in MILLISECONDS), + // not `scheduleDate`; resolveScheduleDate() returns unix seconds, so pass a Date. + if (scheduleDate) params.schedule = new Date(scheduleDate * 1000); return Object.keys(params).length ? params : undefined; } @@ -289,7 +291,9 @@ function buildMediaSendParams(options = {}) { if (options.silent) params.silent = true; if (options.noForwards || options.noforwards) params.forbidForwards = true; const scheduleDate = resolveScheduleDate(options); - if (scheduleDate) params.scheduleDate = scheduleDate; + // mtcute's high-level send methods take `schedule` (Date, or a number in MILLISECONDS), + // not `scheduleDate`; resolveScheduleDate() returns unix seconds, so pass a Date. + if (scheduleDate) params.schedule = new Date(scheduleDate * 1000); if (options.captionAbove) params.invert = true; return Object.keys(params).length ? params : undefined; } diff --git a/tests/send-messages.test.js b/tests/send-messages.test.js index 04627cf..60bb391 100644 --- a/tests/send-messages.test.js +++ b/tests/send-messages.test.js @@ -206,10 +206,10 @@ describe('sendTextMessage new send parameters', () => { expect(tc.client.sendText).toHaveBeenCalledWith('@chat', 'hello', { forbidForwards: true }); }); - it('--schedule passes scheduleDate as unix timestamp in params', async () => { + it('--schedule passes `schedule` (Date) to mtcute, not the ignored `scheduleDate`', async () => { const scheduleDate = Math.floor(Date.now() / 1000) + 3600; await tc.sendTextMessage('@chat', 'hello', { scheduleDate }); - expect(tc.client.sendText).toHaveBeenCalledWith('@chat', 'hello', { scheduleDate }); + expect(tc.client.sendText).toHaveBeenCalledWith('@chat', 'hello', { schedule: new Date(scheduleDate * 1000) }); }); it('combined silent + replyTo passes both in params', async () => { @@ -233,7 +233,7 @@ describe('sendTextMessage new send parameters', () => { expect(tc.client.sendText).toHaveBeenCalledWith('@chat', 'hello', { silent: true, forbidForwards: true, - scheduleDate, + schedule: new Date(scheduleDate * 1000), }); }); @@ -246,7 +246,7 @@ describe('sendTextMessage new send parameters', () => { const iso = '2027-01-15T09:00:00Z'; const expected = Math.floor(new Date(iso).getTime() / 1000); await tc.sendTextMessage('@chat', 'hello', { schedule: iso }); - expect(tc.client.sendText).toHaveBeenCalledWith('@chat', 'hello', { scheduleDate: expected }); + expect(tc.client.sendText).toHaveBeenCalledWith('@chat', 'hello', { schedule: new Date(expected * 1000) }); }); it('no new params still sends undefined params (backward compat)', async () => { @@ -281,7 +281,7 @@ describe('sendFileMessage new send parameters', () => { it('--schedule passes scheduleDate in params', async () => { const scheduleDate = Math.floor(Date.now() / 1000) + 3600; await tc.sendFileMessage('@chat', temp.filePath, { scheduleDate }); - expect(tc.client.sendMedia).toHaveBeenCalledWith('@chat', expect.anything(), { scheduleDate }); + expect(tc.client.sendMedia).toHaveBeenCalledWith('@chat', expect.anything(), { schedule: new Date(scheduleDate * 1000) }); }); it('--caption-above passes invertMedia: true in params', async () => { @@ -325,7 +325,7 @@ describe('sendFileMessage new send parameters', () => { const iso = '2027-06-01T12:00:00Z'; const expected = Math.floor(new Date(iso).getTime() / 1000); await tc.sendFileMessage('@chat', temp.filePath, { schedule: iso }); - expect(tc.client.sendMedia).toHaveBeenCalledWith('@chat', expect.anything(), { scheduleDate: expected }); + expect(tc.client.sendMedia).toHaveBeenCalledWith('@chat', expect.anything(), { schedule: new Date(expected * 1000) }); }); it('combined silent + noforwards + replyTo passes all in params', async () => {