-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathprivate-messages.js
53 lines (51 loc) · 1.31 KB
/
private-messages.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
53
import zulip from '../lib';
const config = {
username: process.env.ZULIP_USERNAME,
apiKey: process.env.ZULIP_API_KEY,
realm: process.env.ZULIP_REALM,
};
(async () => {
const z = await zulip(config);
// Send a message
const res = z.messages.send({
to: process.env.ZULIP_TEST_USERNAME,
type: 'private',
subject: 'Testing zulip-js',
content: 'Something is wrong....',
});
// Response includes Message ID
console.log(res);
// Fetch messages anchored around id (1 before, 1 after)
console.log(
await z.messages.retrieve({
from: process.env.ZULIP_TEST_USERNAME,
anchor: res.id,
narrow: [
{
operator: 'is',
operand: 'private',
},
],
num_before: 1,
num_after: 1,
})
);
// Fetch the most recent message
const mostRecentParams = {
anchor: 1000000000,
num_before: 1,
num_after: 1,
narrow: [
{
operator: 'is',
operand: 'private',
},
],
};
console.log(await z.messages.retrieve(mostRecentParams));
// Fetch the pointer for the user
const resp = await z.users.me.pointer.retrieve();
// Fetch messages anchored around the last read message (1 before, 1 after)
mostRecentParams.anchor = resp.pointer;
console.log(await z.messages.retrieve(mostRecentParams));
})();