Bi-Directional synchronization of Slack and Discord
Use Git to clone the project to your machine
- In
flippedbot2.py, fill in thetranslationDictwith a mapping of your server's Slack Usernames to their Discord Usernames. One example is already filled in - Repeat this for
flippedBot_d.py
- Using the Slack API, create a Slack App
- Keep track of your Bot Token and your Signing Secret. You'll add these to a ".env" file in the future
- Go to OAuth & Permissions, and add:
chat:write,chat:write.customizeandusers:readfor Bot Token Scopteschannels:historyfor User Token Scopes
- At the top of the OAuth & Permissions page, click "Install App to Workspace"
- Click on "Events Subscriptions"
Turn OnEnable Events- Click
Subscribe to events on behalf of users- Add
message.channelsto the permission scope.
- Add
- Using te Slack API Tester and your Bot Token, get the ID of the General Channel in your Slack Server
- Save this ID for the ".env" file
- Using the Discord API, create a new discord application
- Click
New Application, and make a new Bot - Keep track of your Discord Token. You'll add this to a separate ".env" file in the future
- To invite your bot to your server, click OAuth2
- Tick the
botcheckbox under scopes. - Tick the
Read Message Historypermisson. - Copy the URL and paste it into your browser to add the bot to your server
- Tick the
- In your Discord server, turn on developer settings.
- Save the General channel's channel ID for the ".env" file
- Create a webhook for the General Channel
- Save the webhook's URL for the ".env" file
- Insall and set up Kafka
- I mostly followed this tutorial
- Make sure you download the latest Kafka version available
- Set up 2 Kafka topics:
- "s2d" for messages sent from Slack to Discord
- "d2s" for messages sent from Discord to Slack
- install ngrok
- Run
ngrok http 3000, copy the https URL - In a notepad, paste, then append
/slack/eventsto the end of the URL and copy it again
- Under
Flippedbot2, create a ".env" file and fill in the appropriate values for:SIGNING_SECRET=BOT_TOKEN=CHANNEL=
- Back under your Slack App's settings, click back on "Event Subscriptions"
- Run flippedbot2.py:
python3 flippedbot2.py - In "Event Subscriptions", paste the URL you saved while setting up ngrok under "Request URL". It should say "Verified"
- Under "DiscordBot", create a ".env" file and fill in the appropriate values for:
DISCORD_TOKEN=DISCORD_GUILD=DISCORD_CHANNEL=WEBHOOK_URL=
- Run flippedBot_D.py:
python3 flippedBot_D.py
Both bots have one Kafka Consumer and one Kafka Producer. When a message is received on either end, the bot transforms the message according to a JSON schema and posts it to the corresponding Kafka topic using the Kafka Producer. The other bot consumes that message using the Kafka Consumer and posts it to the other chat.