Hey everyone, I’m running OpenBSD 7.6 on an amd64 system and I’m using ksh. I’ve been thinking about making a simple Telegram bot, but I don’t want to use any fancy libraries or complex programming languages.
I’m wondering if it’s possible to create a basic bot using just shell scripting. My idea is to use common tools like echo, cut, tr, awk, sed, and openssl, along with some clever piping.
The bot’s main job would be to take messages from one channel and forward them to a specific group. I’m planning to set it up so that the source channel, target group, and base URL are passed as command-line arguments.
Has anyone tried something like this before? Is it doable with just shell scripting, or am I better off using a more traditional approach? Any tips or suggestions would be great!
Creating a Telegram bot using shell scripting is certainly possible, though it comes with some challenges. I’ve experimented with this approach before, and while it’s not the most efficient method, it can be a great learning experience.
You’re on the right track with using tools like curl for API requests, jq for JSON parsing, and standard Unix utilities for text processing. However, be prepared for some limitations. Handling real-time updates can be tricky, and you might need to implement a polling mechanism.
One major consideration is error handling. Network issues or API changes can break your script, so robust error checking is crucial. Also, keep in mind that complex operations might strain your system resources more than a purpose-built bot framework would.
If you’re set on this approach, I’d suggest starting with a simple command-response bot before tackling message forwarding. It’ll help you get familiar with Telegram’s API quirks. Good luck with your project!
yo, i’ve dabbled with this kinda stuff before. it’s doable but can be a pain. curl’s ur best friend for api calls, and dont forget bout jq for parsing json responses. watch out for rate limits tho, telegram can be picky. also, security’s important - keep that token safe! it’s a cool project but might get messy for big channels. goodluck man!
I’ve actually implemented something similar using bash on a Debian system. It’s definitely doable, but there are a few gotchas to watch out for.
First, you’ll need to use curl to interact with the Telegram API. For parsing JSON responses, jq is invaluable - it’s much more reliable than trying to parse JSON with sed or awk.
One challenge I encountered was handling rate limiting. Telegram has strict limits on API calls, so you’ll need to implement some form of throttling or you’ll quickly get blocked.
For the forwarding logic, you can use the getUpdates method to poll for new messages, then use forwardMessage to send them to the target group. Be aware that this approach can be somewhat inefficient for high-volume channels.
Security is another concern - make sure you’re handling your bot token safely. Don’t hardcode it in your script.
Overall, it’s a fun project that’ll teach you a lot about both shell scripting and API interactions. Just be prepared for some trial and error!