Last active
July 25, 2023 13:36
-
-
Save aetos382/74e0724020d468291862797983c2bbdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', 'AppPassword')] | |
param( | |
[Parameter(Mandatory)] | |
[string] $AccountHandle, | |
[Parameter(Mandatory)] | |
[string] $AppPassword) | |
Set-StrictMode -Version Latest | |
$createSessionBody = @{ | |
identifier = $AccountHandle | |
password = $AppPassword | |
} | ConvertTo-Json -Depth 100 | |
$createSessionResponse = Invoke-RestMethod ` | |
-Uri 'https://bsky.social/xrpc/com.atproto.server.createSession' ` | |
-Method Post ` | |
-ContentType 'application/json' ` | |
-Body $createSessionBody | |
$createSessionResponse | |
$did = $createSessionResponse.did | |
$secureToken = ($createSessionResponse.accessJwt | ConvertTo-SecureString -AsPlainText -Force) | |
# $targetHandle = 'yui.syui.ai' | |
$targetHandle = 'aetos.bsky.social' | |
$resolveHandleResponse = Invoke-RestMethod ` | |
-Uri "https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=${targetHandle}" ` | |
-Method Get ` | |
-ContentType 'application/json' ` | |
-Authentication Bearer ` | |
-Token $secureToken | |
$resolveHandleResponse | |
$at = "@${targetHandle}" | |
$base64Did = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($did)) | |
$text = "${at} /egg ${base64Did}" | |
$createRecordBody = @{ | |
did = $did | |
repo = $AccountHandle | |
collection = 'app.bsky.feed.post' | |
record = @{ | |
'$type' = 'app.bsky.feed.post' | |
text = $text | |
createdAt = (Get-Date -AsUTC -UFormat '%FT%T') | |
facets = @( | |
@{ | |
'$type' = 'app.bsky.richtext.facet' | |
index = @{ | |
byteStart = 0 | |
byteEnd = [System.Text.Encoding]::UTF8.GetByteCount($at) | |
} | |
features = @( | |
@{ | |
'$type' = 'app.bsky.richtext.facet#mention' | |
did = $resolveHandleResponse.did | |
} | |
) | |
} | |
) | |
} | |
} | ConvertTo-Json -Depth 100 | |
$createRecordBody | |
$createRecordResponse = Invoke-RestMethod ` | |
-Uri 'https://bsky.social/xrpc/com.atproto.repo.createRecord' ` | |
-Method Post ` | |
-ContentType 'application/json' ` | |
-Authentication Bearer ` | |
-Token $secureToken ` | |
-Body $createRecordBody | |
$createRecordResponse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment