For developers

I don't want to pick up: an AI secretary in Telegram that calls back and finds out who called

← All articles

This article is written in the first person by one of our users, who chose to stay anonymous. We changed his name to Alibek. He develops apps. His style and voice are kept as is. We only fixed a few grammar mistakes and hid personal data. Huge thanks to Alibek for the article ❤️

Long story short, I don’t pick up calls from unknown numbers. At all. Plus, honestly, live phone conversations make me uncomfortable. I prefer texting in messengers. And I hate voice messages in messengers!

The problem is that after missed calls from unknown numbers I sit there wondering: what if it was a client? What if he liked my portfolio and is actually ready to order an app? Calling back myself and talking takes a lot of energy (for me), and I’d love to just move the conversation to any messenger.

And even when I’ve psyched myself up, pulled myself together and caught the vibe for a phone call, I often run into yet another "great deal" and other scam calls, and I just hang up.

So I made myself a personal phone secretary. Her name is Aisulu, she lives in Telegram, and I can just send her a number. Then she calls back herself, finds out who it was and what they wanted, and sends me a summary: the transcript and the call recording as a voice message. If nobody picks up three times in a row, it’s spam, and she says so. And if it’s really something about app development orders, she asks them to message me on Telegram or WhatsApp.

The calling and the talking are done by the AutoCall.kz voice AI agent, and the bot itself is just a few lines of Python. Below I explain how I built it and share all the code.

How it works

  1. An unknown number calls. I don’t pick up and send the number to the “Who called?” bot.
  2. With one request to the AutoCall.kz API, the bot creates a call campaign to that number with my agent.
  3. Aisulu calls, introduces herself as a secretary and finds out who it is and why they called. She sorts the answers into fields herself: who, where from, why, details.
  4. When the conversation ends, AutoCall.kz pings the bot with a webhook.
  5. The bot sends me the summary, the transcript and the recording as a voice message.

I didn’t build a separate neural network that writes prompts on the fly or retells the conversation. I set up the agent once in the dashboard, and it writes the call summary itself. The bot is just a courier between Telegram and the API.

Example: two calls, two different outcomes

The first one. The number had called twice. Aisulu dialed it three times, 15 minutes apart, but nobody answered. A report landed in Telegram: doesn’t pick up, three attempts, probably spam. Oh well.

No answer after three attempts, and the bot says so
No answer after three attempts, and the bot says so

The second one. A certain Syrym had supposedly sent me money on Kaspi by mistake and was worried I wouldn’t return it. Aisulu wrote down the amount, the date and his name and explained that she would pass everything on to me, and if the transfer really happened, I would definitely return it. A couple of minutes after the call I had everything as text in Telegram.

Call summary, transcript and recording in one chat
Call summary, transcript and recording in one chat

Here’s the audio recording.

Aisulu and the “mistaken Kaspi transfer”

Funny thing: the AI agent apparently knows about the mistaken transfer scheme, so she said that "Alibek will refund it right in the banking app". The classic move: they ask you to return the money to “another card” or “mom’s number” instead of reversing the same transfer. I just refund the sender in the banking app, and that’s it.

Step 1. Creating the secretary

The AutoCall.kz dashboard has an “AI agents” section. You don’t have to write the prompt by hand: you describe what you need in your own words, and the AI asks you questions and builds the scenario. I picked a female voice and named her Aisulu:

Setting up the agent in the dashboard
Setting up the agent in the dashboard
Alibek

hi) i want to make myself a secretary. you’ll be Aisulu, my AI secretary. my name is Alibek. when an unknown number calls, i don’t pick up cause i don’t like talking, and i send the number to a bot in telegram, and you call back. you need to find out who called, where from, why and generally as many details as possible. you write it all down, and i read it all later in telegram

Aisulu

Hello, Alibek! Great task, I’d be happy to be your personal secretary.

I’ve already sketched the first version of the scenario and the call logic.

How I will start the conversation (in 3 steps):

1. Greeting: “Hello, hi there!” (pause, wait for a reply)

2. Engagement: “Am I catching you at a bad time? Can you talk?” (pause)

3. Introduction and purpose: “My name is Aisulu, I’m Alibek’s secretary. I’m Alibek’s personal assistant. You just called him, and he can’t answer right now. Could you tell me your name and what it’s about?”


What I’ll collect in the report for you:

Number Status Dur. Who called Company / From Reason for the call Details and requests
+7701XXXXXXX Answered 65 Yerlan StroyMarket LLP Invoice for a batch of cement Asks for a call back today before 18:00

Does this report layout and the opening wording work for you?

And tell me a couple of things:

1. What do you do, or what kind of business do you have? (So I understand the context if people start throwing professional terms at me).

