CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/messages/send.ts
Views: 791
1
/*
2
Send an internal message to any one or more user of the site.
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import getParams from "lib/api/get-params";
7
import { SuccessStatus } from "lib/api/status";
8
import send from "@cocalc/server/messages/send";
9
import throttle from "@cocalc/util/api/throttle";
10
11
export default async function handle(req, res) {
12
try {
13
const id = await get(req);
14
res.json({ ...SuccessStatus, id });
15
} catch (err) {
16
res.json({ error: `${err.message ? err.message : err}` });
17
return;
18
}
19
}
20
21
async function get(req) {
22
const from_id = await getAccountId(req);
23
24
if (!from_id) {
25
throw Error("Must be signed in to send messages");
26
}
27
28
throttle({
29
account_id: from_id,
30
endpoint: "messages/send",
31
});
32
const { to_ids, subject, body, reply_id } = getParams(req);
33
return await send({
34
to_ids: to_ids ?? [from_id],
35
from_id,
36
subject,
37
body,
38
reply_id,
39
});
40
}
41
42