UNPKG

rblx.js

Version:

A JavaScript wrapper for interacting with the ROBLOX OpenCloud API.

38 lines (37 loc) 1.39 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const urlcat_1 = __importDefault(require("urlcat")); const axios_1 = __importDefault(require("axios")); const BASE_URL = "https://apis.roblox.com/messaging-service/v1/universes"; async function main(apiKey, universeid, topic, message) { try { BigInt(universeid); } catch (e) { throw new Error("Invalid universeid: " + universeid); } const res_url = (0, urlcat_1.default)(BASE_URL, "/:universeid/topics/topic", { universeid, topic }); const config = { headers: { "x-api-key": apiKey } }; const response = await axios_1.default.post(res_url, { "message": message }, config); if (response.status == 400) { throw new Error("Invalid request."); } if (response.status == 401) { throw new Error("API key not valid for operation, user does not have authorization."); } if (response.status == 403) { throw new Error("Publish is not allowed on universe."); } if (response.status == 500) { throw new Error("Server internal error / Unknown error."); } return await response.data; } exports.default = main;