A comprehensive social media integration plugin for PayloadCMS 3.0+ that enables automated posting and social sharing with encrypted credential management.
- 🔐 Secure Credential Management - AES-256-GCM encryption for API keys
- 🐦 Twitter/X Integration - Full OAuth 1.0a support with media uploads
- 🚀 Auto-Posting - Background queue processing on content publish
- ⚡ Real-Time Testing - One-click API credential validation
- 🎨 Template System - Customizable message templates with variable substitution
- 🔧 Non-Breaking - Seamless integration with existing PayloadCMS projects
- 📱 Admin Interface - Intuitive settings management through PayloadCMS admin
- 🛡️ Production Ready - Comprehensive error handling and retry logic
npm install github:Royalti-io/payloadcms-social-media-pluginOr with yarn:
yarn add github:Royalti-io/payloadcms-social-media-pluginWhen published to npm:
npm install payloadcms-social-media-plugin- PayloadCMS 3.0 or higher
- Node.js 18 or higher
- TypeScript project (recommended)
// payload.config.ts
import { buildConfig } from 'payload'
import { socialMediaPlugin } from 'payloadcms-social-media-plugin'
export default buildConfig({
collections: [
// Your existing collections
],
plugins: [
socialMediaPlugin({
platforms: {
twitter: {
enabled: true,
// Credentials will be managed through admin interface
}
},
collections: {
posts: {
name: 'socialSharing',
platforms: ['twitter'],
autoPost: false, // Start with manual posting
templates: [{
name: 'blog-post',
template: '📚 New blog post: {{title}}\n\n{{url}} #blog'
}]
}
}
})
]
})- Start your PayloadCMS application
- Login to the admin panel
- Navigate to Globals → Social Media Settings
- Enable Twitter integration
- Enter your Twitter API credentials:
- API Key
- API Secret
- Access Token
- Access Token Secret
- Click Test Connection to verify your credentials
- Configure message templates and auto-posting settings
- Create or edit posts in your enabled collections
- You'll see a new Social Sharing section in the admin interface
- Enable sharing for specific posts
- Customize messages or use templates
- Publish your content → automatic social media posting (if enabled)
socialMediaPlugin({
platforms: {
twitter: {
enabled: true,
characterLimit: 280,
allowMedia: true
}
},
collections: {
posts: {
name: 'socialSharing',
platforms: ['twitter'],
autoPost: true,
shareButtons: {
enabled: true,
position: 'bottom'
}
}
}
})socialMediaPlugin({
platforms: {
twitter: {
enabled: true,
characterLimit: 280,
allowMedia: true,
maxMediaSize: 5 * 1024 * 1024 // 5MB
},
linkedin: {
enabled: true,
characterLimit: 3000,
postAsOrganization: false
}
},
collections: {
posts: {
name: 'socialSharing',
label: 'Social Media Sharing',
platforms: ['twitter', 'linkedin'],
defaultEnabled: false,
autoPost: true,
templates: [
{
name: 'announcement',
template: '🎉 {{title}}\n\n{{excerpt}}\n\n{{url}} {{hashtags}}',
platforms: ['twitter']
},
{
name: 'professional',
template: 'New article: {{title}}\n\n{{excerpt}}\n\nRead more: {{url}}',
platforms: ['linkedin']
}
],
shareButtons: {
enabled: true,
position: 'both',
style: 'buttons'
}
}
},
options: {
debug: true,
analytics: {
enabled: true
},
queue: {
maxRetries: 3,
retryDelayMs: 5000
}
}
})To use Twitter integration, you need to create a Twitter Developer account and app:
- Go to Twitter Developer Portal
- Apply for a developer account
- Create a new app in your developer dashboard
- In your Twitter app dashboard, go to Keys and tokens
- Generate/copy the following credentials:
- API Key (Consumer Key)
- API Secret (Consumer Secret)
- Access Token
- Access Token Secret
- Go to App settings → Permissions
- Select Read and Write permissions
- Save changes
- In your PayloadCMS admin, go to Globals → Social Media Settings
- Enable Twitter integration
- Enter all four credentials
- Click Test Connection to verify
Use these variables in your message templates:
{{title}}- Document title{{excerpt}}- Document excerpt or truncated content{{url}}- Full URL to the published content{{slug}}- Document slug{{hashtags}}- Auto-generated hashtags from tags/categories{{tags}}- Document tags (comma-separated){{author}}- Author name{{publishDate}}- Publication date{{customField}}- Any custom field from your document
templates: [
{
name: 'blog-announcement',
template: '📝 New blog post: {{title}}\n\n{{excerpt}}\n\n🔗 {{url}} {{hashtags}}',
platforms: ['twitter']
},
{
name: 'news-update',
template: '🔥 Breaking: {{title}}\n\n{{url}}',
platforms: ['twitter']
},
{
name: 'linkedin-professional',
template: 'I\'ve published a new article: {{title}}\n\n{{excerpt}}\n\nRead the full article here: {{url}}\n\n#{{tags}}',
platforms: ['linkedin']
}
]The plugin automatically adds social sharing fields to your specified collections:
// Your collection will automatically get these fields added:
{
name: 'socialSharing',
type: 'group',
fields: [
{
name: 'enabled',
type: 'checkbox',
defaultValue: false
},
{
name: 'platforms',
type: 'select',
hasMany: true,
options: [
{ label: 'Twitter', value: 'twitter' },
{ label: 'LinkedIn', value: 'linkedin' }
]
},
{
name: 'customMessage',
type: 'textarea',
admin: {
description: 'Override the default template for this post'
}
},
{
name: 'autoPost',
type: 'checkbox',
defaultValue: true
}
// ... additional fields for status tracking
]
}- AES-256-GCM Encryption - All API credentials encrypted at rest
- Admin-Only Access - Social media settings restricted to admin users
- OAuth 1.0a Security - Proper Twitter API signature generation
- Input Validation - Comprehensive validation and sanitization
- Error Sanitization - No sensitive data exposed in error messages
- Real-Time Connection Testing - Validate API credentials instantly
- Template Management - Visual template editor with variable preview
- Post Status Tracking - Monitor posting success/failures
- Bulk Operations - Enable/disable sharing for multiple posts
- Error Reporting - Detailed error messages with troubleshooting guidance
The plugin automatically posts to social media when:
- New Content Published - Content created with status 'published'
- Draft to Published - Existing draft content published
- Auto-Post Enabled - Both global and per-post auto-posting enabled
- Platforms Selected - At least one platform enabled for the post
Run the included tests:
npm testBuild the plugin:
npm run buildContributions are welcome! Please read our Contributing Guide for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Full documentation available in the
/docsfolder - Issues: Report bugs on GitHub Issues
- Discord: Join the PayloadCMS community for support
- LinkedIn API completion
- Facebook/Instagram integration
- Scheduled posting
- Analytics dashboard
- Share button components
- Advanced template editor
- Webhook integration
- Multiple account support per platform
- PayloadCMS team for the amazing CMS framework
- Twitter/X API documentation and community
- All contributors and testers
Made with ❤️ for the PayloadCMS community