@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
JavaScript
// 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 };