-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmessage-reply.ts
More file actions
48 lines (37 loc) · 1.49 KB
/
message-reply.ts
File metadata and controls
48 lines (37 loc) · 1.49 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
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 {
// Send first message
const firstMessage = await sdk.messages.sendMessage({
chatGuid: CHAT_GUID,
message: "What's your favorite color?",
});
console.log(`sent: ${firstMessage.guid}`);
await new Promise((resolve) => setTimeout(resolve, 1000));
// Send second message
const secondMessage = await sdk.messages.sendMessage({
chatGuid: CHAT_GUID,
message: "Also, what's your favorite food?",
});
console.log(`sent: ${secondMessage.guid}`);
await new Promise((resolve) => setTimeout(resolve, 2000));
// Reply to the FIRST message
const replyMessage = await sdk.messages.sendMessage({
chatGuid: CHAT_GUID,
message: "My favorite color is blue!",
selectedMessageGuid: firstMessage.guid,
});
console.log(`\nreplied: ${replyMessage.guid}`);
console.log(`replying to: ${firstMessage.guid.substring(0, 20)}...`);
} catch (error) {
handleError(error, "Failed to send reply");
}
await sdk.close();
process.exit(0);
});
await sdk.connect();
}
main().catch(console.error);