-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbackground-set.ts
More file actions
56 lines (45 loc) · 1.9 KB
/
background-set.ts
File metadata and controls
56 lines (45 loc) · 1.9 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
44
45
46
47
48
49
50
51
52
53
54
55
56
import fs from "node:fs";
import path from "node:path";
import { createSDK, handleError } from "./utils";
const CHAT_GUID = process.env.CHAT_GUID || "any;-;+1234567890";
const IMAGE_PATH = process.env.IMAGE_PATH || path.join(__dirname, "test-image.png");
async function main() {
const sdk = createSDK();
sdk.on("ready", async () => {
try {
if (!fs.existsSync(IMAGE_PATH)) {
console.error(`File not found: ${IMAGE_PATH}`);
await sdk.close();
process.exit(1);
}
console.log(`Setting background for chat: ${CHAT_GUID}`);
console.log(`Using image: ${IMAGE_PATH}`);
const currentBg = await sdk.chats.getBackground(CHAT_GUID);
console.log("\nCurrent background info:");
console.log(` Has background: ${currentBg.hasBackground}`);
if (currentBg.hasBackground) {
console.log(` Background ID: ${currentBg.backgroundId}`);
console.log(` Image URL: ${currentBg.imageUrl}`);
}
console.log("\nSetting new background...");
await sdk.chats.setBackground(CHAT_GUID, {
filePath: IMAGE_PATH,
});
console.log("Background set successfully!");
console.log("\nVerifying new background...");
const newBg = await sdk.chats.getBackground(CHAT_GUID);
console.log("New background info:");
console.log(` Has background: ${newBg.hasBackground}`);
if (newBg.hasBackground) {
console.log(` Background ID: ${newBg.backgroundId}`);
console.log(` Image URL: ${newBg.imageUrl}`);
}
} catch (error) {
handleError(error, "Failed to set background");
}
await sdk.close();
process.exit(0);
});
await sdk.connect();
}
main().catch(console.error);