AI explained

ChatGPT on Telegram: bridge a model to a bot safely

A Telegram bot with an AI behind it is a small bridge between two APIs. Here is how it works, the choices that matter for customers, and an example you can adapt.

By the Askocto team · · 5 min read

Running ChatGPT on Telegram means building a bot account that receives messages, passes each one to a model, and sends the answer back. The bridge is small. The decisions around it are not: which content the model answers from, how one chat becomes one conversation, what happens when it cannot help, and where customer data ends up. This guide covers those decisions for a business bot, not a hobby project.

In short: A Telegram bot is a thin bridge. Keep the logic, knowledge and handoff in the agent behind it, map each Telegram chat to one conversation, and decide in advance what the bot must refuse.

How the pieces connect

Three parts are involved:

  1. The Telegram bot. An account your code controls. Telegram's own bot documentation describes how to create one and how messages reach your code.
  2. The bridge. A small service you host. It receives a message, calls the AI, and sends the reply.
  3. The AI behind it. Either a bare model, or a configured agent with sources, procedures and rules.

Option three is the one that matters for customers. A bare model answers from general knowledge. A configured agent answers from your content and follows your procedures. Start by deciding which one the bridge will call.

Askocto's built-in channels are the website widget, email, voice, WhatsApp, Instagram, Messenger, Slack, SMS through Twilio and the Help page. Telegram is not one of them, so a Telegram bot reaches an Askocto agent through the chat API, using a bridge you host. That keeps your knowledge, procedures and guardrails in one agent, whichever channel a customer uses.

Design decisions before you write code

One chat, one conversation

Map each Telegram chat to one conversation id and store the mapping in a database. If you send every message as a new conversation, the AI forgets context and customers repeat themselves.

Plain text only, to start

Chat apps have their own formatting and buttons. Begin with plain text replies and add formatting later. Long answers read badly on a phone, so tell the agent to keep replies short.

Handoff

Decide what "I need a person" does. Options: send the customer a link to email or a form, create a ticket in your helpdesk with the transcript, or notify a staff member. Pick one, test it, and make sure the bot tells the customer what will happen next.

A chat message may contain names, orders and anything else the customer types. Tell customers at the first message that they are talking to an AI, and where to find your privacy policy. Check your obligations with your own advisers, since this is not legal advice.

A minimal bridge

The example below shows only the call to an Askocto agent. The Telegram side depends on the library you choose, so check Telegram's current documentation for how your code receives messages and sends replies.

// Maps a Telegram chat id to an Askocto conversation id.
// Use a database in production, not memory.
const conversations = new Map()

async function askAgent(telegramChatId, text) {
  const res = await fetch("https://api.askocto.co/v2/agents/agt_123/chat", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.OCTO_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      messages: [{ role: "user", content: text }],
      conversationId: conversations.get(telegramChatId),
      stream: false,
      metadata: { channel: "telegram", chatId: String(telegramChatId) },
    }),
  })
  if (res.status === 429) return "We are busy right now. Please try again in a minute."
  if (!res.ok) return "Sorry, something went wrong. A person will follow up."
  const data = await res.json()
  conversations.set(telegramChatId, data.conversationId)
  return data.message.content
}

The first request has no conversation id, so the response creates one and your bridge stores it. The key stays on your server, never in a message or a public file. The chat endpoint reference lists the request and response fields.

What to test

Before you share the bot's link:

  • Ten questions the agent should answer from your content
  • Five questions it should decline
  • One request for a person, to check the handoff
  • A long message, a message in another language and a message with only an emoji
  • A forced error, such as a wrong key in a test environment, to see the fallback

Testing an AI support agent before launch describes a fuller routine. In Askocto, the Playground in the Test tab shows which source and procedure produced each answer, so you can fix problems in the agent instead of in the bridge.

Run it quietly for a week

Do not announce the bot on day one. Share the link with colleagues and a few friendly customers, then read every conversation for a week. Mark each answer as correct, partly correct or wrong, and note the questions that were not in your content. Each gap is a source to add or a procedure to write. A bridge that runs for a week with no surprises is ready for a wider audience. Keep reading transcripts after launch, at least weekly, because customers use a chat app differently from a website: shorter messages, more typos, voice notes you cannot read and screenshots the bot cannot see unless you plan for them. Decide in advance what the bot says when it receives a file or image, and test that too.

Where Telegram fits among channels

Add a channel when customers already use it, not because you can. If most of your customers write on your site or WhatsApp, start there. The WhatsApp support agent guide covers a channel with built-in setup, and the multichannel chatbot guide explains how to keep answers consistent across channels. If you are comparing a direct model call with a configured agent, see the ChatGPT API guide, and the product overview for the channels an agent covers without a bridge.

Frequently asked questions

Can I run ChatGPT on Telegram?

Yes. You create a Telegram bot and a small service that passes each message to the AI and returns the answer. Use a configured agent if customers will rely on the answers.

Do I need to code to put an AI on Telegram?

For a custom bot, yes, a small bridge service is code. Check whether your support platform supports the channel directly before you build one.

How do I stop the bot from making things up?

Have it answer from your own content, add a rule to decline questions outside it, and test with questions that are not in your sources.

Is a Telegram bot safe for customer data?

It depends on what customers send and how you store it. Limit what you log, tell customers they are talking to an AI, and review with your privacy contact.

Train an agent on your own help center

Askocto answers the repeat questions across chat, email and voice and hands the hard ones to your team.

Keep reading

All articles
AI explainedchatgpt adoption
Jul 23, 20254 min read

ChatGPT adoption at work: a plan for rolling it out safely

Roll out ChatGPT at work with a pilot, a short use policy, clear data rules, training and simple measures. Also see when a purpose-built support agent is the better tool.

Read article
AI explaineduse chatgpt for business
May 17, 20255 min read

How to use ChatGPT for business: a practical rollout plan

A general assistant like ChatGPT helps most when each use has an owner, a data rule and a review step. Here is how to choose the jobs, set the rules and test the results.

Read article
AI explainedchatgpt agent mode
May 11, 20254 min read

ChatGPT agent mode vs a deployed support agent: how to decide

Agent mode lets a general assistant take multi-step actions for one person. Learn how to evaluate it on your tasks, which guardrails to apply and when to use a deployed support agent.

Read article