Cross tweet from Mastodon

ekardnam fb146f7cc1 Read me 4 years ago
.dockerignore 308e06b9bb more docker 4 years ago
.gitignore 2eeadd9f2a OAuth 4 years ago
Dockerfile 308e06b9bb more docker 4 years ago
LICENSE 921ae2e84e Add 'LICENSE' 4 years ago
README.md fb146f7cc1 Read me 4 years ago
app.js 0649ade820 Fix 4 years ago
bot.js 308e06b9bb more docker 4 years ago
cert.pem 2eeadd9f2a OAuth 4 years ago
key.pem 2eeadd9f2a OAuth 4 years ago
oauth.js 2eeadd9f2a OAuth 4 years ago
package.json affbbc7c1a Docker 4 years ago
storage.js 2eeadd9f2a OAuth 4 years ago

README.md

XTweet

Converts noisy toots to tiny tweets

Configurazione e deployment

Crea un file config.js con questa struttura

module.exports = {
  twitter_consumer_key: '...',
  twitter_consumer_secret: '...',

  mastodon_token: '...',
  mastodon_user: 'ekardnam',
  instance: 'mastodon.bida.im',

  key: 'key.pem',
  cert: 'cert.pem',
  passphrase: 'pass',
  bind_ip: '0.0.0.0',
  port: 8000,
  callback_url: 'https://localhost:8000',
  callback_path: '/oauth/callback'
}

In twitter_consumer_key e in twitter_consumer_secret ci vanno i token relativi all'app Twitter.

Collegare Mastodon

Per Mastodon basta andare nel menù Impostazioni > Sviluppo > Nuova applicazione e dare il permesso read:statuses.

Collegare Twitter

Twitter è po' più complicato. Bisgona eseguire l'app in locale alla prima esecuzione siccome non trovarà un file storage.json con i token di Twitter l'app avvierà un webserver per l'autorizzazione di Twitter.

I certificati che sono nella repo sono di test e sono configurati già nel config d'esempio. Siccome vengono negoziati i token di Twitter è bene cambiarli. Si generano con

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365

bind_ip e port sono dove si binda il server HTTPS per l'autorizzazione, mentre callback_url e callback_path concatenati danno il callback dell'OAuth (che deve essere settato nell'app Twitter)

Avviato il webserver lo si visita (a https://localhost:8000 con la configurazione di default) e verrà chiesto di autenticarsi su Twitter e di autorizzare l'app.

Deployment del bot

Dopo aver seguito i passi precedenti si può finalmente eseguire il bot. Se lo si vuole ospitare su un server a questo punto sono necessarie alcune accortezze. Dopo aver clonato la repo sul server è necessario copiare nella directory sul server i file config.js e storage.json che contengono i token relativi a Mastodon e Twitter.

Fatto questo si può buildare l'immagine Docker con docker build . -t xtweet e successivamente eseguirla con docker run -d xtweet