Post status

Create a new toot. A required parameter are a `mastodon` resource with an accessToken and "status" (text content). Optional parameters are an array of media files (base64 encoded), a boolean flag "sensitive", a string "spoiler_text", a string "inReplyToId", an ENUM["public","unlisted","private","direct"] "visibility", an ISO 8601 datetime "scheduledAt" and an ISO 639 language code "language". It should return the JSON object that the API responds.

Script mastodon Verified

by jaller94 ยท 8/10/2022

The script

Submitted by jaller94 Deno
Verified 386 days ago
1
export async function main(
2
  baseUrl: string,
3
  accessToken: string,
4
  status: string,
5
  inReplyToId?: string,
6
  sensitive = false,
7
  spoilerText?: string,
8
  visibility: "public" | "unlisted" | "private" | "direct" = "public",
9
  language?: string,
10
) {
11
  const resp = await fetch(`${baseUrl}/api/v1/statuses`, {
12
    method: "POST",
13
    headers: {
14
      Authorization: `Bearer ${accessToken}`,
15
      "Content-Type": "application/json",
16
    },
17
    body: JSON.stringify({
18
      sensitive,
19
      status,
20
      visibility,
21
      ...(inReplyToId && {
22
        in_reply_to_id: inReplyToId,
23
      }),
24
      ...(spoilerText && {
25
        spoiler_text: spoilerText,
26
      }),
27
      ...(language && {
28
        language,
29
      }),
30
    }),
31
  });
32

33
  if (!resp.ok) {
34
    throw Error(`Failed to post status: Error HTTP${resp.status}`);
35
  }
36

37
  return await resp.json();
38
}
39

Other submissions
  • Submitted by tessoudalio367 Deno
    Created 1146 days ago
    1
    // import * as wmill from 'https://deno.land/x/windmill/index.ts'
    2
    
    
    3
    export async function main(x: string) {
    4
      return x
    5
    }
  • Submitted by tessoudalio367 Deno
    Created 1146 days ago
    1
    // import * as wmill from 'https://deno.land/x/windmill/index.ts'
    2
    
    
    3
    export async function main(x: string) {
    4
      return x
    5
    }