Skip to content

Commit

Permalink
✨ feat: add bluesky richtext facets
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillaverde committed Nov 13, 2024
1 parent 11c46d6 commit d2833b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/tasks/publishBluesky.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AtpAgent } from 'npm:@atproto/api'
import { AtpAgent, RichText } from 'npm:@atproto/api'
import blueskyconfig from "../config/bluesky.config.ts";
import logger from "../services/logger.service.ts";
import mqttService from "../services/mqtt.service.ts";
Expand Down Expand Up @@ -38,7 +38,7 @@ export default function publishBluesky() {
}
const messageStatus = blueskyconfig[decodedMessage.type].messageTemplate
.replace(/{channelName}/g, decodedMessage.title)
.replace(/{mentionUser}/g, decodedMessage.twitter ? ` (${decodedMessage.twitter})` : ``)
.replace(/{mentionUser}/g, decodedMessage.bluesky ? ` (${decodedMessage.bluesky})` : ``)
.replace(/{title}/g, decodedMessage.entryTitle)
.replace(/{url}/g, decodedMessage.entryLink);

Expand All @@ -49,10 +49,17 @@ export default function publishBluesky() {
identifier: blueskyconfig[decodedMessage.type].identifier,
password: blueskyconfig[decodedMessage.type].password
})
const status = await agent.post({
const rt = new RichText({
text: messageStatus,
createdAt: new Date().toISOString()
})
await rt.detectFacets(agent) // automatically detects mentions and links
const postRecord = {
$type: 'app.bsky.feed.post',
text: rt.text,
facets: rt.facets,
createdAt: new Date().toISOString(),
}
const status = await agent.post(postRecord)
logger.info(messageStatus, status);
} catch (error) {
logger.error(error);
Expand Down
1 change: 1 addition & 0 deletions src/types/pubsub.message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default interface PubSubMessage {
entryTitle: string;
entryLink: string;
twitter?: string;
bluesky?: string;
mastodon?: string;
stream?: ITwitchStream,
game?: ITwitchGame,
Expand Down

0 comments on commit d2833b2

Please sign in to comment.