2. What should I do if it’s obvious spam or cold sales (loans, surveys, courses)? Just end the call politely?

Alibek

report’s fine 👍 i freelance, building apps and tg bots, sometimes clients call. if it’s spam and sales, say bye politely, but still write down whoever it was. and one more important thing: say that Alibek is sick, lost his voice and can’t talk on the phone right now, so you’re calling back. just don’t promise anything on my behalf, and if they ask for a call back or don’t want to say what they wanted, better tell them to text me on Telegram or WhatsApp

Aisulu

Got all your edits, Alibek!

I updated the scenario:

Reason for the callback: Now I explain right away that you’re sick, you’ve lost your voice and can’t talk on the phone for now, so I’m the one calling back.

Spam and sales: If it’s advertising or sales, I say goodbye politely, but I always note in the report who called and why.

If they’re secretive or ask for a call back: I say I can’t promise anything on your behalf and suggest they message you directly on Telegram or WhatsApp.

By the way, a basic version of me is already ready: you can press “Test” and talk to me live. Meanwhile, we’ll keep refining me.

Should I send the person an SMS with a link to your Telegram/WhatsApp if they ask for a call back or have an urgent question? Or do we stick to the call for now?

Alibek

nah, no sms needed. thanks. most important, try to find out everything pls

Aisulu

Deal, no SMS!

I will carefully and politely ask follow-up questions to gather as many details as possible about the task, deadlines and project, but I won’t promise anything extra. I’ll write all the data into the report right away.

We’re all set. Want to test a call right now, or shall we add more details?

A couple of messages and the secretary is ready. Here’s what came out:

Aisulu’s full scenario
## Who you are
Aisulu is Alibek’s personal AI secretary (Alibek is a freelancer who builds apps and Telegram bots). You call people who have just called Alibek to find out why they called and pass detailed information on to him.
Personality: polite, attentive, focused, businesslike.

## Call goal
Find out who is calling, from which company, about what (app/bot development, partnership, spam/sales) and collect as many details as possible.

## Conversation flow
1. First phrase EXACTLY: “Hello?! Hi!” and THAT’S IT. Then stay silent and wait for a response.
2. Once they respond, an engagement phrase: “Am I catching you at a bad time? Can you talk?” And wait again.
3. Once they answer, the introduction and purpose EXACTLY: “I’m Alibek’s personal assistant. You just called him, but he’s unwell and has lost his voice, so he can’t talk on the phone for now and asked me to call you back. Could you tell me your name and what it’s about?”
4. If they’re silent after the first phrases, ask once: “Hello, can you hear me?”. If it’s still silent, say goodbye politely and end the call.
5. Find out their name, company/industry and the reason for the call. Ask follow-up questions to learn as much as possible about the project or task.
6. If it’s spam, advertising or sales, say goodbye politely and end the call, but still be sure to record in the report who called and what they offered.
7. If the caller refuses to introduce themselves, doesn’t want to say why they called or just asks for Alibek to call back, suggest they message Alibek directly on Telegram or WhatsApp.
8. Find out the details: how urgent it is, details of the project or offer.
9. Confirm that all the details are recorded and will be passed on to Alibek. Say goodbye politely.

## What to collect
- caller_name: the caller’s first and last name.
- company: company, project or “personal / individual”.
- purpose: reason for the call (app order, Telegram bot, partnership, spam/advertising).
- details: details of the request.

## Boundaries
- Don’t promise anything on Alibek’s behalf (no deadlines, no prices, no agreement to projects/meetings).
- Don’t disclose Alibek’s personal information, except that he’s unwell and has lost his voice.
- If they refuse to talk or ask for a call back, suggest messaging Alibek on Telegram or WhatsApp.

Fields the bot will receive: caller_name (who), company (where from), purpose (why) and details (details). Remember these keys, the bot prints exactly them.

The finished agent and its id, the bot will need it
The finished agent and its id, the bot will need it

Step 2. API key

In the “API” section I create a separate key just for the bot. Minimal permissions: call campaigns and calls.

A separate key for the bot: only call campaigns and calls
A separate key for the bot: only call campaigns and calls

Step 3. The bot itself

I register the bot with @BotFather and get my Telegram ID from @userinfobot: the bot listens only to me. All the code is in one file:

bot.py

import asyncio
import html
import os
import re
import shutil

from aiohttp import ClientSession, web
from aiogram import Bot, Dispatcher, F
from aiogram.types import BufferedInputFile, Message

API = "https://autocall.kz/api/v1"

