What Is a Personal AI Assistant
A personal AI assistant is a program that receives your messages, thinks using a language model, and performs tasks. You already know ChatGPT in the browser. The difference here is that the assistant lives in YOUR chat (Telegram), replies 24 hours a day, and can do real things: check the weather forecast, save a note, create a reminder. It doesn't just chat: it takes action.
🧠 Analogy: The Intern Who Lives in the Chat
Think of a super dedicated intern. You send a message in the chat: "find out how much time is left before the meeting." They read it, understand, check the calendar, and get back to you. You don't need to explain how to search the calendar: they know. That's exactly what your AI assistant is, but digital and available anytime.
- •You send: a natural language message ("summarize this text for me")
- •It thinks: the AI model interprets what you want
- •It acts: use a tool if needed
- •It replies: sends the response back in the chat
💡 Why “Jarvis”?
Jarvis is Iron Man's assistant in the movies: you speak, he understands, and he gets things done. Your Jarvis won't pilot an armored suit, but he'll help you in your day-to-day life. The concept is the same: a an assistant that listens to natural language and executes. You'll discover that putting one together is simpler than it seems: just combine three pieces (a chat, a brain, and a few tools).
The Basic Architecture
Every assistant follows the same four-step flow: the bot receives the message, the AI model thinks, the tools run, and the response comes back. Understanding this path makes everything easier, because each piece you build in the next topics fits into this diagram.
👁 The four steps, in order
- 1.Receives: you send "what time is it in Tokyo?" on Telegram. The bot (your code) receives this text.
- 2.Think: the bot sends your message to the AI model. The model understands the intent.
- 3.Run: if it needs external data, the model asks to use a tool (e.g., check the time).
- 4.Responds: the final response goes back through the bot to your Telegram chat.
💡 Tip: just three pieces
At its core, the whole assistant fits into three pieces: the chat (Telegram, where the conversation happens), the brain (the LLM, which thinks) and the tools (functions that perform actions). If you always know which piece you’re working on, you’ll never get lost in the code.
Creating the Telegram Bot
Telegram has an official, free way to create bots: the BotFather. It’s a bot that creates bots. You talk to it, give your assistant a name, and get a token (a unique password that gives your code control of the bot). Without a token, your code can't send or receive messages.
Open BotFather
On Telegram, search for @BotFather (the official one has a blue verified badge). Click "Start".
Create the bot
Enter the command and follow the prompts: display name and username (must end in "bot").
/newbot
# BotFather asks for the name:
My Jarvis
# And the username (must end in "bot"):
meu_jarvis_bot
Store the token
BotFather replies with the token. It looks like this (copy it and store it carefully):
Use this token to access the HTTP API:
7891234567:AAH4k_exemplo-de-token-NAO-use-o-real
Polling (simplest)
Your code keeps asking Telegram "any new messages?" from time to time. You don't need a domain or HTTPS. Ideal for getting started and running on a VPS.
- ✓Runs anywhere
- ✓Zero network configuration
Webhook (more advanced)
Telegram notifies your server whenever a message arrives. It’s more efficient, but requires a public HTTPS address. Save this for later.
- ✓Instant response
- ✓Lower network usage
⚠️ Common Error
Problem: "I pasted the token into a file and pushed it to GitHub. Now it’s leaked."
Solution: The token is a password. Anyone who has it controls your bot. Never put the token directly in your code or in a public repository. Use a file .env (you'll see this in topic 6) and add .env no .gitignore. If it leaked, contact BotFather and use /revoke to generate a new token.
Connecting the Brain: Claude or GPT
Now your bot needs a brain. Instead of programming rules like “if the message is X, reply with Y,” you send the user’s message to an AI model (Claude from Anthropic or GPT from OpenAI), and it returns the answer. Technically, this is a API call: your code sends a request over the internet and gets the response back.
The bot that only responds (no AI yet)
Start simple: receive a message and repeat it. Here's how in Python with the library python-telegram-bot.
# install the library
$ pip install python-telegram-bot anthropic
import os
from telegram.ext import Application, MessageHandler, filters
async def responder(update, ctx):
texto = update.message.text
await update.message.reply_text("You said: " + texto)
🤖 Now with an AI brain
Instead of repeating the text, you send the message to the model and return its response. The "API key" is the password that gives you access to the model (get one from console.anthropic.com or platform.openai.com).
from anthropic import Anthropic
cliente = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
async def responder(update, ctx):
resp = cliente.messages.create(
model="claude-3-5-haiku-latest",
max_tokens=500,
messages=[{"role": "user",
"content": update.message.text}])
texto = resp.content[0].text
await update.message.reply_text(texto)
O prompt is the content you send; the response comes in resp.content[0].text.
👁 What you’ll see in the chat
# You on Telegram:
You: explica o que e Git em uma frase
# The bot (AI brain) responds:
Jarvis: Git is a system that saves the
history of your code, allowing you to
go back in time and work as a team.
💡 Tip: start with the cheaper model
Each API call costs money (a few cents, but it adds up). While you're testing and making mistakes, use a small, inexpensive model (like Haiku or GPT-mini). Once the assistant is polished, you can change one line (the model name) to use a more powerful one. That way, you won't waste money while learning.
Skills and Commands
So far, your Jarvis only chats. For it to perform actions, you create commands. In Telegram, commands start with a slash: /start, /ajuda, /nota. Each command points to a function in your code. It's the simplest way to give your assistant "skills".
Mapping /command to an action
You register a CommandHandler for each command. When the user types /nota comprar pao, the function receives the text and acts.
from telegram.ext import CommandHandler
async def cmd_start(update, ctx):
await update.message.reply_text("Hello! I'm Jarvis.")
async def cmd_nota(update, ctx):
texto = " ".join(ctx.args)
salvar_nota(texto) # your function
await update.message.reply_text("Note saved: " + texto)
app.add_handler(CommandHandler("start", cmd_start))
app.add_handler(CommandHandler("nota", cmd_nota))
👁 What you’ll see in the chat
You: /nota comprar pao e leite
Jarvis: Note saved: buy bread and milk
You: /ajuda
Jarvis: Commands: /nota, /tempo, /lembrete
✓ What TO DO
- ✓Always create one
/ajudathat lists the commands - ✓Give short, clear names (
/tempo,/nota) - ✓Confirm the action with a response ("Note saved")
✗ What NOT to do
- ✗Creating 20 commands before the bot works
- ✗Confusing names (
/xpt2) - ✗Leave the user without feedback (silence makes it seem broken)
💡 Tip: commands in the Telegram menu
Go back to BotFather and use /setcommands to register the list of commands. That way, when you type "/" in the chat, a nice menu appears with the available commands. It's a small detail that makes your Jarvis look professional.
Deploy: Running 24/7 on the VPS
Your Jarvis only responds while the code is running. On your computer, it stops when you close the terminal or turn off the machine. To respond at any time, it needs to live on a VPS (the Trilha 3 server) and run as a systemd service, which starts automatically and restarts if it crashes.
Step 1: Upload the code and create the .env
On the VPS, the file .env stores the tokens outside the code.
$ nano .env
# inside the file:
TELEGRAM_TOKEN=7891234567:AAH...
ANTHROPIC_API_KEY=sk-ant-...
# and protect it so no one can read it
$ chmod 600 .env
Step 2: Create the systemd service
Create the file /etc/systemd/system/jarvis.service.
[Unit]
Description=Jarvis Bot
After=network.target
[Service]
WorkingDirectory=/home/deploy/jarvis
EnvironmentFile=/home/deploy/jarvis/.env
ExecStart=/usr/bin/python3 bot.py
Restart=always
[Install]
WantedBy=multi-user.target
Step 3: Start it and watch it run
# reloads the list of services
$ sudo systemctl daemon-reload
# starts now and also on boot
$ sudo systemctl enable --now jarvis
# check the status
$ sudo systemctl status jarvis
● jarvis.service - Jarvis Bot
Active: active (running)
⚠️ Common Error
Problem: "The service won’t start, and the status says failed."
Solution: Almost always, it’s a wrong path or a missing variable. Check the logs with journalctl -u jarvis -n 50. Check whether the WorkingDirectory exists, if the .env has both tokens and whether the Python path is correct (test with which python3).
✓ What TO DO
- ✓Store tokens in the
.env, never in the code - ✓Use
Restart=alwaysto bring it back up if it goes down - ✓Look
journalctlwhen something goes wrong
✗ What NOT to do
- ✗Run with
python bot.pyin the terminal and close the session - ✗Commit the
.envin Git - ✗Forget the
enable(doesn’t come back up after a reboot)
🏆 Congratulations!
If you've made it this far, you have an AI assistant that lives in your Telegram, thinks with Claude or GPT, runs commands, and operates 24 hours a day on your server. This is the skeleton of any assistant. In the next module, you'll dive deeper into your Jarvis's brain and give it richer memory and reasoning.
📚 Module Summary
Next Module:
5.2 - Intelligence: giving your AI assistant memory and deeper reasoning