post_skeet.rb
Example: make a new post (aka "skeet") with text passed in the argument to the script.
rb
# Requires a yml config file in the same directory with contents like this:
#
# id: your.handle
# pass: secretpass
require 'didkit'
require 'minisky'
require 'yaml'
$config_file = ARGV[0]
$message = ARGV[1]
if $config_file.nil? || $message.nil?
puts "Usage: #{$PROGRAM_NAME} <config.yml> <text>"
puts "Config.yml needs to include: { id: 'handle', pass: 'password' }"
exit 1
elsif !File.exist?(File.expand_path($config_file))
puts "Config file not found (#{$config_file})."
puts "Create a YAML file with { id: 'handle', pass: 'password' }"
exit 1
end
# this is a bit suboptimal, but currently you need to pass the PDS hostname to
# Minisky, even though it could look it up itself based on the handle in the config.
# this might be fixed in the future
id = YAML.load(File.read($config_file))['id']
pds = DID.resolve_handle(id).document.pds_host
# create a client instance using the auth config file
bsky = Minisky.new(pds, $config_file)
# to make a post, we upload a post record to the posts collection (app.bsky.feed.post)
# in the user's repo
bsky.post_request('com.atproto.repo.createRecord', {
repo: bsky.user.did,
collection: 'app.bsky.feed.post',
record: {
text: $message,
# we need to set the date to current time manually
createdAt: Time.now.iso8601,
# if you don't set a post language explicitly, it may be autodetected incorrectly
langs: ["en"]
}
})
puts "Posted ✓"