Skip to content

Commit

Permalink
feat: Add the KOL profile to the display
Browse files Browse the repository at this point in the history
  • Loading branch information
sukbearai committed Jan 7, 2025
1 parent daa633d commit 1b2ace5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/scenes/kol.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { TwitterProfile } from '../twitter/manager'
import { Scenes } from 'telegraf'
import { startTwitterAuth } from '~/src/twitter/'
import { cleanMarkdown } from '../utils/markdown'
Expand All @@ -12,7 +13,25 @@ kolScene.on('text', async (ctx) => {
const twitterManager = await startTwitterAuth()
const msg = ctx.message.text

const profile = (await twitterManager.fetchProfile(msg)) as TwitterProfile
const content = await twitterManager.handleTwitterKolList(msg, 'kol')

if (profile?.screenName) {
await ctx.replyWithMediaGroup([
{
type: 'photo',
media: profile.banner,
caption: `
<b>${profile.screenName}</b>
<code>
${profile.bio}
</code>
`.trim(),
parse_mode: 'HTML',
},
])
}

await ctx.reply(cleanMarkdown(content))
await ctx.scene.leave()
})
6 changes: 3 additions & 3 deletions src/twitter/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { writeTweetsTxt } from '~/src/utils/file'
import { consola } from '~/src/utils/log'
import { RequestQueue } from './queue'

interface TwitterProfile {
export interface TwitterProfile {
id: string
username: string
screenName: string
Expand Down Expand Up @@ -268,7 +268,7 @@ export class TwitterManager {
}
}

async fetchProfile(username: string): Promise<TwitterProfile | null> {
async fetchProfile(username: string): Promise<TwitterProfile | string> {
try {
const profile = await this.requestQueue.add(async () => {
const profile = await this.twitterClient.getProfile(username)
Expand All @@ -286,7 +286,7 @@ export class TwitterManager {
} catch (error) {
console.error('Error fetching Twitter profile:', error)

return null
return 'error'
}
}

Expand Down

0 comments on commit 1b2ace5

Please sign in to comment.