Code Snippets on the Go
Ideas don't wait for you to be at your desk. With Moltbot, you can write code, debug logic, create GitHub issues, and even push code — all from a Telegram message on your phone.
You: Write a Python function that takes a list of URLs,
makes concurrent requests to all of them, and returns
the one with the fastest response time. Use aiohttp
with timeout handling.Moltbot returns a complete, working function with type hints, error handling, and docstrings — formatted in a code block you can copy directly.
Prerequisites
- Moltbot running and connected to Telegram
- GitHub MCP tool (optional) — For creating issues, PRs, and interacting with repositories directly from chat
- File system or shell MCP tool (optional) — For writing code to files on your server
- Memory system (optional) — For saving snippets and recalling past code discussions
Setup
Step 1: Basic Code Generation
No special setup is needed for basic code generation. Moltbot's underlying LLM is capable of writing code in any mainstream language out of the box. Just ask:
You: Write a Go function that validates email addresses
using regex. Include test cases.You: Give me a bash one-liner that finds all files larger
than 100MB in the current directory, sorted by size.You: Write a SQL query that finds users who signed up
in the last 30 days but haven't made a purchase.
Include indexes that would speed this up.Step 2: Enable GitHub Integration
With the GitHub MCP tool, you can manage your repos from Telegram:
Create issues:
You: Create an issue on steipete/moltbot titled
"Add Matrix protocol support" with a technical proposal outlineReview pull requests:
You: Show me the open PRs on steipete/moltbot.
Summarize what each one does.Check CI status:
You: What's the status of the latest CI run on steipete/moltbot main branch?Read code from repos:
You: Show me the contents of src/config.ts in steipete/moltbotStep 3: Save Snippets to Memory
If you want to recall code you've generated later, enable memory and ask Moltbot to save it:
You: Save that aiohttp function to memory under "python-snippets".
I might need it for the API project.Later:
You: Find the Python concurrent request function I saved last week.Step 4: Write Code to Files (Optional)
If Moltbot has file system access on your server, you can go beyond chat and write code directly:
You: Write that function to ~/projects/api-tools/concurrent_fetch.py
with a proper module docstring and __main__ block for testing.Common Workflows
Debug a tricky error:
You: I'm getting "RuntimeError: Event loop is closed" in Python
when using aiohttp with asyncio.run(). The code works on
Linux but fails on Windows. What's going on and how do I fix it?Moltbot will explain the platform difference (Windows uses ProactorEventLoop) and provide a cross-platform solution.
Generate boilerplate:
You: Generate a FastAPI app skeleton with:
- Health check endpoint
- CORS middleware
- Structured logging with structlog
- Docker-ready (include Dockerfile and docker-compose.yml)Review your own code:
You: Review this function for bugs and performance issues:
def process_items(items):
result = []
for item in items:
if item not in result:
result.append(item)
return resultMoltbot will identify the O(n^2) complexity and suggest using a set or dict.fromkeys().
Explain unfamiliar code:
You: Explain what this Rust code does, line by line:
fn main() {
let v: Vec<i32> = (0..10).filter(|x| x % 2 == 0).collect();
println!("{:?}", v);
}Create a technical proposal:
You: Create an issue on my-org/backend titled "Migrate from REST to gRPC"
with sections: Motivation, Proposed Changes, Migration Plan, and Risks.
Base the technical details on our current Express.js setup.Edge Cases and Troubleshooting
- Code formatting in Telegram: Telegram supports markdown code blocks, so Moltbot's code output is generally well-formatted. For very long snippets (500+ lines), the message may be split across multiple messages or truncated. Consider asking for the code to be written to a file instead.
- Language detection: If you don't specify a language, Moltbot infers from context. Be explicit when the language matters: "Write this in TypeScript, not JavaScript."
- Outdated APIs: The LLM's training data has a cutoff date. For very recent libraries or APIs, double-check the output against current documentation. You can help by specifying versions: "Use Python 3.12 and aiohttp 3.9."
- Complex multi-file projects: Moltbot works best for individual files, functions, or small modules. For full project scaffolding across many files, consider using it to generate a plan first, then implement file by file.
- GitHub permissions: Ensure your GitHub personal access token has the correct scopes. Creating issues requires
repoorpublic_reposcope. Creating PRs on repos you don't own requires fork access.
Pro Tips
- Iterate rapidly. Ask for a function, then refine: "Make it async." "Add retry logic." "Handle the case where all URLs timeout." Each message builds on the previous context within the conversation.
- Use memory for project context. Tell Moltbot about your project once: "My backend is Python 3.11, FastAPI, PostgreSQL, deployed on Kubernetes." Memory retains this, so future code requests automatically align with your stack.
- Generate tests alongside code. Always ask for tests: "Write the function AND pytest tests covering edge cases." This is especially useful for mobile coding where you cannot run the code immediately.
- Create issues as a thinking tool. Even if you are the only contributor, creating a well-structured GitHub issue from your phone helps you think through a feature before sitting down to implement it.
- Pair with the Weekly Report. If you create issues or log coding work through Moltbot, it is already in memory. The Weekly Report recipe can pull this activity into your end-of-week summary automatically.
Related Pages
- Memory System — Save and recall code snippets and project context
- MCP Tools — Setting up GitHub and file system tools
- GitHub Repo Monitoring — Monitor repos for activity
- Weekly Report — Include coding activity in weekly summaries
- Creative Use Cases — More automation ideas