Path: blob/master/src/packages/next/pages/api/v2/messages/get.ts
1454 views
/*1Get your messages via an api2*/34import getAccountId from "lib/account/get-account";5import getParams from "lib/api/get-params";6import { SuccessStatus } from "lib/api/status";7import getMessages from "@cocalc/server/messages/get";8import throttle from "@cocalc/util/api/throttle";910export default async function handle(req, res) {11try {12const messages = await get(req);13res.json({ ...SuccessStatus, messages });14} catch (err) {15res.json({ error: `${err.message ? err.message : err}` });16return;17}18}1920async function get(req) {21const account_id = await getAccountId(req);2223if (!account_id) {24throw Error("Must be signed in to get messages");25}2627throttle({28account_id,29endpoint: "messages/get",30});31const { limit, offset, type, cutoff } = getParams(req);32return await getMessages({ account_id, limit, offset, type, cutoff });33}343536