• Mail us
  • Book a Meeting
  • Call us
  • Chat with us

AI/ML

Building a Telegram AI Bot with N8N


Introduction

The provided source explains how to create a Telegram AI bot using the open-source workflow automation tool N8N. The tutorial focuses on utilizing a pre-built template to streamline the development process, although users also have the option to create the workflow from scratch. The bot described in the source takes user prompts via Telegram and responds with an image generated by OpenAI.

What is N8N?

N8N is an open-source workflow automation tool that allows users to automate tasks and workflows by connecting various applications, services, and APIs. It employs a visual, node-based interface, similar to flowcharts, enabling users to create automated workflows without needing to write any code. N8N offers flexibility through its ability to integrate with a wide array of popular applications and services like Google Drive, Slack, and GitHub. This integration capability allows for the automation of diverse tasks such as data synchronization, notifications, and data processing.

Building the Telegram AI Bot Using a Template

The tutorial guides users through building the bot using a pre-designed template within the N8N platform.

  • Upon logging into N8N, users are directed to the canvas page.

  • To access and use templates, users need to navigate to the templates section located in the left sidebar.

  • The specific template to search for is "Telegram AI bot with LangChain nodes". Alternatively, users can click on a provided direct link to access the template.

  • After finding the template, a "Use Workflow" pop-up will appear, which users should click.

  • Users with multiple N8N instances can then select the specific instance they wish to use for this template.

Configuring Telegram Credentials

The next step involves configuring the necessary credentials for Telegram integration.

  • A pop up will prompt the user to configure Telegram credentials, and they should click on "Create New" their "Telegram credential".

  • To obtain the required token, users need to go to their Telegram account and search for the BotFather account.

  • Within the BotFather chat, the command /newbot should be entered.

  • BotFather will then ask for a name for the application, and upon providing it, will furnish an access token for the HTTP API as shown in the image below. Note: The actual image mentioned is not provided in the source text.

  • The source advises referring to the Telegram N8N documentation for additional configuration or information.

  • Finally, the copied access token from BotFather needs to be pasted into the configuration section provided in N8N.

Configuring OpenAI Chat Model Credentials

Following the Telegram credentials, the OpenAI Chat Model needs to be configured.

  • Users should click on "Create new OpenAI Chat Model credential".

  • To obtain the API key, users need to navigate to the OpenAI API Keys dashboard and create a new API key for the application.

  • Once created, this API key should be added to the "API Key" section in the N8N configuration.

  • There is also an optional field for the organization ID.

Workflow Operation

The configured workflow operates as follows:

  • It listens for incoming events from Telegram.

  • The received request is then forwarded to an AI agent (OpenAI) for processing.

  • After the AI agent processes the request, the output image is sent back to Telegram.

  • Users can test the workflow by clicking on "Test Workflow". The visual representation of this workflow is described as a "map" in the source.

Webhook Command

The source mentions a specific webhook command that can be found in the starting components of the workflow. This webhook is used to trigger the workflow and provide the prompts necessary for the application to create images using OpenAI. An example of the webhook command provided is:

https://<Elestio Domain>/webhook-test/<Your N8N Service Id>/webhook

Conclusion

By following these steps and utilizing the provided template, users can successfully create a Telegram AI bot with N8N that can take text prompts and respond with corresponding images generated by OpenAI. The source encourages users to explore Elestio resources and the official N8N documentation to further enhance their understanding of N8N and its capabilities. It also suggests the possibility of creating multiple such workflows based on the OpenAI function type. N8N, being an open source platform, provides a flexible way for coders to automate tasks and grow their skills.

 

Ready to transform your business with our technology solutions? Contact Us  today to Leverage Our AI/ML Expertise. 

Share

facebook
LinkedIn
Twitter
Mail
AI/ML

Related Center Of Excellence