Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions telegram-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions tests/send-messages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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),
});
});

Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading