-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathsend-and-recieve.js
52 lines (46 loc) · 1.05 KB
/
send-and-recieve.js
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
import zulip from '../../lib';
if (process.argv.length < 7) {
console.log(
'Usage: $node examples/typing-notifications/send-and-recieve.js realm-url sender-username sender-API-key recipient-username recipient-API-key'
);
process.exit(1);
}
const [
,
,
realm,
sender,
senderAPIKey,
recipient,
recipientAPIKey,
] = process.argv;
(async () => {
const senderClient = await zulip({
username: sender,
apiKey: senderAPIKey,
realm,
});
const recipientClient = await zulip({
username: recipient,
apiKey: recipientAPIKey,
realm,
});
const { user_id: recipientId } = await recipientClient.users.me.getProfile();
const res = await recipientClient.queues.register({
event_types: ['typing'],
});
console.log(`Registered queue for ${recipient}`);
const queueID = res.queue_id;
console.log(
await senderClient.typing.send({
to: [recipientId],
op: 'start',
})
);
console.log(
await recipientClient.events.retrieve({
queue_id: queueID,
last_event_id: -1,
})
);
})();