Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bluesky time-bound query issues #229

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bluesky/credential/tool.gpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Name: Bluesky Basic Auth Credential
Share Credential: ../../basic-auth as bluesky
with bluesky_handle as username_field and
BLUESKY_HANDLE as username_env and
bluesky_app_password as password_field and
BLUESKY_APP_PASSWORD as password_env and
"Enter your Bluesky handle and app password.\nTo generate a new app password, go to https://bsky.social/settings/app-passwords" as message
Type: credential
8 changes: 8 additions & 0 deletions bluesky/src/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ export async function searchPosts (
since?: string,
until?: string,
limit?: string,
tags?: string,
): Promise<void> {
let queryParams: AppBskyFeedSearchPosts.QueryParams = {
q: query ?? '',
sort: 'latest',
limit: 25
}

if (!query) {
Expand Down Expand Up @@ -40,6 +42,12 @@ export async function searchPosts (
}
}

if (!!tags) {
queryParams.tag = tags
.split(',')
.map(tag => tag.trim().replace(/^#/, ''))
}

const response = await agent.app.bsky.feed.searchPosts(queryParams)

console.log(JSON.stringify(response.data.posts))
Expand Down
19 changes: 18 additions & 1 deletion bluesky/src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,27 @@ if (process.argv.length !== 3) {
process.exit(1)
}

const BLUESKY_HANDLE = process.env.BLUESKY_HANDLE
const BLUESKY_APP_PASSWORD = process.env.BLUESKY_APP_PASSWORD

const command = process.argv[2]

try {
if (!BLUESKY_HANDLE) {
throw new Error('bluesky username not set')
}

if (!BLUESKY_APP_PASSWORD) {
throw new Error('bluesky app password not set')
}

const agent = new AtpAgent({
service: 'https://api.bsky.app'
service: 'https://bsky.social'
})

await agent.login({
identifier: BLUESKY_HANDLE,
password: BLUESKY_APP_PASSWORD
})

switch (command) {
Expand All @@ -22,6 +38,7 @@ try {
process.env.SINCE,
process.env.UNTIL,
process.env.LIMIT,
process.env.TAGS,
)
break
case 'searchUsers':
Expand Down
11 changes: 7 additions & 4 deletions bluesky/tool.gpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ Share Tools: Search Posts, Search Users

---
Name: Search Posts
Description: Search for posts on Bluesky
Description: Search for Bluesky posts
Credential: ./credential
JSON Response: true
Share Context: ../time
Share Tools: Search Users
Param: query: A Lucene query to search for posts with.
Param: since: (optional) ISO 8601 timestamp to search for posts since. Defaults to 7 days ago.
Param: until: (optional) ISO 8601 timestamp to search for posts until. Defaults to now.
Param: since: (optional) ISO 8601 UTC timestamp to search for posts since (inclusive). Defaults to 7 days ago.
Param: until: (optional) ISO 8601 UTC timestamp to search for posts until (exclusive). Defaults to now.
Param: limit: (optional) The maximum number of posts to return. Must be an integer >=1 and <=100. Defaults to 25.
Param: tags: (optional) A comma separated list of tags to find posts containing any of the specified tags. For example, `#apple,#banana` will return posts that include either `#apple`, `#banana`, both. To search for posts containing multiple tags together, combine hashtags with the 'AND' operator. For instance, `#apple AND #banana,#cherry` will return posts that include both `#apple` and `#banana`, as well as posts that include `#cherry`.

#!/usr/bin/env npm --silent --prefix ${GPTSCRIPT_TOOL_DIR} run tool -- searchPosts

---
Name: Search Users
Description: Search for users on Bluesky
Description: Search for Bluesky users
Credential: ./credential
JSON Response: true
Share Context: ../time
Param: query: A Lucene query to search for users with.
Expand Down