Crossposter to post statuses between Mastodon and Twitter
Crossposter to post statuses between Mastodon and Twitter
This project is now archived. The code here has been functional but affected by Twitter changes. You can probably still run this locally, but no further support will be given and no component will be upgraded.
This is an app for crossposting between Mastodon and Twitter. The app is made so that multiple users can connect to it using the OAuth interface from both Twitter and Mastodon and choose options on how the crosspost should work.
If you just want to use it, there's one running at https://crossposter.masto.donte.com.br, which you can use from most Mastodon servers (except the ones suspended at masto.donte.com.br).
Post from Twitter to Mastodon
Post from Mastodon to Twitter
The crossposter will never follow anyone or post anything but the content you selected to be crossposted.
If you decide to crosspost from Twitter to Mastodon, remember to turn on notifications about when people mention you to avoid not seeing interactions!
The crossposter is made with multiple users in mind. For that reason, it can be quite a lot of moving parts if you want to self-host yourself. There's other good tools to self-host out there like https://github.com/AmauryCarrade/MastodonToTwitter or https://github.com/klausi/mastodon-twitter-sync and the others listed at the Bridges from/to other platforms section of the Mastodon apps. That being said, it should work even if you only want it for your own usage.
Ruby 3.1.0
Rails 7.0
Without extra configuration, a local postgres instance is needed. Node is needed for assets compilation, can be installed using nvm.
The poster uses the ruby-filemagic gem for detecting the types of the files posted. Follow the instructions described in the README to install the needed library and headers.
TWITTER_CLIENT_ID) and consumer secret (on our side TWITTER_CLIENT_SECRET).https://crossposter.example.com/users/auth/twitter/callback.Note: If you are running side-by-side with Mastodon or other sidekiq-using software, you need to configure redis to avoid issues with mixed jobs. More info at the end.
You need to install Yarn and Ruby 3.1.0. Yarn has installation instructions for several OSs here: https://yarnpkg.com/lang/en/docs/install/ and Ruby can be installed either using RVM (https://rvm.io/rvm/install) or rbenv (https://github.com/rbenv/rbenv#installation). After you have ruby and yarn setup, you'll need to do:
# Install bundler
gem install bundler
# Use bundler to install Ruby dependencies
bundle install --deployment --without development test
# Use yarn to install node.js dependencies
yarn install --pure-lockfileA separate user is recommended.
If you want the crossposter to send data to a statsd instance, you need to configure the appropriate variables in the .env file. You can check the example for reference.
Before starting for the first time, you need to generate the assets and setup the database:
bundle exec rake db:setup # sets up the database
bundle exec rake assets:precompile # generates the assetsAn example nginx configuration can be found at util/nginx.conf. It assumes the crossposter is running at port 3000, in the directory /home/crossposter/live and the domain crossposter.example.com needs to be replaced by your own.
An example of the configuration file is provided at .env.example. To generate SECRET_KEY_BASE, you need to run bundle exec rake secret and copy the resulting hash. You need to configure an app on Twitter with permission to read and write. The credentials that they give you need to be added to TWITTER_CLIENT_ID and TWITTER_CLIENT_SECRET. \
If you're not using Librato, you don't need to fill any of the Librato variables.
To start the web app, you need to do:
bundle exec puma -C config/puma.rb"
If you are using systemd, you can create a service with something like:
[Unit]
Description=mastodon-twitter-crossposter
After=network.target
[Service]
Type=simple
User=crossposter
WorkingDirectory=/home/crossposter/live
Environment="RAILS_ENV=production"
Environment="RAILS_LOG_TO_STDOUT=enabled"
Environment="PORT=3001"
ExecStart=/bin/bash -lc "bundle exec puma -C config/puma.rb"
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.targetAnd put it on /etc/systemd/system/crossposter.service
And a second one like this:
[Unit]
Description=mastodon-twitter-crossposter-sidekiq
After=network.target
[Service]
Type=simple
User=crossposter
WorkingDirectory=/home/crossposter/live
Environment="RAILS_ENV=production"
Environment="RAILS_LOG_TO_STDOUT=enabled"
Environment="RAILS_MAX_THREADS=5"
ExecStart=/bin/bash -lc "bundle exec sidekiq -c 5 -q default"
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.targetAnd put it on /etc/systemd/system/crossposter-sidekiq.service
(note that RAILS_MAX_THREADS and the number of sidekiq threads should be the same)
These example files are provided in the config/systemd-services directory. You may copy these files (with necessary modifications, if applicable) to /etc/systemd/system/ to run the system in the background.
If you are running the crossposter on a server with other sidekiq/redis applications, you need extra configuration to make sure everything is separated.
For a more in-depth information, you can check out Sidekiq Wiki, but one thing you can do it's to use another redis db, which could be done by creating a file in config/initializers/sidekiq.rb with the content like
Sidekiq.configure_server do |config|
config.redis = { url: 'redis://redis.example.com:7372/2' }
end
Sidekiq.configure_client do |config|
config.redis = { url: 'redis://redis.example.com:7372/2' }
endYou need to replace all values with actual values relevant to your server.
.env based on .env.example and set DB_HOST=db, DB_USER=postgres, REDIS_URL=redis://redis. You also need to set ALLOWED_DOMAIN or BLOCKED_DOMAINS to your preferences. Set CROSSPOSTER_DOMAIN to the URL where the app can be accessed, such as http://127.0.0.1:/ if running locally (3000 used as the port below.).http://127.0.0.1:/users/auth/twitter/callback, where the `` is the port you choose to launch the web-app in (3000 used below). Use anything for the website..env file, set TWITTER_CLIENT_ID to the "API Key" in the "Consumer Keys" section of your Twitter app. Set TWITTER_CLIENT_SECRET to the "API Secret".FROM node:18-alpine as node into FROM --platform=linux/amd64 node:18-alpine as node and FROM ruby:3.1.0-alpine into FROM --platform=linux/amd64 ruby:3.1.0-alpine to emulate an x86_64 architecture.docker-compose up -d --build.docker-compose run --rm web bundle exec rake secret. Set this as SECRET_KEY_BASE in the .env file.docker-compose run --rm web bundle exec rake db:setup.docker-compose run --rm web bundle exec rake assets:precompile.docker-compose run -p 3000:3000 --rm web bundle exec puma -C config/puma.rb, which lets you configure options locally in your browser 127.0.0.1:3000, and perform user log-ins.sidekiq with docker-compose run -p 3001:3001 --rm sidekiq to start sidekiq, which performs the posting.You can add ALLOWED_DOMAINS=your.domain.com to .env.production to only allow users from your instance to access the crossposter. This variable can contain multiple instances separated by comma.
At the same time, you can add BLOCKED_DOMAINS=evil.corp,bad.instance to .env.production to block users from those instances to access the crossposter. They need to be separated by commas, spaces are optional.
You should only enable one at each time.
If you are an admin, you might want to make yourself an admin, which allows you to take a look on the status of the sidekiq queues (and solve possible issues that happen regarding users crosspo
No open issues yet, or sync has not completed.