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