1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export const sendPostToBsky = async (
{ identifier, password, text, facets },
) => {
const { default: AtProto } = await import("npm:@atproto/api");
const { BskyAgent, RichText } = AtProto;
const bskyService = "https://bsky.social";
const agent = new BskyAgent({ service: bskyService });
if (identifier && password && text) {
await agent.login({
identifier,
password,
});
const rt = new RichText({ text, facets });
// only detectFacets if parameter did not assign it
if (!facets) {
await rt.detectFacets(agent);
}
await agent.post({
$type: "app.bsky.feed.post",
text: rt.text,
facets: rt.facets,
});
}
else {
console.log("ERR: Missing necessary data");
}
};
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.