jarvis
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v31View latest version
This Telegram bot uses OpenAI's GPT-4o-mini model via the AI SDK to provide intelligent responses to user messages.
- Responds to text messages using OpenAI's GPT-4o-mini
- Shows typing indicator while generating responses
- Handles errors gracefully
- Concise and friendly AI responses optimized for chat
-
TELEGRAM_TOKEN: Your Telegram bot token
- Get this from @BotFather on Telegram
- Create a new bot with
/newbotcommand - Copy the token provided
-
OPENAI_API_KEY: Your OpenAI API key
- Get this from OpenAI Platform
- Create a new API key
- Make sure you have credits in your OpenAI account
/start- Welcome message and bot introduction- Any text message - Gets an AI-generated response
The bot's personality and behavior can be customized by editing the system-prompt.md file. This markdown file contains:
- The main system prompt that defines the AI's role and behavior
- Guidelines for response style and tone
- Instructions for handling specific scenarios
Simply edit the markdown file and redeploy to update the bot's behavior. The system includes a fallback prompt in case the file cannot be loaded.
- Uses Grammy framework for Telegram bot functionality
- Integrates AI SDK with OpenAI provider
- Configured to use GPT-4o-mini model (cost-effective and fast)
- Maximum response length: 500 tokens
- System prompt loaded from
system-prompt.mdfile for easy customization
- Validates required environment variables on startup
- Handles API errors gracefully with user-friendly messages
- Logs errors for debugging
- Only responds to text messages (ignores media, stickers, etc.)
- Set up the required environment variables in Val Town
- Customize the system prompt by editing
system-prompt.md - Deploy the val as an HTTP endpoint
- Start chatting with your bot on Telegram!
The bot will automatically set up the webhook when it receives its first request.
