-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathscheduled-message-recurring.ts
More file actions
43 lines (35 loc) · 1.3 KB
/
scheduled-message-recurring.ts
File metadata and controls
43 lines (35 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { createSDK, handleError } from "./utils";
const CHAT_GUID = process.env.CHAT_GUID || "any;-;+1234567890";
async function main() {
const sdk = createSDK();
sdk.on("ready", async () => {
try {
const tomorrow9am = new Date();
tomorrow9am.setDate(tomorrow9am.getDate() + 1);
tomorrow9am.setHours(9, 0, 0, 0);
const daily = await sdk.scheduledMessages.createScheduledMessage({
type: "send-message",
payload: {
chatGuid: CHAT_GUID,
message: "Good morning!",
method: "apple-script",
},
scheduledFor: tomorrow9am.getTime(),
schedule: {
type: "recurring",
intervalType: "daily", // hourly, daily, weekly, monthly, yearly
interval: 1,
},
});
console.log(`scheduled: ${daily.id}`);
console.log(`first: ${tomorrow9am.toLocaleString()}`);
console.log(`repeats: every day`);
} catch (error) {
handleError(error, "Failed to schedule recurring message");
}
await sdk.close();
process.exit(0);
});
await sdk.connect();
}
main().catch(console.error);