Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor upload function and improve file handling #183

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cf-pages
Copy link
Owner

@cf-pages cf-pages commented Sep 8, 2024

Solve issue: #178 #180 #182

Use tg channel/chat for storage

How to use?

First, you need to create a new telegram bot to obtain the token and a telegram channel to obtain Chat_ID

How to Obtain Bot_Token and Chat_ID for Telegram

If you don't have a Telegram account yet, please create one first. Then, follow these steps to get the Bot_Token and Chat_ID:

  1. Get the Bot_Token

    • In Telegram, send the command /newbot to @BotFather, and follow the prompts to input your bot's name and username. Once successfully created, you will receive a Bot_Token, which is used to interact with the Telegram API.
  2. Set the bot as a channel administrator

    • Create a new channel and, after entering the channel, go to channel settings. Add the bot you just created as a channel administrator, so it can send messages.
  3. Get the Chat_ID

    • Use @GetTheirIDBot to get your channel ID. Send a message to this bot and follow the instructions to receive your Chat_ID (the ID of your channel).

Important

由于原有的Telegraph API接口被官方关闭,需要将上传渠道切换至Telegram Channel,请按照文档中的部署要求设置TG_Bot_TokenTG_Chat_ID,否则将无法正常使用上传功能。

如何获取Telegram的Bot_TokenChat_ID

如果您还没有Telegram账户,请先创建一个。接着,按照以下步骤操作以获取BOT_TOKENCHAT_ID

  1. 获取Bot_Token
    • 在Telegram中,向@BotFather发送命令/newbot,根据提示依次输入您的机器人名称和用户名。成功创建机器人后,您将会收到一个BOT_TOKEN,用于与Telegram API进行交互。

202409071744569

  1. 设置机器人为频道管理员
    • 创建一个新的频道(Channel),进入该频道后,选择频道设置。将刚刚创建的机器人添加为频道管理员,这样机器人才能发送消息。

202409071758534

202409071758796

  1. 获取Chat_ID

    • 通过@VersaToolsBot获取您的频道ID。向该机器人发送消息,按照指示操作,最后您将得到CHAT_ID(即频道的ID)。
    • 或者通过@GetTheirIDBot获取您的频道ID。向该机器人发送消息,按照指示操作,最后您将得到CHAT_ID(即频道的ID)。

    202409071751619

最后去Cloudflare Pages后台设置相关的环境变量(注:修改环境变量后,需要重新部署才能生效)

环境变量 示例值 说明
TG_Bot_Token 123468:AAxxxGKrn5 @BotFather获取的Telegram Bot Token。
TG_Chat_ID -1234567 频道的ID,确保TG Bot是该频道或群组的管理员。

本地运行命令,需先按照Cloudflare官方文档安装wrangler

npx wrangler pages dev ./ --kv "img_url" --port 8080 --binding BASIC_USER=admin --binding BASIC_PASS=123 --binding TG_Chat_ID=[Your Chat ID] --binding TG_Bot_Token=[Your Telegram Bot token] --persist-to ./data

Reference:
@x-dr/telegraph-Image
@MarSeventh/CloudFlare-ImgBed

Copy link

cloudflare-workers-and-pages bot commented Sep 8, 2024

Deploying tpic with  Cloudflare Pages  Cloudflare Pages

Latest commit: b12b5c1
Status: ✅  Deploy successful!
Preview URL: https://0b60900a.tpic.pages.dev
Branch Preview URL: https://feature-telegram-bot-api.tpic.pages.dev

View logs

@huaji1hao
Copy link

I tried, it workds. Thank u a lot!!!

@8bytes-code
Copy link

8bytes-code commented Sep 9, 2024

ok,拉取这个分支重新部署能用了!感谢作者!

@huaji1hao
Copy link

huaji1hao commented Sep 9, 2024 via email

@yasirarism
Copy link

Still buggy for upload video, it will changed to images mimetype

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants