Telegram Chat ID vs Peer ID: Telethon Guide

Refer to the Telethon official documentation  https://docs.telethon.dev/en/stable/concepts/chats-vs-channels.html ID is something like this 4011678806 2079829990 6702958858 If you use Forkgram on the desktop, you can see these IDs directly on the interface   While Peer ID is like this: 460693903 -4016131921 -1002079829990 Numbers without a sign mean this is a user, a bot is a type of user. If the number has a minus sign in front, it is a private group. If the number has -100 in front, it is a channel, or a public group.  When you use the web version of Telegram, you can find such IDs in the browser's address bar When using the Telethon framework, chat_id is the Peer ID. For example, @client.on(events.MessageEdited) @client.on(events.NewMessage()) async def on_greeting(event):       real_id, peer_type = resolve_id(event.chat_id) # Convert to the official real id   print(f"event.chat_id {event.chat_id}")   print(f"real_id {real_id}") The command line prints someth...

在 Telethon 中 ID 和 Peer ID

参考 Telethon 官方文档  https://docs.telethon.dev/en/stable/concepts/chats-vs-channels.html ID是像这样的 4011678806 2079829990 6702958858 你如果在桌面端 使用 Forkgram, 那么你可以直接在界面上看到这些ID   而 Peer ID 是像这样的: 460693903 -4016131921 -1002079829990 只有数字的意思是, 这是一个用户user, 机器人bot是用户的一种. 如果数字前面有一个减号, 这是一个私有群组private group 如果数字前面有一个减100, 这是一个频道channel, 或者是一个公开群组public group.  在你使用网页web版的telegram时, 你可以在浏览器的地址栏发现这样的ID 在使用 Telethon 框架中, chat_id 是 Peer ID. 如, @client.on(events.MessageEdited) @client.on(events.NewMessage()) async def on_greeting(event):       real_id, peer_type = resolve_id(event.chat_id) # 转换为官方真实id   print(f"event.chat_id {event.chat_id}")   print(f"real_id {real_id}") 命令行打印的是类似这样: event.chat_id -1001730207212 real_id 1730207212 event.chat_id -4016131921 real_id 4016131921 注意, resolve_id 是 telethon 官方函数. 对应的反向转换函数是 get_peer_id 要这样引入一下 from telethon.utils import resolve_id, get_peer_id peer_type 可能为 PeerUser, PeerChat, PeerChannel 需要这样引入一下 f...

How to Build a One-Time QR Code with URL Redirect

Requirement https://t.me/blacktechsharing/183161 Approach A QR code is essentially a string of characters embedded in an image. This string can be a URL. Since the QR code image has already been sent to others, and you can't go to their computer or phone to delete the image, how is a "one-time QR code" implemented? If the QR code image stays the same, then the URL A corresponding to the QR code stays the same. When you visit URL A, you're accessing a server. This server can make everyone who visits URL A redirect to a new URL B. We define URL B as the URL that actually carries the real meaning. We let the server allow only the first visitor to URL A to be redirected to URL B; subsequent visits to URL A will have the redirection disabled. This is how a "one-time QR code" is implemented.

白嫖worker 自建短链服务 Url-Shorten-Worker 支持阅后即焚snapchat mode 配合二维码生成工具 制作一次性二维码

需求 https://t.me/blacktechsharing/183161 思路 二维码实际上就是以一种图片的方式写的一串字符. 这串字符可以是一个网址. 既然这个二维码图片已经发给别人了, 你不可以跑到别人的电脑或者手机里面去删掉图片, 那么"一次性二维码"是怎么实现的呢? 二维码图片不变, 那么二维码对应的网址A不变. 你访问网址A就是访问一个服务器. 这个服务器可以让来访问网址A的人都跳转到一个新的网址B. 我们定义网址B才是真正有实际意义的网址. 让服务器只允许第一次访问网址A的人跳转到网址B, 以后再来访问网址A, 跳转都失效. 这样就实现了 "一次性二维码".

URL Shortener on Cloudflare Workers with Visit Count

Thanks to https://github.com/EasyChris/Url-Shorten-Worker for implementing the basic counting functionality. Building on this, I further optimized the operation page so that you can read the visit count directly on the operation page, without needing to check the visit count in the KV backend. Demo

白嫖worker 自建短链服务 Url-Shorten-Worker 支持访问计数 visit count 支持查询短链 API接口增删查齐全 可以作为独立短链API服务

感谢 https://github.com/EasyChris/Url-Shorten-Worker 实现基本的计数功能. 我在此基础上, 继续优化了操作页面, 可以在操作页面读出访问计数, 不需要到KV后台去看访问计数了. 效果

Fix Url-Shorten-Worker API Error: CORS Solution

Question  Wanted to debug Url-Shorten-Worker, saved index.html on local computer, called the server API at https://1way.eu.org/, got an error Access to fetch at 'https://1way.eu.org/bodongshouqulveweifengci' from origin 'null' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

调试 Url-Shorten-Worker API报错 from origin 'null' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

问题  想调试 Url-Shorten-Worker, 把 index.html 保存在本地电脑上, 调用服务器https://1way.eu.org/的API, 报错 Access to fetch at 'https://1way.eu.org/bodongshouqulveweifengci' from origin 'null' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.