UNPKG

@budytalk/activity-server

Version:

Complete social media content management server with built-in PostgreSQL database, real-time features, and zero-configuration setup

190 lines (153 loc) • 6.19 kB
// Simple usage example for BudyTalk Content Server const { BudyTalkContent } = require('../dist/index'); async function simpleExample() { console.log('šŸš€ Starting BudyTalk Content Server example...\n'); try { // Initialize the content server const budytalk = new BudyTalkContent({ port: 3000, database: { type: 'sqlite', url: './content.db' } }); await budytalk.initialize(); await budytalk.start(); console.log('āœ… Content server started on port 3000\n'); // Sync user accounts from your main user database console.log('šŸ“ Syncing user accounts...'); const alice = await budytalk.syncUserAccount({ userId: 'user_123', username: 'alice', displayName: 'Alice Johnson', avatar: 'https://example.com/alice.jpg' }); const bob = await budytalk.syncUserAccount({ userId: 'user_456', username: 'bob', displayName: 'Bob Smith', avatar: 'https://example.com/bob.jpg' }); console.log(`āœ… Synced accounts for ${alice.displayName} and ${bob.displayName}\n`); // Bob follows Alice console.log('šŸ“ Setting up following relationship...'); await budytalk.followUser(bob.userId, alice.userId); console.log('āœ… Bob is now following Alice\n'); // Alice creates a text post console.log('šŸ“ Creating posts...'); const textPost = await budytalk.createPost({ userId: alice.userId, content: 'Hello everyone! This is my first post using BudyTalk Content Server! šŸŽ‰', postType: 'text', hashtags: ['#hello', '#budytalk', '#social'], mentions: ['@bob'] }); console.log(`āœ… Alice created a text post: ${textPost.id}\n`); // Alice creates a poll const pollPost = await budytalk.createPost({ userId: alice.userId, content: 'Quick poll: What\'s your favorite social media feature?', postType: 'poll', poll: { question: 'What\'s your favorite social media feature?', options: [ { text: 'Timeline Feed' }, { text: 'Real-time Reactions' }, { text: 'Comments & Replies' }, { text: 'Trending Posts' } ], settings: { allowMultipleChoices: false, showResults: 'after_vote', duration: 24 } } }); console.log(`āœ… Alice created a poll: ${pollPost.id}\n`); // Bob likes Alice's post console.log('šŸ“ Adding reactions...'); await budytalk.likePost(bob.userId, textPost.id); console.log(`āœ… Bob liked Alice's post\n`); // Bob comments on Alice's post console.log('šŸ“ Adding comments...'); const comment = await budytalk.commentOnPost({ userId: bob.userId, postId: textPost.id, content: 'Great first post, Alice! Welcome to the platform! šŸ‘‹', mentions: ['@alice'] }); console.log(`āœ… Bob commented on Alice's post\n`); // Alice replies to Bob's comment console.log('šŸ“ Adding replies...'); await budytalk.replyToComment({ userId: alice.userId, postId: textPost.id, parentCommentId: comment.id, content: 'Thanks Bob! Excited to be here! 😊', mentions: ['@bob'] }); console.log(`āœ… Alice replied to Bob's comment\n`); // Bob likes Alice's reply await budytalk.likeComment(bob.userId, comment.id); console.log(`āœ… Bob liked Alice's comment\n`); // Bob retweets Alice's post with a comment console.log('šŸ“ Retweeting...'); await budytalk.retweetPost({ userId: bob.userId, postId: textPost.id, comment: 'Everyone should see this amazing first post! šŸ”„' }); console.log(`āœ… Bob retweeted Alice's post with comment\n`); // Bob votes on Alice's poll console.log('šŸ“ Voting on poll...'); if (pollPost.poll) { const timelineOption = pollPost.poll.options.find(opt => opt.text === 'Timeline Feed'); if (timelineOption) { await budytalk.voteOnPoll({ userId: bob.userId, pollId: pollPost.poll.id, optionIds: [timelineOption.id] }); console.log(`āœ… Bob voted for "Timeline Feed"\n`); } } // Get Bob's timeline (should include Alice's posts) console.log('šŸ“ Checking timelines...'); const bobTimeline = await budytalk.getTimeline(bob.userId, 10, 0); console.log(`āœ… Bob's timeline has ${bobTimeline.length} posts\n`); // Get Alice's feed (her own posts) const aliceFeed = await budytalk.getUserFeed(alice.userId, 10, 0); console.log(`āœ… Alice's feed has ${aliceFeed.length} posts\n`); // Get trending posts const trending = await budytalk.getTrendingPosts(5, 24); console.log(`āœ… Found ${trending.length} trending posts in the last 24 hours\n`); console.log('šŸŽ‰ EXAMPLE COMPLETED SUCCESSFULLY!'); console.log('================================'); console.log('āœ… User account sync working'); console.log('āœ… Following system working'); console.log('āœ… Posts created (text and poll)'); console.log('āœ… Reactions system functional (likes on posts and comments)'); console.log('āœ… Comments and replies working'); console.log('āœ… Retweets with comments working'); console.log('āœ… Poll voting working'); console.log('āœ… Timeline and feed generation working'); console.log('āœ… Trending posts algorithm working'); console.log(''); console.log('šŸš€ Your content management system is ready!'); console.log('šŸ“± Connect your user database and start building amazing social features!'); // Keep server running for testing console.log('\nā° Server will keep running for 30 seconds for testing...'); setTimeout(async () => { await budytalk.stop(); console.log('āœ… Server stopped'); }, 30000); } catch (error) { console.error('āŒ Example failed:', error.message); process.exit(1); } } // Run the example if (require.main === module) { simpleExample(); } module.exports = { simpleExample };