This repository was archived by the owner on Mar 12, 2026. It is now read-only.
forked from lucianocosta/node-red-contrib-rocketchat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrocketchat.js
More file actions
134 lines (131 loc) · 2.5 KB
/
rocketchat.js
File metadata and controls
134 lines (131 loc) · 2.5 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const axios = require('axios');
module.exports = ({ host, user, token }) => ({
async spotlight(query) {
const { data } = await axios.get(`${host}/api/v1/spotlight`, {
params: {
query
},
headers: {
'X-Auth-Token': token,
'X-User-Id': user
}
});
return data;
},
async createIM({ username }) {
const { data } = await axios.post(
`${host}/api/v1/im.create`,
{ username },
{
headers: {
'X-Auth-Token': token,
'X-User-Id': user
}
}
);
return data;
},
async send({ roomId, text, attachments }) {
const { data } = await axios.post(
`${host}/api/v1/chat.postMessage`,
{ roomId, text, attachments },
{
headers: {
'X-Auth-Token': token,
'X-User-Id': user
}
}
);
return data;
},
async getSubscriptions() {
const { data } = await axios.get(`${host}/api/v1/subscriptions.get`, {
headers: {
'X-Auth-Token': token,
'X-User-Id': user
}
});
return data;
},
async getSubscription({ roomId }) {
const { data } = await axios.get(`${host}/api/v1/subscriptions.getOne`, {
params: {
roomId
},
headers: {
'X-Auth-Token': token,
'X-User-Id': user
}
});
return data;
},
async getUnreadMessages({ roomId, oldest, type }) {
try {
let endpoint;
switch (type) {
case 'g':
endpoint = 'groups';
break;
case 'd':
endpoint = 'im';
break;
default:
endpoint = 'channels';
break;
}
const { data } = await axios.get(`${host}/api/v1/${endpoint}.history`, {
params: {
roomId,
oldest
},
headers: {
'X-Auth-Token': token,
'X-User-Id': user
}
});
return data;
} catch ({ message }) {
console.error(message);
return { success: false, error: { message } };
}
},
async markAsRead({ rid }) {
const { data } = await axios.post(
`${host}/api/v1/subscriptions.read`,
{ rid },
{
headers: {
'X-Auth-Token': token,
'X-User-Id': user
}
}
);
return data;
},
async createChannel({ name, members, readOnly = false }) {
const { data } = await axios.post(
`${host}/api/v1/channels.create`,
{ name, members, readOnly },
{
headers: {
'X-Auth-Token': token,
'X-User-Id': user
}
}
);
return data;
},
async createGroup({ name, members, readOnly = false }) {
const { data } = await axios.post(
`${host}/api/v1/groups.create`,
{ name, members, readOnly },
{
headers: {
'X-Auth-Token': token,
'X-User-Id': user
}
}
);
return data;
}
});