telegram里面用户是可以无限上传文件的,但是我们在国内无法直接访问telegram,所以有大佬开发了个项目,可以通过机器人获取telegram里的文件直链,只需要一台vps即可
原项目地址:点我直达
环境要求:
python3
首先我们通过git拉取项目:
|
|
进入项目地址
|
|
如果这一步报错“Command 'virtualenv' not found, but can be installed with
”,说明没有安装virtualenv,执行:
|
|
安装好virtualenv后,再执行:
|
|
然后我们telegram里面搜索botfather并添加机器人:
向bot发送/newbot
指令来新建一个bot,以下带#号为bot回复的语句
|
|
输入用户名后,botfather会回复给你一串机器人密钥,我们要保存好,图中圈出来的部分就是密钥
接下来我们新建一个频道,公开频道或者私人频道都可以
搜索添加@getidsbot
再将bot添加到频道中,它会回复一个负数给你,那个就是你频道的id,id格式为-100xxxxxxxxxx
我们再到浏览器打开https://my.telegram.org/
,登录我们的telegram账号,注册获取一个app id
和app hash
,这一步就不详细写了,按流程走就行了
现在我们拥有一个机器人密钥,一个app id和一个app hash和一个频道id
然后在项目目录下新建一个名为.env的文件,注意不要忘记前面那个.
按照以下格式编辑.env文件,注意#号后面的内容不要输入到文件中:
|
|
编辑好后,保存,我们再在ssh内执行
|
|
现在我们只要把tg内的文件转发给我们新建的机器人,或者上传文件给机器人,机器人就会返回一条文件直链供我们下载,下载文件会经过我们的vps中转,如图