### Set up Node.js Project for Fluxer Bot Source: https://docs.fluxer.app/quickstart Commands to create a new Node.js project directory, initialize a package.json file, and install necessary @discordjs/ core packages for Fluxer API interaction. ```bash mkdir fluxer-quickstart cd fluxer-quickstart echo '{ "name": "fluxer-quickstart", "version": "1.0.0", "type": "module", "main": "bot.js" }' > package.json npm install @discordjs/core @discordjs/rest @discordjs/ws ``` -------------------------------- ### Run Fluxer Bot Source: https://docs.fluxer.app/quickstart Command to execute the Node.js bot script. Ensure the FLUXER_BOT_TOKEN environment variable is set in the same shell before running. ```bash node bot.js ``` -------------------------------- ### Configure Fluxer Bot Token Environment Variable Source: https://docs.fluxer.app/quickstart Instructions for setting the FLUXER_BOT_TOKEN environment variable on different operating systems. This token is crucial for authenticating your bot with the Fluxer API. ```bash # macOS/Linux: export FLUXER_BOT_TOKEN="your_bot_token_here" # Windows (Command Prompt): set FLUXER_BOT_TOKEN="your_bot_token_here" # Windows (PowerShell): $Env:FLUXER_BOT_TOKEN = "your_bot_token_here" ``` -------------------------------- ### Write Minimal Fluxer Bot with JavaScript Source: https://docs.fluxer.app/quickstart A JavaScript code snippet that sets up a Fluxer bot using @discordjs/core. It connects to the Fluxer Gateway, listens for 'ping' messages, and responds with 'pong'. It also logs the bot's username upon successful connection. ```javascript import { Client, GatewayDispatchEvents } from "@discordjs/core"; import { REST } from "@discordjs/rest"; import { WebSocketManager } from "@discordjs/ws"; const token = process.env.FLUXER_BOT_TOKEN; if (!token) { console.error("Missing FLUXER_BOT_TOKEN environment variable."); process.exit(1); } const rest = new REST({ api: "https://api.fluxer.app", version: "1", }).setToken(token); const gateway = new WebSocketManager({ token, intents: 0, // Fluxer has no intents yet rest, version: "1", }); export const client = new Client({ rest, gateway }); client.on(GatewayDispatchEvents.MessageCreate, async ({ api, data }) => { if (data.content === "ping") { await api.channels.createMessage(data.channel_id, { content: "pong" }); } }); client.on(GatewayDispatchEvents.Ready, ({ data }) => { console.log(`Logged in as ${data.user.username}#${data.user.discriminator}`); }); gateway.connect(); ``` -------------------------------- ### Get Default Avatar URL (JavaScript) Source: https://docs.fluxer.app/api-reference Generates the URL for a default avatar based on a user ID. It uses the modulo operator to select one of six available default avatar images. ```javascript function getDefaultAvatarUrl(userId: string): string { const index = Number(BigInt(userId) % 6n); return `https://fluxerstatic.com/avatars/${index}.png`; } ``` -------------------------------- ### Authentication Source: https://docs.fluxer.app/api-reference Instructions on how to authenticate API requests using a bot token in the `Authorization` header. ```APIDOC ## Authentication Most API requests require authentication. Send your bot token in the `Authorization` header: ``` Authorization: Bot YOUR_BOT_TOKEN ``` Replace `YOUR_BOT_TOKEN` with the token from **User Settings > Applications** in the Fluxer web/desktop app. Keep bot tokens secret. Don't commit them to source control or ship them in client-side code. ``` -------------------------------- ### User Content CDN - Query Parameters Source: https://docs.fluxer.app/api-reference The Fluxer CDN endpoints support query parameters for on-the-fly media transformation and optimization. ```APIDOC ### Query Parameters CDN endpoints support the following query parameters for transforming and optimizing media on the fly: ``` -------------------------------- ### File Uploads Source: https://docs.fluxer.app/api-reference Information on file upload limits and methods. ```APIDOC ## File Uploads ### File Size Limits - **Free Users**: Default limit is 25 MiB per file. - **Premium Users**: Default limit is 500 MiB per file. ### Upload Limits - At most 10 files can be uploaded in a single message. ### Multipart Form Data Upload Upload files directly with your message using `multipart/form-data`. ### Example Request Body ```javascript const form = new FormData(); form.append( 'payload_json', JSON.stringify({ content: 'Check out these files!', attachments: [ {id: 0, filename: 'cat.png', description: 'A cute cat'}, {id: 1, filename: 'dog.jpg', description: 'A good dog'}, ], }), ); form.append('files[0]', catImageBlob, 'cat.png'); form.append('files[1]', dogImageBlob, 'dog.jpg'); const response = await fetch('https://api.fluxer.app/v1/channels/123456789012345678/messages', { method: 'POST', headers: { Authorization: 'Bot YOUR_BOT_TOKEN', }, body: form, }); ``` ``` -------------------------------- ### Multipart Form Data Upload (JavaScript) Source: https://docs.fluxer.app/api-reference Demonstrates how to upload files to a channel using multipart form data. This method is suitable for sending multiple files along with message content and attachment metadata. ```javascript const form = new FormData(); form.append( 'payload_json', JSON.stringify({ content: 'Check out these files!', attachments: [ {id: 0, filename: 'cat.png', description: 'A cute cat'}, {id: 1, filename: 'dog.jpg', description: 'A good dog'}, ], }), ); form.append('files[0]', catImageBlob, 'cat.png'); form.append('files[1]', dogImageBlob, 'dog.jpg'); const response = await fetch('https://api.fluxer.app/v1/channels/123456789012345678/messages', { method: 'POST', headers: { Authorization: 'Bot YOUR_BOT_TOKEN', }, body: form, }); ``` -------------------------------- ### Static Assets CDN - Default Avatars Source: https://docs.fluxer.app/api-reference Access default avatars through the Static Assets CDN. ```APIDOC ## Static Assets CDN - Default Avatars ### Base URL `https://fluxerstatic.com` ### CDN Endpoints #### Default Avatar - **Path Template**: `/avatars/{index}.png` - **Supported Formats**: PNG - **Description**: `{index}` is a number from `0` to `5`, representing the six default avatar options. Use `index = user_id % 6` to select a default avatar based on the user's ID. ### Example Usage ```javascript function getDefaultAvatarUrl(userId: string): string { const index = Number(BigInt(userId) % 6n); return `https://fluxerstatic.com/avatars/${index}.png`; } ``` ``` -------------------------------- ### Snowflakes and Pagination Source: https://docs.fluxer.app/api-reference Explanation of Fluxer's use of Snowflakes for IDs and how they can be used for pagination. ```APIDOC ## Snowflakes Fluxer uses Twitter Snowflakes as IDs for users, messages, channels, and other entities. Within a single entity type (for example, messages), Snowflakes are unique. Different entity types may share the same numeric Snowflake, so always track which entity an ID refers to. Snowflakes are 64-bit unsigned integers that encode a timestamp plus some extra bits. In JSON, they're always sent as strings to avoid precision issues. Treat them as opaque strings unless you need to decode them. Component| Bits| Description ---|---|--- Timestamp| 42| Milliseconds since the Fluxer epoch (`1420070400000`, the first second of 2015) Worker ID| 5| ID of the worker that generated the Snowflake Process ID| 5| ID of the process that generated the Snowflake Sequence Number| 12| Counter for IDs generated in the same millisecond If you decode the timestamp part, you can tell when a resource was created. ```javascript function snowflakeToTimestamp(snowflake: string): number { const fluxerEpoch = 1420070400000n; const timestamp = (BigInt(snowflake) >> 22n) + fluxerEpoch; return Number(timestamp); } ``` ### Pagination with Snowflakes Many API endpoints return lists. These endpoints accept `before`, `after`, and `limit` query parameters. Check the individual endpoint docs to see which ones support pagination. Because Snowflake IDs encode timestamps, you can generate Snowflakes from timestamps to paginate by time: ```javascript function timestampToSnowflake(timestamp: number): string { const fluxerEpoch = 1420070400000n; snowflake = (BigInt(timestamp) - fluxerEpoch) << 22n; return snowflake.toString(); } const currentTimeMs = Date.now(); const currentSnowflake = timestampToSnowflake(currentTimeMs); ``` To specify the beginning of time, use the Snowflake `0`. ``` -------------------------------- ### Message Formatting Source: https://docs.fluxer.app/api-reference Fluxer supports rich message formatting using Markdown-like syntax, with compatibility intended for easy porting from Discord-flavored Markdown. ```APIDOC ## Message Formatting Fluxer supports rich message formatting using Markdown-style syntax. Compatibility with most Discord-flavored Markdown is intentional so you can port bots and integrations with minimal changes. ### Format Types In addition to standard formatting such as bold, italics, underline, strikethrough, inline code, code blocks, blockquotes, headings, lists, and links, Fluxer supports the following formatting options: Type| Syntax| Example ---|---|--- Spoiler| `||text||`| `||spoiler||` (hidden until clicked) Subtext (small gray text)| `-# your text`| `-# extra context / footnote` Email link| ``| `` Phone link| `<+1234567890>`| `<+1234567890>` Mention user| `<@user_id>`| `<@123456789012345678>` Mention channel| `<#channel_id>`| `<#123456789012345678>` Mention role| `<@&role_id>`| `<@&123456789012345678>` Standard emoji| Unicode emoji| 😄 Custom emoji| `<:name:emoji_id>`| `<:custom_emoji:123456789012345678>` Custom emoji (animated)| ``| `` Unix timestamp| ``| `` Unix timestamp (styled)| ``| `` ### Timestamp Styles When using Unix timestamps, you can specify a style character to control how the timestamp is displayed: Style| Description| Example Output ---|---|--- `t`| Short time| 16:29 `T`| Medium time| 16:29:00 `d`| Short date| 10/21/2015 `D`| Long date| October 21, 2015 `f`*| Long date, short time| October 21, 2015 at 16:29 `F`| Full date, short time| Wednesday, October 21, 2015 at 16:29 `s`| Short date, short time| 10/21/2015, 16:29 `S`| Short date, medium time| 10/21/2015, 16:29:00 `R`| Relative time| 2 hours ago * Default if no style is provided. ``` -------------------------------- ### Image Query Schema Source: https://docs.fluxer.app/api-reference Endpoints for Avatar, Icon, Banner, Splash, and Emoji support the ImageQuerySchema for image transformations. ```APIDOC ## Image Query Schema Parameters ### Description Supports transformations for Avatar, Icon, Banner, Splash, and Emoji endpoints. ### Parameters #### Query Parameters - **size** (integer) - Optional - The desired width in pixels. Must be one of: 16, 20, 22, 24, 28, 32, 40, 44, 48, 56, 60, 64, 80, 96, 100, 128, 160, 240, 256, 300, 320, 480, 512, 600, 640, 1024, 1280, 1536, 2048, 3072, 4096. The image will be resized proportionally. - **quality** (string) - Optional - Image quality preset. Options: `high` (80% quality), `low` (20% quality), `lossless` (100% quality). Default: `high`. - **animated** (boolean) - Optional - Whether to preserve animation for WebP images. Note: GIF images are always animated regardless of this parameter. Default: `false`. ``` -------------------------------- ### User Content CDN - Endpoints Source: https://docs.fluxer.app/api-reference This section details the various CDN endpoints available for accessing different types of user-uploaded media, including supported formats. ```APIDOC ### CDN Endpoints Resource Type| Path Template| Supported Formats ---|---|--- User Avatar| `/avatars/{user_id}/{avatar_hash}.{ext}`| PNG, JPEG, WebP, GIF Guild Icon| `/icons/{guild_id}/{icon_hash}.{ext}`| PNG, JPEG, WebP, GIF Guild Banner| `/banners/{guild_id}/{banner_hash}.{ext}`| PNG, JPEG, WebP, GIF Guild Splash| `/splashes/{guild_id}/{splash_hash}.{ext}`| PNG, JPEG, WebP, GIF Guild Embed Splash| `/embed-splashes/{guild_id}/{embed_splash_hash}.{ext}`| PNG, JPEG, WebP Custom Emoji| `/emojis/{emoji_id}.{ext}`| PNG, JPEG, WebP, GIF Sticker| `/stickers/{sticker_id}.{ext}`| WebP, GIF Guild Member Avatar| `/guilds/{guild_id}/users/{user_id}/avatars/{avatar_hash}.{ext}`| PNG, JPEG, WebP, GIF Guild Member Banner| `/guilds/{guild_id}/users/{user_id}/banners/{banner_hash}.{ext}`| PNG, JPEG, WebP, GIF Attachment| `/attachments/{channel_id}/{attachment_id}/{filename}`| Various All CDN endpoints support query parameters for dynamic image transformation and optimization. ``` -------------------------------- ### Image Data URI Scheme Source: https://docs.fluxer.app/api-reference Illustrates the format for image data URIs, which embed image data directly within a URL. This format supports PNG, JPEG, WebP, and GIF. ```plaintext data:image/{format};base64,{base64_data} ``` -------------------------------- ### API Base URL and Versioning Source: https://docs.fluxer.app/api-reference All HTTP API requests go through the same base URL. Fluxer uses versioned API endpoints, with the current version being `v1`. ```APIDOC ## Base URL All HTTP API requests go through the same base URL: ``` https://api.fluxer.app ``` ## API Versioning Fluxer uses versioned API endpoints. The current version is `v1`, and all documented endpoints are prefixed with `/v1/`. ``` GET /v1/... ``` If you omit the version prefix, you'll hit the latest stable version. That can change over time, so pin a version like `/v1/` for anything you don't want to break unexpectedly. ``` -------------------------------- ### User Content CDN - Base URL Source: https://docs.fluxer.app/api-reference User-uploaded media content is accessible via the Fluxer User Content CDN at the specified base URL. ```APIDOC ## User Content CDN ### Base URL ``` https://fluxerusercontent.com ``` All user-uploaded media content is served through the User Content CDN at the above base URL. ``` -------------------------------- ### Gateway API (WebSocket) Source: https://docs.fluxer.app/api-reference Fluxer provides a Gateway API that allows clients to establish and maintain a persistent WebSocket connection for receiving real-time events. ```APIDOC ## Gateway API (WebSocket) Fluxer's Gateway API lets you maintain a long-lived WebSocket connection for real-time events. For how to connect and interact, see the Gateway API documentation. ``` -------------------------------- ### Using Attachments in Embeds Source: https://docs.fluxer.app/api-reference Referencing uploaded files within embed objects. ```APIDOC ## Using Attachments in Embeds ### Description Use the special `attachment://{filename}` URL format to reference uploaded files within embed objects. Only PNG, JPEG, WebP, and GIF image formats are supported. ### Example Embed Structure ```json { "embeds": [ { "title": "Look at this image", "image": { "url": "attachment://cat.png" } } ] } ``` ``` -------------------------------- ### Backwards Compatibility Source: https://docs.fluxer.app/api-reference New response fields in the Fluxer API are backwards-compatible and should be ignored by clients if unrecognized. Breaking changes are announced in advance. ```APIDOC ## Backwards Compatibility New response fields (documented or not) are backwards-compatible. Your client should ignore fields it doesn't recognize. Breaking changes will be announced in advance, with a migration period where old and new versions both work. ``` -------------------------------- ### External Query Schema for Attachments Source: https://docs.fluxer.app/api-reference Attachment endpoints support flexible transformations via the ExternalQuerySchema. ```APIDOC ## External Query Schema Parameters for Attachments ### Description Supports flexible transformations for attachment endpoints. ### Parameters #### Query Parameters - **width** (integer) - Optional - The desired width in pixels (1-4096). If only width is specified, height is calculated to maintain aspect ratio. - **height** (integer) - Optional - The desired height in pixels (1-4096). If only height is specified, width is calculated to maintain aspect ratio. - **format** (string) - Optional - Convert the image to the specified format. Options: `png`, `jpg`, `jpeg`, `webp`, `gif`. - **quality** (string) - Optional - Image quality preset. Options: `high` (80% quality), `low` (20% quality), `lossless` (100% quality). Default: `lossless`. - **animated** (boolean) - Optional - Whether to preserve animation for GIF and WebP images. Must be set to `true` to preserve animation in attachments. Default: `false`. **Note:** If no transformations are specified (no `width`, `height`, `format`, or `quality` other than `lossless`), the original file is served directly. ``` -------------------------------- ### Image Data URI Scheme Source: https://docs.fluxer.app/api-reference Image data is represented using a data URI scheme. ```APIDOC ## Image Data URI Scheme ### Description Supports PNG, JPEG, WebP, and GIF formats. Consists of a prefix indicating the media type and encoding, followed by the base64-encoded image data. ### Format `data:image/{format};base64,{base64_data}` **Note:** Replace `{format}` with the actual image format (e.g., `png`, `jpeg`, `webp`, `gif`) and `{base64_data}` with the base64-encoded string of the image. ``` -------------------------------- ### HTTP API - User Agent Source: https://docs.fluxer.app/api-reference When making HTTP requests to the Fluxer API, it is required to set a custom User-Agent header to identify your application. ```APIDOC ## HTTP API - User Agent When making HTTP requests, set a custom `User-Agent` header that identifies your application. Example: ``` User-Agent: MyFluxerBot ($url, $version) ``` ``` -------------------------------- ### Nullable & Optional Fields Convention Source: https://docs.fluxer.app/api-reference Fluxer API follows a convention for nullable and optional fields, similar to Discord's API, to indicate their presence and nullability in responses. ```APIDOC ## Nullable & Optional Fields To stay close to Discord's API docs, the Fluxer API uses this convention for nullable and optional fields in tables: Field Name| Type| Description ---|---|--- `optional_field?`| string| An optional field that may be missing in the response `nullable_field`| ?string| A nullable field that may be `null` in the response, but is always present `optional_nullable_field?`| ?string| An optional field that may be missing or `null` in the response ``` -------------------------------- ### Encryption Source: https://docs.fluxer.app/api-reference Information regarding the required use of TLS for all HTTP and WebSocket connections to Fluxer. ```APIDOC ## Encryption All HTTP and WebSocket connections to Fluxer must use TLS (`https://` and `wss://`). The minimum supported version is TLS 1.2. Plain `http://` and `ws://` endpoints are not available. ``` -------------------------------- ### ISO 8601 Timestamps Source: https://docs.fluxer.app/api-reference Information on the format of timestamps returned in Fluxer API responses. ```APIDOC ## ISO 8601 Timestamps Timestamps in Fluxer API responses use the ISO 8601 format in UTC. Parse them with standard libraries in your language of choice. ``` -------------------------------- ### Attachment URL in Embeds (JSON) Source: https://docs.fluxer.app/api-reference Shows how to reference an uploaded file within an embed object using the `attachment://` URL format. This allows displaying images that have been uploaded with a message. ```json { "embeds": [ { "title": "Look at this image", "image": { "url": "attachment://cat.png" } } ] } ``` -------------------------------- ### Editing Messages with Attachments Source: https://docs.fluxer.app/api-reference How to manage attachments when editing messages. ```APIDOC ## Editing Messages with Attachments ### Description When `PATCH`ing messages with new attachments, existing attachments must be specified. Any attachments not specified will be removed and replaced with the specified list. If you do not specify the `attachments` field at all, the existing attachments will remain unchanged. ``` -------------------------------- ### Error Responses Source: https://docs.fluxer.app/api-reference Details on how Fluxer handles generic and form validation errors, including the structure of error responses. ```APIDOC ## Error Responses ### Generic Error Response When a request fails, the API returns an HTTP status code plus a JSON body with error details: ```json { "code": "UNKNOWN_USER", "message": "Unknown User" } ``` `code` is stable and machine-readable. `message` is for humans and may change, so don't rely on it for program logic. ### Form Validation Errors For endpoints that accept form data, failed validation returns `400 Bad Request` and a list of field-level errors: ```json { "code": "INVALID_FORM_BODY", "message": "Input Validation Error", "errors": [ {"path": "username", "message": "Username must be at least 3 characters long."}, {"path": "email", "message": "Email must be a valid email address."} ] } ``` For nested structures, `path` uses dot and index notation to point at the field that failed: ```json { "code": "INVALID_FORM_BODY", "message": "Input Validation Error", "errors": [ {"path": "profile.address.street", "message": "Street is required."}, {"path": "items.0.quantity", "message": "Quantity must be a positive integer."} ] } ``` Treat `code` as the stable part of the error and use `errors[*].path` to locate invalid inputs. ``` -------------------------------- ### HTTP API - Content Type Source: https://docs.fluxer.app/api-reference The Content-Type header should be set appropriately based on the request body format when interacting with the Fluxer API. ```APIDOC ## HTTP API - Content Type Set the `Content-Type` header to `application/json`, `application/x-www-form-urlencoded`, or `multipart/form-data` as appropriate for your request body. ``` -------------------------------- ### HTTP API - Rate Limits Source: https://docs.fluxer.app/api-reference Fluxer API enforces rate limits, which are communicated via HTTP headers. Exceeding these limits will result in a '429 Too Many Requests' response. ```APIDOC ## HTTP API - Rate Limits Rate limits are reported via HTTP headers. If you exceed a limit, you'll receive `429 Too Many Requests`. For details, see the Rate Limits documentation. ``` -------------------------------- ### Convert Timestamp to Snowflake (TypeScript) Source: https://docs.fluxer.app/api-reference Converts a Unix timestamp (number) into a Fluxer Snowflake ID (string). This function is essential for paginating API results by time, allowing you to generate Snowflakes corresponding to specific timestamps. It utilizes BigInt for precise conversion. ```typescript function timestampToSnowflake(timestamp: number): string { const fluxerEpoch = 1420070400000n; const snowflake = (BigInt(timestamp) - fluxerEpoch) << 22n; return snowflake.toString(); } const currentTimeMs = Date.now(); const currentSnowflake = timestampToSnowflake(currentTimeMs); ``` -------------------------------- ### Convert Snowflake to Timestamp (TypeScript) Source: https://docs.fluxer.app/api-reference Converts a Fluxer Snowflake ID (string) into a Unix timestamp (number). This function is useful for determining the creation time of entities identified by Snowflakes. It requires BigInt support for accurate calculations. ```typescript function snowflakeToTimestamp(snowflake: string): number { const fluxerEpoch = 1420070400000n; const timestamp = (BigInt(snowflake) >> 22n) + fluxerEpoch; return Number(timestamp); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.