The Problem ๐Ÿค”

A friend of mine uses Discord but not WhatsApp, so we had the idea of combining the Discord API and the Twilio WhatsApp API. It's a simple project not up to our usual Hackathon standards, but the idea of Paradigm Conference was to try out a programming language you don't normally use, in this case Haskell, and get experience making a project with it. Given this constraint, we are pleased to have come up with this project. The project is not ready for general use as it still has a hard-coded server id and we are using Twilio Sandboxing, but it is a good proof of concept.

What it does ๐Ÿƒ

  1. Discord Bot is added to server by the server owner.
  2. Channel is nominated as the "To-Whatsapp" Channel.
  3. User sends a message in said channel.
  4. The bot script is run. a. The bot logs into Discord and downloads all messages from that channel b. The bot filters those messages to select only the ones that haven't been synced yet. c. For each message that hasn't yet been sent over to Whatsapp, the bot makes an API request to Twilio to get a WhatsApp message sent to the nominated number for the channel.
  5. The user receives the message via WhatsApp

How we built it ๐Ÿค–

We used Haskell with the http-conduit library to make the web requests, and Aeson to parse the JSON responses into our own types. The date checking is done with the Data.Time library and Data.Time.ISO8601, which enables Discord's timestamps to be parsed to native UTCTime objects that are members of the Ord typeclass and so can be compared.

Challenges we ran into๐Ÿ˜ฌ

  1. Making the Twilio API work within the sandbox with the correct token - eventually we managed to find the correct token.
  2. Installing the correct dependencies using Cabal
  3. As this was the first time some of our team mates used Haskell it was quite difficult to build a working project and learn the language at the same time.

Accomplishments that we're proud of ๐Ÿ†

Using Haskell which is a programming language we don't have much experience in (though we had used it a little bit before) and broadening our knowledge of functional programming concepts.

What we learned ๐Ÿ“š

  1. How to send WhatsApps with the Twilio API.
  2. How to use the http-conduit library in Haskell.
  3. How to process ISO-6801 timestamps in Haskell.

What's next for Discord-To-Whatsapp-Bot๐Ÿ”ฎ

  1. Two-way communication (currently only one way)
  2. Enable messages to be sent into group chats and not just DMs on WhatsApp
  3. Create a sign-in flow to select the number to link the bot to so it could actually be used in practice.

Slides: https://docs.google.com/presentation/d/1yLr9tIdAXoKCK_3qD4C5ooBi814ikDYi16ZbQGQ8OJ0/edit?usp=sharing

Built With

  • cabal
  • discord
  • haskell
  • http-conduit
  • rest
Share this project:

Updates

Submission history