TOKEN = os.environ["TELEGRAM_TOKEN"]
OWNER_ID = int(os.environ["OWNER_ID"])
AUTOCALL_KEY = os.environ["AUTOCALL_KEY"]
AGENT_ID = int(os.environ["AGENT_ID"])
PUBLIC_URL = os.environ["PUBLIC_URL"].rstrip("/")
HOOK_SECRET = os.environ["HOOK_SECRET"]
PORT = int(os.environ.get("PORT", 8080))

FIELDS = {
    "caller_name": "Who",
    "company": "From",
    "purpose": "Why",
    "details": "Details",
}

MISSED = {
    "no_answer": "doesn’t pick up",
    "busy": "line always busy",
    "error": "number doesn’t exist",
    "spam": "asked not to call again",
}

bot = Bot(TOKEN)
dp = Dispatcher()
http: ClientSession
seen: set[int] = set()


def phone(text: str) -> str | None:
    digits = re.sub(r"\D", "", text)
    if len(digits) == 10:
        digits = "7" + digits
    if len(digits) != 11 or digits[0] not in "78":
        return None
    return "+7" + digits[1:]


async def to_voice(wav: bytes) -> bytes | None:
    if not shutil.which("ffmpeg"):
        return None
    proc = await asyncio.create_subprocess_exec(
        "ffmpeg", "-loglevel", "error", "-i", "pipe:0", "-c:a", "libopus", "-b:a", "24k", "-f", "ogg", "pipe:1",
        stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE,
    )
    ogg, _ = await proc.communicate(wav)
    return ogg if proc.returncode == 0 else None


@dp.message(F.from_user.id == OWNER_ID, F.text)
async def callback_request(message: Message):
    number = phone(message.text)
    if not number:
        await message.answer("send a number, e.g. +7 701 123 45 67")
        return

    payload = {
        "name": f"Who called {number}",
        "type": "agent",
        "agent_id": AGENT_ID,
        "list_id": [{"number": number}],
        "time_from": "11:00:00",
        "time_to": "21:00:00",
        "max_tries": 3,
        "tries_interval": 15,
        "record": True,
        "callback_url": f"{PUBLIC_URL}/hook/{HOOK_SECRET}",
    }
    async with http.post(f"{API}/autocalls", json=payload) as r:
        if r.status != 201:
            error = (await r.json(content_type=None) or {}).get("message", r.status)
            await message.answer(f"didn’t work: {error}")
            return

    await message.answer(f"Aisulu will call {number} back and find out everything. if no one picks up, she’ll try two more times")


async def fresh(call: dict) -> dict:
    async with http.get(f"{API}/autocalls/{call['autocall_id']}") as r:
        if r.status != 200:
            return call
        calls = (await r.json())["calls"]["data"]
    return next((c for c in calls if c["id"] == call["id"]), call)


async def report(call: dict):
    number = call["number"]

    if call["status"] in MISSED:
        text = f"{number} {MISSED[call['status']]}, attempts: {call['tries']}"
        if call["status"] in ("no_answer", "busy"):
            text += "\nprobably spam"
        await bot.send_message(OWNER_ID, text)
        return

    # fields and transcript keep filling in for about ten seconds after the call
    await asyncio.sleep(15)
    call = await fresh(call)

    data = call.get("data") or {}
    lines = [f"<b>{label}:</b> {html.escape(str(data[key]))}" for key, label in FIELDS.items() if data.get(key)]
    await bot.send_message(OWNER_ID, f"talked to {number}\n\n" + "\n".join(lines), parse_mode="HTML")

    async with http.get(f"{API}/calls/{call['id']}/transcript") as r:
        text = (await r.json()).get("text") if r.status == 200 else None
    if text:
        quote = html.escape(text[:3500])
        await bot.send_message(OWNER_ID, f"<blockquote expandable>{quote}</blockquote>", parse_mode="HTML")

    async with http.get(f"{API}/calls/recordings/{call['id']}") as r:
        if r.status != 200:
            return
        wav = await r.read()

    voice = await to_voice(wav)
    if voice:
        await bot.send_voice(OWNER_ID, BufferedInputFile(voice, "call.ogg"))
        return
    await bot.send_document(OWNER_ID, BufferedInputFile(wav, f"{number}.wav"))


async def hook(request: web.Request) -> web.Response:
    if request.match_info["secret"] != HOOK_SECRET:
        raise web.HTTPNotFound()

    call = (await request.json()).get("call")
    if not call or call["status"] == "in_queue" or call["id"] in seen:
        return web.Response()

    seen.add(call["id"])
    asyncio.create_task(report(call))
    return web.Response()


async def main():
    global http
    http = ClientSession(headers={"Authorization": f"Bearer {AUTOCALL_KEY}", "Accept": "application/json"})

    app = web.Application()
    app.router.add_post("/hook/{secret}", hook)
    runner = web.AppRunner(app)
    await runner.setup()
    await web.TCPSite(runner, port=PORT).start()

    try:
        await dp.start_polling(bot)
    finally:
        await http.close()


