WhatsUpGenius? is a WhatsApp bot that allows you to add music to a spotify playlist. The application, developed with Ruby on Rails, consists of a web interface to connect to Spotify and enter the phone number with which you want to communicate with the bot. Then, you just have to send a message to the bot to start using it.
- Twilio (WhatsApp)
- Spotify (you know why, right?)
- OpenAI (to communicate with the bot in a natural way)
Thus, thanks to OpenAI, each bot response (track found or not, music added, etc.) is unique. Also, when the bot asks you if you want to add the music to your playlist, no keyword is required. The bot is able to determine whether your answer is positive or negative and act accordingly.
On your Spotify developer dashboard, create an application. In the settings, enter the following redirect URI: http://localhost:3000/auth/spotify/callback
. Copy your client ID
and client secret
then add it to the credentials:
EDITOR=nano bin/rails credentials:edit
spotify:
client_id: your_client_id
client_secret: your_client_secret
Now, go to Twilio and create a WhatsApp sandbox (you can try through this link, it's a pain to find your way in their dashboard ngl). Once you have created your sandbox, copy the phone number and code to join the sandbox. In your sandbox settings, we need to add a URL so that Twilio can send us webhooks. To do so, create an ngrok tunnel:
ngrok http 3000
Copy the generated URL and add the following path: /webhooks/twilio/messages
. For example, mine looks like this: https://e80f-2a01-e0a-9a9-120-5c92-a021-b398-5c3d.eu.ngrok.io/webhooks/twilio/messages
Then, go to your account and copy your API token. Again, add these informations to the credentials:
twilio:
auth_token: your_auth_token
whatsapp_number: your_whatsapp_phone_number
join_code: your_sandbox_join_code
Great! Now, we just need to get our API token for OpenAI.
Go to your OpenAI account, API Keys, and create a secret key. Copy it and add it to the credentials:
openai:
access_token: your_secret_key
Perfect!
Make sure your ngrok tunnel is open. If not, restart it and update the URL in the settings for the WhatsApp sandbox on Twilio.
cd whatsupgenius
bundle
rails db:setup
bin/dev
Visit http://localhost:3000/
and let's go!