···25252626 // (Optional) A description of your feed
2727 // Ex: Top trending content from the whole network
2828- const description = 'Tweets from all the Alices.'
2828+ const description = 'Posts from all the Alices.'
29293030 // (Optional) The path to an image to be used as your feed's avatar
3131 // Ex: ~/path/to/avatar.jpeg
···4545 const agent = new AtpAgent({ service: 'https://bsky.social' })
4646 await agent.login({ identifier: handle, password })
47474848- // try {
4949- // await agent.api.app.bsky.feed.describeFeedGenerator()
5050- // } catch (err) {
5151- // throw new Error(
5252- // 'The bluesky server is not ready to accept published custom feeds yet',
5353- // )
5454- // }
4848+ try {
4949+ await agent.api.app.bsky.feed.describeFeedGenerator()
5050+ } catch (err) {
5151+ throw new Error(
5252+ 'The bluesky server is not ready to accept published custom feeds yet',
5353+ )
5454+ }
55555656 let avatarRef: BlobRef | undefined
5757 if (avatar) {
···7070 avatarRef = blobRes.data.blob
7171 }
72727373- await agent.api.com.atproto.repo.createRecord({
7373+ await agent.api.com.atproto.repo.putRecord({
7474 repo: agent.session?.did ?? '',
7575 collection: ids.AppBskyFeedGenerator,
7676 rkey: recordName,
+25-2
src/server.ts
···99import { FirehoseSubscription } from './subscription'
1010import { AppContext, Config } from './config'
1111import wellKnown from './well-known'
1212-import AtpAgent from '@atproto/api'
1212+import AtpAgent, { AtpSessionData, AtpSessionEvent } from '@atproto/api'
1313import * as process from 'node:process'
14141515export class FeedGenerator {
···2020 public cfg: Config
2121 public agent: AtpAgent
2222 public didResolver: DidResolver
2323+ public session: string | null
23242425 constructor(
2526 app: express.Application,
···67686869 async start(): Promise<http.Server> {
6970 await migrateToLatest(this.db)
7070- this.agent = new AtpAgent({ service: 'https://bsky.social' })
7171+ this.agent = new AtpAgent({
7272+ service: 'https://bsky.social',
7373+ persistSession: (evt: AtpSessionEvent, sess?: AtpSessionData) => {
7474+ // store the session-data for reuse
7575+ switch (evt) {
7676+ case 'create':
7777+ if (!sess) throw new Error('should be unreachable')
7878+ this.session = JSON.stringify(sess)
7979+ break
8080+ case 'create-failed':
8181+ this.session = null
8282+ console.error('Could not create session')
8383+ break
8484+ case 'update':
8585+ if (!sess) throw new Error('should be unreachable')
8686+ this.session = JSON.stringify(sess)
8787+ break
8888+ case 'expired':
8989+ this.session = null
9090+ break
9191+ }
9292+ },
9393+ })
7194 await this.agent.login({
7295 identifier: process.env.HANDLE!,
7396 password: process.env.PASSWORD!,