ad
ad
Topview AI logo

AI can talk now? Create a Conversational AI Chatbot for Telegram! ?

Science & Technology


Introduction

In today's digital landscape, integrating AI into our daily communications can be both fun and useful. This article will guide you through the steps to create a Telegram chatbot that can interact with you using voice messages, powered by OpenAI's capabilities.

Prerequisites

To set up your conversational AI chatbot, you'll need the following:

  1. A Telegram account.
  2. An OpenAI account along with your API key.
  3. N8N installed on your system.

If you haven't installed N8N yet, check out my previous video that covers two different installation methods.

Getting Started

  1. Open N8N: Once installed, open N8N and create a new workflow. Name it "Telegram AI Voice Assistant."

  2. Setting up the Trigger:

    • Click on the first step and type "Telegram".
    • Choose "On Message" under the triggers.
    • Under credentials, create a new credential named "Telegram AI Voice Assistant" and add your Access Token from BotFather where you created your new bot.
  3. Test Your Bot: Click on the test step to send a message to capture it in your N8N instance.

  4. Filter Users:

    • Add an "IF" condition step named "Filter Other Users."
    • Set the chat ID to ensure that only you can interact with the bot. If someone else sends a message, the bot will do nothing.
  5. Receive Voice Messages:

    • The bot will ignore text or image messages and will only respond to voice messages.
    • Send a voice message from Telegram (e.g., "Hey, what's up?") and check the captured data.
  6. Retrieve the Voice File:

    • To get the actual voice file, add a step to retrieve it using the file ID from the voice object.
  7. Transcribing Voice to Text:

    • Use your OpenAI API key to transcribe the voice message into text.
    • Add the OpenAI node for transcribing and test it.
  8. Creating AI Responses:

    • Add another OpenAI node and set it to use your model (e.g., GPT-4 or a mini version).
    • Specify instructions for your AI, such as the need for brevity and a friendly tone.
  9. Convert Text to Voice:

    • Add another OpenAI step to generate audio from the AI’s response.
  10. Sending Voice Messages via HTTP:

    • Unfortunately, N8N does not support sending voice messages directly.
    • You will need to set up an HTTP request to send the audio file as a voice message. Use the Telegram bot API documentation to help build this request.
  11. Activating the Workflow:

    • Make sure to activate the workflow. Test it by asking a question, like the difference between NFTs and cryptocurrencies.
  12. Longer Conversations:

    • You can even have back-and-forth conversations. For example, you can instruct the bot, "From now on, speak to me in English, but reply in German."

Conclusion

With this setup, your Telegram bot is ready to chat, responding to your voice messages and even understanding the context of a conversation. This simple system harnesses the power of AI, bringing conversational technology right into your pocket.


Keyword

  • Telegram
  • Chatbot
  • OpenAI
  • N8N
  • Voice Message
  • Transcribe
  • API Key

FAQ

Q: What do I need to create a conversational AI chatbot on Telegram?
A: You'll need a Telegram account, an OpenAI account with an API key, and N8N installed on your system.

Q: Can the bot only respond to voice messages?
A: Yes, the bot is set up to ignore text and image messages, only responding to voice messages.

Q: How can I ensure that only I can interact with the bot?
A: You can filter users by setting a condition where the chat ID matches your user ID, preventing others from sending messages.

Q: Does N8N support sending voice messages directly?
A: No, N8N does not support sending voice messages, but you can use HTTP requests to send audio files as voice messages through the Telegram API.

Q: Can the bot handle long conversations?
A: Yes, the bot can maintain context throughout your conversation, making it capable of more interactive dialogues.

ad

Share

linkedin icon
twitter icon
facebook icon
email icon
ad