/telegram-chatgpt-bot

Integrate ChatGPT to your Telegram. This bot could be invited to a channel or used via DM.

Primary LanguageRustGNU General Public License v3.0GPL-3.0

A Telegram ChatGPT bot

flows.network Discord flows.network Twitter Create a flow

Deploy this function on flows.network, and you will get a Telegram bot that uses ChatGPT to respond to every question in your Telegram DM or channel/group automatically.

image

The example in the above image is to leverage ChatGPT to generate code comments.

Prerequisites

  • You will need to bring your own OpenAI API key. If you do not already have one, sign up here.

  • You also need a bot token to access the Telegram API. If you don't already have one, go to Telegram to get a bot token from @botfather.

Deploy a ChatGPT Telegram bot

To install the ChatGPT Telegram App, we will use flows.network, a serverless platform that makes deploying your own app quick and easy in just three steps.

Prepare the code: fork this repo

Fork this repo and go to flows.network to deploy your function.

Deploy the code on flow.network

  1. Log into flows.network from your GitHub account. It's free.

  2. Click on the "Create a Flow" button to start deploying the ChatGPT GitHub APP

  3. Authenticate the flows.network to access the telegram-gpt repo you just forked. image

  4. Click the Advanced test to see more settings. Here we need to use Environment Variables to pass the Telegram token and OpenAI API key name.

  • telegram_token: Fill in the token you received from Fatherbot.
  • openai_key_name: Fill in the name you want for your OpenAI key. You can put any name here, and we will connect it to the actual key later.

image

  1. Click on the Deploy button to deploy your function.

Configure SaaS integrations

After that, the flows.network will direct you to configure the SaaS integration required by your flow. Since we have configured Telegram in the above step, OpenAI is the only SaaS we need to configure here.

image

Click the "Connect/+ Add new authentication" button to add your OpenAI API key. On the next page, copy and paste your OpenAI API key and then name the key. Note the name you enter here should be the same as the name in the environment variable.

image

Give it a try.

Click on the Check button to see your flow details. As soon as the flow function's status becomes ready and the flow's status becomes running, the Telegram ChatGPT App goes live. Go ahead and send a private message to the bot! You can also invite this bot to your channel/group.

Dev notes

If you want to build locally, make sure you have installed Rust and added the wasm32-wasi target.

cargo build --target wasm32-wasi --release