Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7c1d2c47ec |
@@ -1,4 +1,5 @@
|
|||||||
import createPost from './create-post/index.js';
|
import createPost from './create-post/index.js';
|
||||||
|
import replyToPost from './reply-to-post/index.js';
|
||||||
import searchPostByUrl from './search-post-by-url/index.js';
|
import searchPostByUrl from './search-post-by-url/index.js';
|
||||||
|
|
||||||
export default [createPost, searchPostByUrl];
|
export default [createPost, replyToPost, searchPostByUrl];
|
||||||
|
@@ -0,0 +1,55 @@
|
|||||||
|
import { BskyAgent, RichText } from '@atproto/api';
|
||||||
|
|
||||||
|
import defineAction from '../../../../helpers/define-action.js';
|
||||||
|
import getReplyRefs from '../../common/get-reply-refs.js';
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Reply to post',
|
||||||
|
key: 'replyToPost',
|
||||||
|
description: 'Replies to a post.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Post Url',
|
||||||
|
key: 'postUrl',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
variables: true,
|
||||||
|
description: 'Enter whole post url you want to reply here.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Text',
|
||||||
|
key: 'text',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
variables: true,
|
||||||
|
description: 'Your post.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const text = $.step.parameters.text;
|
||||||
|
const postUrl = $.step.parameters.postUrl;
|
||||||
|
|
||||||
|
const replyRefs = await getReplyRefs($, postUrl);
|
||||||
|
|
||||||
|
const agent = new BskyAgent({ service: 'https://bsky.social/xrpc' });
|
||||||
|
const richText = new RichText({ text });
|
||||||
|
await richText.detectFacets(agent);
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
repo: $.auth.data.did,
|
||||||
|
collection: 'app.bsky.feed.post',
|
||||||
|
record: {
|
||||||
|
$type: 'app.bsky.feed.post',
|
||||||
|
text: richText.text,
|
||||||
|
facets: richText.facets,
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
reply: replyRefs,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data } = await $.http.post('/com.atproto.repo.createRecord', body);
|
||||||
|
|
||||||
|
$.setActionItem({ raw: data });
|
||||||
|
},
|
||||||
|
});
|
58
packages/backend/src/apps/bluesky/common/get-reply-refs.js
Normal file
58
packages/backend/src/apps/bluesky/common/get-reply-refs.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
const parseUri = (uri) => {
|
||||||
|
const parts = uri.split('/');
|
||||||
|
|
||||||
|
return {
|
||||||
|
repo: parts[4],
|
||||||
|
collection: 'app.bsky.feed.post',
|
||||||
|
rkey: parts[6],
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const getReplyRefs = async ($, parentUri) => {
|
||||||
|
const uriParts = parseUri(parentUri);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { data: parent } = await $.http.get('/com.atproto.repo.getRecord', {
|
||||||
|
params: uriParts,
|
||||||
|
});
|
||||||
|
|
||||||
|
const parentReply = parent.value?.reply;
|
||||||
|
let root;
|
||||||
|
|
||||||
|
if (parentReply) {
|
||||||
|
const rootUri = parentReply.root.uri;
|
||||||
|
const [rootRepo, rootCollection, rootRkey] = rootUri
|
||||||
|
.split('/')
|
||||||
|
.slice(2, 5);
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
repo: rootRepo,
|
||||||
|
collection: rootCollection,
|
||||||
|
rkey: rootRkey,
|
||||||
|
};
|
||||||
|
|
||||||
|
const rootResp = await $.http.get('/com.atproto.repo.getRecord', {
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
|
||||||
|
root = rootResp.data;
|
||||||
|
} else {
|
||||||
|
root = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
uri: root.uri,
|
||||||
|
cid: root.cid,
|
||||||
|
},
|
||||||
|
parent: {
|
||||||
|
uri: parent.uri,
|
||||||
|
cid: parent.cid,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error('Error while fetching records');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getReplyRefs;
|
@@ -3,6 +3,8 @@ favicon: /favicons/bluesky.svg
|
|||||||
items:
|
items:
|
||||||
- name: Create post
|
- name: Create post
|
||||||
desc: Creates a new post.
|
desc: Creates a new post.
|
||||||
|
- name: Reply to post
|
||||||
|
desc: Replies to a post.
|
||||||
- name: Search post by url
|
- name: Search post by url
|
||||||
desc: Searches a post in a thread by url.
|
desc: Searches a post in a thread by url.
|
||||||
---
|
---
|
||||||
|
Reference in New Issue
Block a user