Creating a form submission handler that forwards data to Telegram chat via bot API

I’m helping my buddy set up his website. He built it using HTML with some JavaScript and jQuery. What he wants is pretty simple - when visitors submit his contact form, he wants all that info automatically sent to his Telegram group.

I know how to grab the chat ID but I’m totally new to working with Telegram bots. I’ve been trying to test this by making POST calls using curl to hit the sendMessage endpoint, but something’s not working right.

When I run my curl command, I don’t see any response back. I read somewhere that the output goes to stdout but I’m not sure what that means exactly.

Two things I need help with:

  1. How do I get curl to actually show me what the API returns?
  2. What’s the correct way to structure the request for sending messages?

I found this example format:

curl -X POST \
https://api.telegram.org/bot<MY_TOKEN>/sendMessage \
-d "text=Hello from my website bot" \
-d "chat_id=12345"

I plugged in my real bot token and chat ID but nothing happens when I run it in terminal.

When working with Telegram’s Bot API, I encountered a similar issue at first. It sounds like your curl command is properly formatted, but you might not be seeing the response because of how the terminal is handling the output. Use the -v flag for verbose mode, or -i to include the response headers in your output:

curl -X POST -i \
https://api.telegram.org/bot<YOUR_TOKEN>/sendMessage \
-d "text=Hello from my website bot" \
-d "chat_id=12345"

Additionally, make sure your bot token is correct, and confirm that the bot has been allowed to message the group.

Had this exact issue when I set up automated notifications. Your bot probably doesn’t have permission to post in that chat. Add the bot to your Telegram group first and give it admin rights (or at least posting permissions). For debugging, add -s and -S flags to your curl command - kills the progress bars and shows actual errors. Your command looks fine, but test it with a DM to yourself first. Use your personal chat ID instead of the group ID. Get your chat ID by messaging the bot directly and checking what comes back. Once DMs work, then fix the group permissions. Also make sure there’s no extra spaces or weird characters in your bot token when you paste it into the URL.

first, check if ur bot token’s still active - hit up @BotFather on telegram and make sure the bot wasn’t disabled. try switching to --data-urlencode instead of -d for the text param in case there’s encoding problems. sometimes the API responds but curl doesn’t display it right without verbose flags.