Build Your Own ChatGPT AI Assistant on Telegram

Build Your Own ChatGPT AI Assistant on Telegram

The world of AI is growing rapidly, and many people are eager to harness its power to improve 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. However, for the future of AI to be open and prosperous, we believe in the importance of open-source development.

We’re excited to introduce an open-source codebase that allows you to build your own AI assistant. While others may build more advanced systems, our project aims to provide a foundation for unique use-cases and foster community-driven development. Thanks to LangChain, it’s possible to create incredible AI applications by chaining multiple GPT prompts or other LLM models together.

We’ll begin by showing you how to set up a Telegram ChatGPT. For the WhatsApp integration, we’ve just published a comprehensive guide titled “Create Your Own ChatGPT AI Assistant on WhatsApp“. In the future, we’ll explore expanding its applications to sending emails, managing calendars, writing code, and more. Make sure to follow our updates and repo to stay informed!

For now, we’re just opening a gateway to OpenAI’s ChatGPT via Telegram.

Step 1: Deploy your own application

To deploy your own application that communicates with OpenAI’s API and Telegram, you have 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 own server. This method requires some knowledge of Python and server deployment. By hosting the project on your own server, you can have more control over the resources and customization of your AI assistant.

The Github repository: https://github.com/mortium91/langchain-assistant

Or use Replit for Free hosting

If you’re new to server deployment or prefer a hassle-free solution, Replit offers an excellent alternative. Replit (https://replit.com/) is an online, cloud-based integrated development environment (IDE) that allows users to write, run, and share code directly from their web browsers.

You can host a temporary application for free using Replit, which is perfect for testing and development purposes. We have a ready-to-use ‘repl’ available, so you can quickly set up your AI assistant without any cost. With Replit’s user-friendly interface, you can easily deploy your application without extensive knowledge of Python or server management. Since this is the easiest way to try out our open-source AI assistant, we will focus on the Replit use case in this guide.

LangChain Assistant Telegram WhatsApp Bot Repl

Fork the Repl:

If you go to the above link, you can fork the Repl and use it for yourself:

Warning: you can use it for free, but this means your project will be publicly available. Make sure you don’t add any sensitive data directly into the repository. To prevent this, you can opt for a paid plan.

Step 2: Add your OpenAI api key

To connect GPT with your AI assistant, an OpenAI API key is required. This key facilitates secure communication and access to OpenAI’s GPT models. As of now, our support is limited to OpenAI GPT models such as GPT-3, GPT-3.5-Turbo, and GPT-4. We intend to incorporate other open-source LLMs in the future, allowing users to utilize this service entirely free of charge even after depleting free trial credits. To obtain your API key, follow these simple steps:

  1. Visit OpenAI’s API key management page at https://platform.openai.com/account/api-keys.
  2. If you haven’t already, create an account and sign in to the OpenAI platform.
  3. Once logged in, you will see a list of your API keys (if any). To generate a new key, click the “+ Create new secret key” button.
  4. After clicking the button, a new API key will be generated. Make sure to copy and save this key securely, as it won’t be displayed again.

To add this to your Repl repository, open the project and navigate to ‘Secrets’. Here, you can add your OpenAI API key.

key: OPENAI_API_KEY
value: <<api key>>

Step 3: Create a Telegram Bot

Creating your own Telegram bot for communicating with ChatGPT is a simple process that involves the following steps:

  1. Install and open the Telegram app on your device (mobile or desktop) and log in to your account.
  2. In the search bar, type “@BotFather” and select the official BotFather bot from the search results.
  3. Start a chat with the BotFather by clicking the “Start” button or sending the “/start” command.
  4. To create a new bot, send the “/newbot” command to the BotFather. It will prompt you to provide a name for your bot. Choose a unique name that reflects the purpose of your bot.
  5. After selecting a name, the BotFather will ask you to choose a username for your bot. The username must end with “bot,” such as “MyAssistantBot” or “SampleBot.” Ensure that the username is also unique, as duplicate usernames are not allowed.
  6. Once you’ve provided a valid username, the BotFather will create your bot and send you a message with a link to your newly created bot, along with an API token. This token is essential for connecting your bot to the Telegram API and controlling its behavior. Make sure to save the API token securely, as you will need it for future interactions with your bot.
  7. Optionally, you can customize your bot’s appearance by setting a profile picture or adding a description. To do this, send the corresponding commands to the BotFather, such as “/setuserpic” or “/setdescription.”

To add this API Token to your Repl repository, navigate to ‘Secrets’ again and enter the information:

key: TELEGRAM_BOT_TOKEN
value: <<your:token>>

Step 4: Run and Chat via Telegram!

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

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 Telegram bot. Create the following URL and visit it in your browser:

https://api.telegram.org/bot{YOUR_TOKEN}/setWebhook?url={YOUR_WEBHOOK_ENDPOINT}

It will look something like this:

https://api.telegram.org/bot*****:**************/setWebhook?url=https://your-bot-project.username292.repl.co/webhook/

When you visit this URL in your browser, you should see a confirmation message:

Now you can chat with a powerful GPT model via Telegram!

The steps for WhatsApp are similar. Check out this guide on how to do the same for WhatsApp with Twillio.

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 *