DEV Community

Cover image for Twilio Challenge: Language Translator via Twilio Functions, WhatsApp, Appwrite & OpenAI
Aditya Oberai
Aditya Oberai

Posted on • Edited on

Twilio Challenge: Language Translator via Twilio Functions, WhatsApp, Appwrite & OpenAI

This is a submission for Twilio Challenge v24.06.12

What I Built

As an avid translator who often faces challenges with different languages when traveling across different countries. To solve my own problem, I wanted to create a simple chatbot that lets me quickly translate text from my preferred language to another, making it so much easier to communicate with other people.

Therefore, I created an AI Language Translator using the WhatsApp Sandbox mode in Twilio Programmable Messaging, Twilio Functions, Appwrite Database and OpenAI's GPT-4o API.

Demo

Watch how it works

Here is a demo video of the app:

Tech Stack

  • The chatbot uses Twilio Programmable Messaging (WhatsApp Sandbox) and Twilio Functions to communicate with the user.
  • Appwrite Database is primarily used to store the state of the user through the conversation, and all conversation data is deleted as soon as the translation is sent to the user.
  • OpenAI's GPT-4o API is used to translate the text to the specified language.

Steps to try

You can try it out by scanning the QR Code in the image or by texting the code join trail-has to the number +14155238886 on WhatsApp.

Twilio WhatsApp Sandbox

Once that is done, send the message Hello Twilio to begin using the chatbot.

Source code

You can also view the source code of the Twilio Function on GitHub:

GitHub logo adityaoberai / language-translator-twilio-function

Twilio function that translates language using GPT-4o and responds through the Twilio Programmable Messaging on WhatsApp

Twilio Challenge: Language Translator via Twilio Functions, WhatsApp, Appwrite & OpenAI

Description

Twilio function that translates language using GPT-4o and responds through the Twilio Programmable Messaging on WhatsApp

Screen_Recording_20240617_172845_WhatsApp.mp4

How it works

  • Twilio Programmable Messaging (WhatsApp Sandbox) and Twilio Functions is used to communicate with the user
  • Appwrite Database is used to store the state of the user through the conversation, and all conversation data is deleted as soon as the translation is sent to the user
  • OpenAI's GPT-4o API is used to translate the text to the specified language



Twilio and AI

To create this chatbot, I used OpenAI's GPT-4o API in a Twilio Function. This function consumes the text to translate, and the target language based on the user's input and returns the translated text.

Additional Prize Categories

  • Twilio Times Two: The project uses Twilio Programmable Messaging (WhatsApp Sandbox) and Twilio Functions.

  • Impactful Innovators: In a far more interconnected world than ever, a tool that simplifies cross-language communication will help bring people from different cultures closer together.

Feedback, Updates, and Testimonials

  • During the process of developing the Twilio Function, I discovered an issue with the max length of environment variables. The issue has already been acknowledged by the Twilio team.

Just finished my submission 🥳

@anthonyjdella, I do have some product feedback. When trying out Twilio Functions, I noticed that the max length of environment variables is set to 255 characters. I was using Appwrite Databases as a part of my project, and the API keys happened to be 256 characters in length. This made it somewhat challenging to use environment variables for that purpose.

  • The project is getting real-world usage and positive user feedback publicly!

Top comments (13)

Collapse
 
sojinsamuel profile image
Sojin Samuel • Edited

Wonderful contribution adi :)

Collapse
 
adityaoberai profile image
Aditya Oberai

Thank you!

Collapse
 
sojinsamuel profile image
Sojin Samuel • Edited

You're welcome, you might like my extended version of this same whatsapp chatbot:
How to create a whatsapp chatbot with custom knowledge base (with twilio, supabase)

Thread Thread
 
adityaoberai profile image
Aditya Oberai

I did extend the application to save and check state using Appwrite

Collapse
 
chintanonweb profile image
chintanonweb

I don't have idea for two way communication in twilio whatsapp and how to confuigure function for response can you please guide me!

Thread Thread
 
sojinsamuel profile image
Sojin Samuel

Are you planning to use twilio functions instead of tunneling via ngrok?

aditya has already given the open source example for a serverless function you can easily migrate it. but if you face any difficulties feel free to reach out.

Make sure to read about:
Twilio functions (Implement very basic ones first), Twilio code exchange has starter examples.
How to use the sandbox environment, and implement webhooks for a 2 way conversation have already listed on my article.

Can't wait to see what you come up with and best of luck with @twilio1 challenge.

Thread Thread
 
adityaoberai profile image
Aditya Oberai

I'll probably also write a blog on how I built my function but not until a little while later.

@chintanonweb Twilio also has their help chatbot here: help.twilio.com/

Collapse
 
devarshishimpi profile image
Devarshi Shimpi

Well made!

Collapse
 
adityaoberai profile image
Aditya Oberai

Thank you!

Collapse
 
neurabot profile image
Neurabot

Innovative and exciting.

Collapse
 
adityaoberai profile image
Aditya Oberai

Thank you!

Collapse
 
tonic profile image
Tonic

i came for the source code and i wasnt disappointed. thank you !

Collapse
 
adityaoberai profile image
Aditya Oberai

NGL, it's a bit janky at the moment (need to add proper error handling and all 😆)

But I will be improving it going further and writing some content on how to build this sort of a tool 😌