Build a Telegram Turnstile Join Bot on Cloudflare Workers

Introduction

Previously, I showed muse bypassing Turnstile human verification. 

I have also seen many spam bots in other groups pass nmbot's Turnstile human verification and join groups all day long.

I thought I would test in my own group whether advertisers could solve Turnstile human verification.
* I do not use group-management bots deployed by other people in my own group.

Then I'll develop my own Telegram group-join verification bot  using  Turnstile for human verification 


Agent-Oriented Development

Hermes connected to  agentrouter's free deepseek-v4-flash model

The process was not a one-shot effort, so I documented some key development ideas.

Built on Cloudflare worker, without using KV.
It works well with the Cloudflare Free Plan and suits administrators of small Telegram groups who do not have their own VPS.
* If usage grows or you want to use it commercially, you can scale up your Cloudflare plan, or run it on your own VPS in a Wrangler environment.

A single system can manage multiple groups. Muting and unmuting are independent for each group.

Muting and unmuting are split between two workers.
If usage grows, you can deploy the workers under different Cloudflare accounts to "scale out".
You can also deploy them separately on two VPSs.
The muting worker's URL receives proactive calls from the Telegram server, so users will not know the URL.
The unmuting worker's URL, by contrast, is visited proactively by users and is publicly known. To prevent a flood attack from exhausting the worker's quota, enable Cloudflare's 5-second shield for this URL.
* In the current era of Agent applications, the additional files and deployment steps caused by multiple workers are not a problem. After all, an Agent follows the documentation to deploy them, rather than a person operating them manually.

Workflow:
1. A new member joins the group.
2. worker-a uses bot-admin to mute the new member and posts a group message containing a human-verification link. This link points to worker-b and carries the user ID (user_id) and group ID (chat_id).
3. The user visits worker-b through the human-verification link.
4. worker-b invokes Turnstile for human verification.
5. After the user passes human verification, worker-b uses the user ID (user_id) and group ID (chat_id) carried in the link to have bot-admin unmute the member.

Additional requirements:
The message in step 2 should be an Ephemeral Message (visible only to the designated user), so it does not interfere with other group members.
The human-verification flow in step 4 must also include a Telegram login step to confirm that the person completing the verification also controls the muted Telegram account. This prevents the human-verification link from being shared with "unwitting" strangers.

Exception handling:
There is a whitelist of groups the bot is allowed to manage. If worker-a receives a message pushed by the Telegram server and finds that the group's chat_id is not on the whitelist, the bot leaves the group.


Actual Results

When a new user joins the group, they receive a reminder message visible only to that user

Private reminder shown to a new group member by the anti-ad bot, requiring human verification before posting; link valid for 15 minutes

Opening the link in a browser takes the user through the 5-second shield, Turnstile human verification, and Telegram login, in that order

Browser showing Cloudflare 5-second security verification page with the message Performing security verification

Step 1 of human verification with an embedded Cloudflare Turnstile widget running and the target group name displayed

Step 2 of human verification asking the user to confirm their Telegram account, with a blue Log in with Telegram button and a notice to continue

Final human verification page with a green message under Step 2: Verification successful, please return to the group to post


Github

https://github.com/crazypeace/tg-join-group-exam-bot-worker-turnstile


I had an Agent write the deployment instructions

https://github.com/crazypeace/tg-join-group-exam-bot-worker-turnstile/blob/main/DEPLOY.md


Afterword

Originally, I was going to have Hermes integrate with stealth/space-bunny-alpha, the free model officially provided by Nous Portal.

But as I kept working on it, space-bunny-alpha seemed to have regressed in capability.

Ask it to analyze a problem, and it goes off on tangents. Ask it to develop a feature, and it says my design is flawed and does not follow my requirements.

My sense is that the reasoning stage is exerting too much influence over the final result.

Switching to the free deepseek-v4-flash model from agentrouter solved it.


Comments