Telegram Assistant with OpenAI

tg openai tg

An intelligent Telegram bot that processes user messages in real-time using OpenAI, providing instant answers.

1. Creating a telegram bot and the first module in make.

You will need a make account to create a script. You can register here.

You’ll also need an OpenAI account.

The first thing to do is to create the bot itself in Telegram. Type “BotFather” into the search bar.

Type the command /newbot, enter the bot’s name and nickname. The bot will generate an token, which will be needed in the make script.

Please note:

The token is unique and must be kept secure. You will need this token to connect the bot to Make.

The bot will not appear in your Telegram until you send it the first message.

Next, go to make and create a new scenario.

 

Specify a name for the scenario and create a new module: Telegram Bot.

Next, select Watch Updated and click Add to create a new webhook for this bot.

…and click Add to create a new webhook for this bot.

Set the connection name and specify the token of our Telegram bot.

token

Click Save, Save, copy the webhook address and paste it into the address bar. You should see the following message:

Click OK to save the module and click Save to save the scenario.

To test the script click Run once and type some message to the telegram bot. If everything works without errors, the module will receive new data.

2. Adding an OpenAI module

Add the OpenAI module and select Create a Completion (Prompt) from the list:

In the opened form you need to create a connection with OpenAI, for this you need ApiKey, which you need to create on planform.openai.com. In the Model module, select gpt-4o-mini. Role – User. Text Content. And specify the number of tokens. Press ok.

Save the scenario

add a telegram module to send a reply

In the connection field, select the webhook that was created for this telegram bot.

Fill in the fields shown in the image to the right and click ok.

Save scenario.

Turn on the script and test the telegrambot.

tg test

As you can see the bot responded in German. If you ask the bot to answer in English, it will answer in English. But if we send a message in German again, it will reply in German. Let’s change the text in the Text field of the OpenAI module as follows:

Respond in English only, regardless of the input language. Input: 1.message.text

Save the script and test the bot again. Now we see that the bot responds in English, although we sent the message in German.

Leave a Reply

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