feat(bluesky): add create post action
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
"db:migrate": "node ./bin/database/convert-migrations.js && knex migrate:latest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@atproto/api": "^0.12.13",
|
||||
"@bull-board/express": "^3.10.1",
|
||||
"@casl/ability": "^6.5.0",
|
||||
"@graphql-tools/graphql-file-loader": "^7.3.4",
|
||||
|
@@ -0,0 +1,41 @@
|
||||
import { BskyAgent, RichText } from '@atproto/api';
|
||||
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create post',
|
||||
key: 'createPost',
|
||||
description: 'Creates a new post.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Text',
|
||||
key: 'text',
|
||||
type: 'string',
|
||||
required: true,
|
||||
variables: true,
|
||||
description: '',
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const text = $.step.parameters.text;
|
||||
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(),
|
||||
},
|
||||
};
|
||||
|
||||
const { data } = await $.http.post('/com.atproto.repo.createRecord', body);
|
||||
|
||||
$.setActionItem({ raw: data });
|
||||
},
|
||||
});
|
3
packages/backend/src/apps/bluesky/actions/index.js
Normal file
3
packages/backend/src/apps/bluesky/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import createPost from './create-post/index.js';
|
||||
|
||||
export default [createPost];
|
@@ -1,6 +1,7 @@
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import actions from './actions/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Bluesky',
|
||||
@@ -13,4 +14,5 @@ export default defineApp({
|
||||
primaryColor: '1185fd',
|
||||
beforeRequest: [addAuthHeader],
|
||||
auth,
|
||||
actions,
|
||||
});
|
||||
|
Reference in New Issue
Block a user