UNPKG

@budytalk/activity-server

Version:

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

106 lines (90 loc) 2.67 kB
// Example usage similar to GetStream const { connect } = require('../dist/index'); // Initialize client const client = connect('your-api-key', 'your-api-secret'); async function socialAppExample() { try { // Create user token const userToken = client.createUserToken('chris'); // Get user feed const chris = client.feed('user', 'chris', userToken); // Create a post await chris.addActivity({ actor: 'chris', verb: 'posted', object: 'post:1', content: 'Beautiful bird!', postType: 'image', media: [{ type: 'image', url: 'https://example.com/bird.jpg', filename: 'bird.jpg', size: 1024000 }], hashtags: ['#nature', '#birds'], mentions: ['@alice'] }); // Create a poll await chris.addActivity({ actor: 'chris', verb: 'posted', object: 'poll:1', content: 'What\'s your favorite bird?', postType: 'poll', poll: { question: 'What\'s your favorite bird?', options: [ { text: 'Eagle' }, { text: 'Sparrow' }, { text: 'Parrot' }, { text: 'Owl' } ], settings: { allowMultipleChoices: false, showResults: 'after_vote', duration: 24 // hours } } }); // Add reactions await client.reactions.add('like', 'post:1', {}, { userId: 'alice' }); await client.reactions.add('love', 'post:1', {}, { userId: 'bob' }); // Add comment await client.reactions.add('comment', 'post:1', { text: 'Amazing shot! Where did you take this?' }, { userId: 'alice' }); // Create following relationship const jack = client.feed('timeline', 'jack'); await jack.follow('user', 'chris'); // Read Jack's timeline const results = await jack.get({ limit: 10, reactions: { own: true, counts: true, recent: true } }); console.log('Timeline results:', results); // Share/Retweet await client.reactions.add('retweet', 'post:1', { comment: 'Check out this amazing bird photo!' }, { userId: 'jack', targetFeeds: ['timeline:jack'] }); // Vote on poll await client.reactions.add('vote', 'poll:1', { optionId: 'option:1' }, { userId: 'alice' }); // Bookmark post await client.reactions.add('bookmark', 'post:1', {}, { userId: 'alice' }); } catch (error) { console.error('Error:', error); } } // Run example if (require.main === module) { socialAppExample(); } module.exports = { socialAppExample };