if __name__ == "__main__":
    asyncio.run(main())

A couple of notes on the code.

  • One request per call. POST /autocalls with type: agent creates a call campaign of one number with my agent. max_tries: 3 and tries_interval: 15 give three attempts 15 minutes apart, record: true records the conversation, and the result arrives at callback_url.
  • I skip intermediate events. Between attempts the call arrives with the status in_queue. The final status is success if they talked, or no_answer and busy if not. I react only to the final one.
  • Why I wait 15 seconds. I noticed that the report fields and the transcript can keep filling in for a few seconds after the call on the AutoCall.kz side. Probably a summarizer and a separate LLM are at work. So the bot waits and re-reads the call via GET /autocalls/{id} to send everything in full, not half of it.
  • I answer the webhook right away. The webhook returns 200 immediately. The bot drops duplicates of the same call.
  • A voice message instead of a file. The recording comes as WAV. If ffmpeg is installed, the bot converts it to OGG/Opus, and in Telegram it’s a regular voice message with a waveform and a "Transcribe" button. Without ffmpeg, it sends a file.

Step 4. Launch

terminal

pip install aiogram aiohttp
export TELEGRAM_TOKEN=123456:ABC
export OWNER_ID=123456789
export AUTOCALL_KEY=your_key
export AGENT_ID=agent_id
export PUBLIC_URL=https://bot-address
export HOOK_SECRET=any-long-string
python bot.py

The bot needs a public https address; AutoCall.kz sends the call result there. You don’t need a server for this: you can run the bot right from your laptop and expose it with Cloudflare Tunnel. The command cloudflared tunnel --url http://localhost:8080 gives you an address; put it in PUBLIC_URL.

The full code, with a README and a sample config, is on GitHub. Fork it and tweak it for yourself.

What it costs

I pay only for the conversation, per second: the call plus the AI work.

Plan Minute of talking with the secretary Recording 1 unanswered attempt 3 unanswered attempts
BRONZE 148.8 ₸ 5 ₸ 0 ₸ 0.7 ₸
SILVER 102.6 ₸ 3 ₸ 0 ₸ 0.5 ₸
GOLD 79.8 ₸ 0.5 ₸ 0 ₸ 0.3 ₸

A typical conversation like this fits within a minute. Current prices and terms are on the pricing page.

I topped up my balance with 1200 ₸, and over a week about 190 ₸ was spent.

What else you could add

  • Create another agent for other tasks (passing on some information or payment reminders) and pick the task right in the bot with buttons.
  • I’m waiting for inbound calls to appear in AutoCall.kz, and then I’ll be able to forward calls from my phone to AutoCall.kz and get the summary straight in the Telegram bot.

From AutoCall.kz: inbound calls are already here, and another of our customers did exactly that. Read An AI assistant answers calls and writes to Telegram.

I hope this article helps everyone who doesn’t like talking on the phone and doesn’t like voice messages ;)

The AutoCall.kz team is happy to add bonus funds to your dashboard balance if you offer your own article about how you use our service.

Frequently asked questions

Is it legal to call a stranger back with an AI voice?

You are calling back a number that called you. It’s a regular callback, only your secretary makes it. The AutoCall.kz agent doesn’t pretend to be human: if asked “are you a robot?”, it honestly says it’s an AI assistant. The bot isn’t meant for broadcasts to other people’s databases, and every call campaign goes through moderation.

Do I need a server to run the bot?

You need a public https address where AutoCall.kz will send the call result. You can run the bot right from your laptop and expose it with Cloudflare Tunnel in one command, or use any cheap VPS.

How quickly will the secretary call back?

Every call campaign goes through automatic moderation. Usually it takes seconds; sometimes the campaign goes to a human moderator. Calls go out only within the time window you chose for the campaign. If no one picks up, the secretary tries two more times, 15 minutes apart.

Does the secretary speak Kazakh?

Yes. By default the conversation is in Russian, and if the other person switches to Kazakh, the agent switches to Kazakh too.

What should I do if someone sent me money on Kaspi by mistake and asks for it back?

Don’t transfer money manually to a card or number someone dictated to you. Check in your banking app that the transfer really arrived, and return it with the built-in refund-to-sender feature: the money goes back where it came from. If in doubt, contact your bank’s support.

More on voice agents in the article AI agent or scenario: what to choose for a call campaign, and the full API spec is in openapi.yaml.

Build your own secretary in an evening

Sign-up is free, and the test balance is enough to talk to the agent live.

Try it free →