DalekCoffee

DalekCoffee

In the context of fediverse, I saw someone else recommended pixelfed support

I wanted to also recommend misskey support.

According to fedi.db misskey is the second most popular software out there. Markets to tend to lean more towards Japanese servers, but there is plenty of English adoption as well.

https://misskey-hub.net/en/docs/for-developers/api/

DalekCoffee

DalekCoffee

·

Still very interested in this as well

Attempting to build out some personal automation to cover the gap, found that API documentation is on any misskey server using /api-doc

https://misskey.io/api-doc is available for example, but sign ups are limited to Japan for that server

I have a misskey-fork server i would be willing to volunteer for testing. (Running Sharkey)

Or would be willing to volunteer spinning up a temporary vanilla misskey server if it would help testing/development!

no votes yet
DalekCoffee

DalekCoffee

·

Following the API doc with some AI help I was able to get the following bash script made that works for posting, not sure if this would help cut dev time

#!/bin/bash

# Variables
MISSKEY_SERVER="example.com"
MISSKEY_API_TOKEN="YOUR_API_TOKEN_HERE"
POST_TEXT="YOUR TEXT HERE"
IMAGE_URL="https://static.vecteezy.com/system/resources/previews/004/349/996/non_2x/television-screen-error-tv-test-pattern-and-tv-no-signal-concept-smpte-color-bars-illustration-free-vector.jpg"  # Leave empty "" if no image
DEFEDERATE=true  # true or false
DEBUG=false       # Enable debug output

# Headers common to all requests
AUTH_HEADER="Authorization: Bearer $MISSKEY_API_TOKEN"
CONTENT_TYPE_HEADER="Content-Type: application/json"

# Function to upload image from URL
upload_image() {
  curl -s -X POST "https://$MISSKEY_SERVER/api/drive/files/upload-from-url" \
    -H "$AUTH_HEADER" -H "$CONTENT_TYPE_HEADER" \
    -d "{\"url\":\"$IMAGE_URL\",\"isSensitive\":false,\"force\":true}"
}

# Function to find uploaded image info by filename
find_image() {
  filename=$(basename "$IMAGE_URL")
  curl -s -X POST "https://$MISSKEY_SERVER/api/drive/files/find" \
    -H "$AUTH_HEADER" -H "$CONTENT_TYPE_HEADER" \
    -d "{\"name\":\"$filename\",\"limit\":1}"
}

# Function to post a note without image
post_note_no_image() {
  curl -s -X POST "https://$MISSKEY_SERVER/api/notes/create" \
    -H "$AUTH_HEADER" -H "$CONTENT_TYPE_HEADER" \
    -d "{\"text\":\"$POST_TEXT\",\"visibility\":\"public\",\"localOnly\":$DEFEDERATE}"
}

# Function to post a note with image file ID(s)
post_note_with_image() {
  file_id="$1"
  curl -s -X POST "https://$MISSKEY_SERVER/api/notes/create" \
    -H "$AUTH_HEADER" -H "$CONTENT_TYPE_HEADER" \
    -d "{\"text\":\"$POST_TEXT\",\"visibility\":\"public\",\"localOnly\":$DEFEDERATE,\"fileIds\":[\"$file_id\"]}"
}

# Main logic
if [[ -z "$IMAGE_URL" ]]; then
  if $DEBUG; then
    echo "[DEBUG] No IMAGE_URL specified. Posting text only."
  fi
  post_note_no_image
else
  if $DEBUG; then
    echo "[DEBUG] Uploading image..."
  fi
  upload_response=$(upload_image)
  if $DEBUG; then
    echo "[DEBUG] Upload response (Expected to be Empty): $upload_response"
  fi

  # Wait a few seconds to allow the server to process the uploaded file
  sleep 5

  if $DEBUG; then
    echo "[DEBUG] Searching for uploaded image by filename..."
  fi
  find_response=$(find_image)
  if $DEBUG; then
    echo "[DEBUG] Find response: $find_response"
  fi

  # Extract file ID from find response (array, first element)
  file_id=$(echo "$find_response" | jq -r '.[0].id')

  if [[ -z "$file_id" || "$file_id" == "null" ]]; then
    echo "[ERROR] Failed to get valid file ID from find response."
    exit 1
  fi

  if $DEBUG; then
    echo "[DEBUG] Extracted file ID: $file_id"
    echo "[DEBUG] Posting note with image..."
  fi

  post_response=$(post_note_with_image "$file_id")
  if $DEBUG; then
    echo "[DEBUG] Post note response: $post_response"
  fi
fi
no votes yet
DalekCoffee

DalekCoffee

·

Adding to this that I would also be happy to provide a testing instance for these as well! I run a sandbox instance for testing all kinds of things! https://sandbox.baka.social/

no votes yet

You may use @ to mention someone.

Misskey API

2 total votes
DalekCoffee deadsuperhero
  • DalekCoffee created the item

    1 year ago