Create Your Own ChatGPT AI Assistant on WhatsApp

Create Your Own ChatGPT AI Assistant on WhatsApp

The world of AI is experiencing rapid growth, with many people eager to harness its power to enhance their daily lives. OpenAI has made significant strides in this area, launching powerful tools like ChatGPT, which can help users manage tasks, brainstorm ideas, and check facts. We strongly believe in the importance of open-source development for an open and prosperous future of AI.

Following our previous guide on building your own ChatGPT AI Assistant on Telegram, we are excited to introduce an open-source codebase for integrating ChatGPT with WhatsApp using Twilio. Our project aims to provide a foundation for unique use-cases and foster community-driven development. With LangChain, you can create incredible AI applications by chaining multiple GPT prompts or other LLM models together.

In this guide, we’ll demonstrate how to set up a WhatsApp ChatGPT using Twilio, a renowned cloud communications platform. We also plan to explore extending its applications to sending emails, managing calendars, writing code, and more in future articles. Make sure to follow our updates and repo to stay informed!

For now, we’re providing access to OpenAI’s ChatGPT via WhatsApp and Twilio, extending the possibilities we introduced in our Telegram article.

Follow the steps below to integrate ChatGPT with WhatsApp using Twilio.

Step 1: Deploy your application

To deploy an application that communicates with OpenAI’s API and Twilio, choose one of these two convenient options:

  • Set up the Python project on a server: Visit our GitHub repository and follow the instructions to set up this Python project on your server. This method requires Python and server deployment knowledge. Hosting the project on your server offers greater control over resources and customization.

GitHub repository: https://github.com/mortium91/langchain-assistant

  • Or use Replit for free hosting: Replit (https://replit.com/) is an online, cloud-based integrated development environment (IDE) for writing, running, and sharing code directly from web browsers. You can host a temporary application for free with Replit, perfect for testing and development. We have a ready-to-use ‘repl’ available for a quick and easy AI assistant setup.

LangChain Assistant WhatsApp Bot Repl: Fork the Repl from the link provided.

Warning: Free use makes your project publicly available. Avoid adding sensitive data directly to the repository or opt for a paid plan.

Step 2: Add your OpenAI API key

To integrate GPT with your AI assistant, you need an OpenAI API key. This key enables secure access and communication with OpenAI’s GPT models. Currently, we only support OpenAI GPT models, including GPT-3, GPT-3.5-Turbo, and GPT-4. In the future, we plan to add other open-source LLMs, making it possible to run this service completely for free even after exhausting free trial credits. To obtain your API key, follow these steps:

  1. Visit OpenAI’s API key management page at https://platform.openai.com/account/api-keys.
  2. Create an account and sign in to the OpenAI platform if you haven’t already.
  3. Click the “+ Create new secret key” button to generate a new key. Copy and save this key securely.
  4. Add the OpenAI API key to your Repl repository by navigating to ‘Secrets’.
key: OPENAI_API_KEY
value: <<api key>>

Step 3: Create a Twilio account and set up a WhatsApp Sandbox

Follow these steps to set up a Twilio account and create a WhatsApp Sandbox environment:

  1. Sign up for a Twilio account at https://www.twilio.com/try-twilio.
  2. Navigate to the Twilio Console Dashboard.
  3. Find ‘Messaging’ and click on ‘Try it Out’ in the WhatsApp Sandbox.
  4. Follow instructions to connect your phone number to the WhatsApp Sandbox.
  5. Note your Twilio Account SID and Auth Token from the Twilio Console Dashboard at https://console.twilio.com/?frameUrl=/console.

Messaging -> Try it out -> Send a Whatsapp message

Add the Twilio Account SID, Auth Token and the Sandbox Whatsapp phone-number to your Repl repository by navigating to ‘Secrets’:

key: ACCOUNT_SID 
value: <<your_account_sid>>
key: AUTH_TOKEN 
value: <<your_auth_token>>
key: TWILIO_WHATSAPP_NUMBER 
value: <<phone-number>>

Step 4: Run and Chat via WhatsApp!

You’re almost finished! It’s time to launch the application. The last step is to link your application to the WhatsApp Sandbox.

When you run the application, you should see a ‘Webview’ window. This window contains your public URL, which you need to use in combination with the Twilio WhatsApp Sandbox. Make sure to add the ‘/api’ path add the end of the URL. In the Twilio Console, navigate to the ‘Try WhatsApp’ section, and then to ‘Sandbox Settings’. In the ‘WHEN A MESSAGE COMES IN’ field, enter the following URL:

https://your-bot-project.username292.repl.co/api

Click ‘Save’ at the bottom of the page to apply the changes.

Now you can chat with a powerful GPT model via WhatsApp! And here’s an exciting feature – we also support Voice Chats, making it even more convenient to communicate with your AI assistant.

The process of integrating ChatGPT with other platforms like Telegram is similar, but we have explained those in a different post. With LangChain’s open-source AI assistant, you can leverage the power of AI across multiple platforms, tailoring its capabilities to your needs. Stay tuned for future updates and improvements!

New guide: Manage your Google Calendar on Telegram and WhatsApp with the Zapier NLA integration 📅

Want to follow the progress? Make sure to sign up for our Newsletter and give us a follow on Twitter or LinkedIn.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *