如今越来越多的网站使用Telegram Bot签到,telegram-cli 是一个Telegram的非官方客户端,可以实现在终端中访问Telegram,本文使用telegram-cli+crontab完成了自动签到 #### 在 CentOS 下安装 telegram-cli
快速编译安装
cd ~/ git clone --recursive https://github.com/vysheng/tg.git && cd tg yum install jansson-devel lua-devel readline-devel libconfig-devel libevent-devel ./configure make |
将编译生成的bin/telegram-cli
和tg-server.pub
移动到同一目录下,这里创建一个mytg
目录 > 不必在 https://my.telegram.org/apps 上获取publickey,除非此项目自带的key已经过时
mkdir mytg |
在mytg
中创建telegram.config
配置文件,并放入以下内容
vim telegram.config |
default_profile = "mytg"; |
运行telegram-cli
./telegram-cli -k tg-server.pub -c telegram.config |
这里使用一个脚本文件来快速发送消息,新建~/tg/mytg/telegram_standalone.sh
vim ~/tg/mytg/telegram_standalone.sh |
|
修改脚本权限
chmod +x ~/tg/mytg/telegram_standalone.sh |
如果使用国外VPS执行crontab定期任务,务必修改时区并重启crontab服务
修改为北京时区
ntpdate -u cn.pool.ntp.org |
重启crontab服务
service crond restart |
将vim设为默认文本编辑器
export VISUAL=vim |
或
export EDITOR=vim |
新建crontab任务,运行
crontab -e |
将打开vim,进入Insert编辑模式,放入以下内容
* 10 * * * /root/tg/mytg/telegram_standalone.sh username 签到 |
其中,username
可修改为Telegram中任意Bot的id,签到
为向该Bot发送的签到指令,可任意修改,以上脚本每天上午10点会自动执行。
运行crontab -l
可查看目前创建的crontab任务。
假如你的账号添加了太多Telegram群组,telegram-cli可能无法接收/发送所有消息,可以使用dialog_list
来加载会话列表或使用-w
参数启动telegram-cli,使程序启动后会话列表先加载再发出信息。
关于telegram-cli更多的启动参数详见 https://github.com/vysheng/tg/wiki/Telegram-CLI-Arguments
msg <peer> Text - sends message to this peer
fwd <user> <msg-seqno> - forward message to user. You can see message numbers starting client with -N
chat_with_peer <peer> starts one on one chat session with this peer. /exit or /quit to end this mode.
add_contact <phone-number> <first-name> <last-name> - tries to add contact to contact-list by phone
rename_contact <user> <first-name> <last-name> - tries to rename contact. If you have another device it will be a fight
mark_read <peer> - mark read all received messages with peer
delete_msg <msg-seqno> - deletes message (not completly, though)
restore_msg <msg-seqno> - restores delete message. Impossible for secret chats. Only possible short time (one hour, I think) after deletion
send_photo <peer> <photo-file-name> - sends photo to peer
send_video <peer> <video-file-name> - sends video to peer
send_text <peer> <text-file-name> - sends text file as plain messages
load_photo/load_video/load_video_thumb/load_audio/load_document/load_document_thumb <msg-seqno> - loads photo/video/audio/document to download dir
view_photo/view_video/view_video_thumb/view_audio/view_document/view_document_thumb <msg-seqno> - loads photo/video to download dir and starts system default viewer
fwd_media <msg-seqno> send media in your message. Use this to prevent sharing info about author of media (though, it is possible to determine user_id from media itself, it is not possible get access_hash of this user)
set_profile_photo <photo-file-name> - sets userpic. Photo should be square, or server will cut biggest central square part
chat_info <chat> - prints info about chat
chat_add_user <chat> <user> - add user to chat
chat_del_user <chat> <user> - remove user from chat
rename_chat <chat> <new-name>
create_group_chat <chat topic> <user1> <user2> <user3> ... - creates a groupchat with users, use chat_add_user to add more users
chat_set_photo <chat> <photo-file-name> - sets group chat photo. Same limits as for profile photos.
search <peer> pattern - searches pattern in messages with peer
global_search pattern - searches pattern in all messages
create_secret_chat <user> - creates secret chat with this user
visualize_key <secret_chat> - prints visualization of encryption key. You should compare it to your partner's one
set_ttl <secret_chat> <ttl> - sets ttl to secret chat. Though client does ignore it, client on other end can make use of it
accept_secret_chat <secret_chat> - manually accept secret chat (only useful when starting with -E key)
user_info <user> - prints info about user
history <peer> [limit] - prints history (and marks it as read). Default limit = 40
dialog_list - prints info about your dialogs
contact_list - prints info about users in your contact list
suggested_contacts - print info about contacts, you have max common friends
stats - just for debugging
show_license - prints contents of GPLv2
help - prints this help
get_self - get our user info
export_card - print your 'card' that anyone can later use to import your contact
import_card <card> - gets user by card. You can write messages to him after that.
quit - quit
safe_quit - wait for all queries to end then quit
来自于23.227.193.227美国伊利诺斯芝加哥网友评分!
来自于42.119.148.32越南胡志明市网友评分!
来自于85.237.206.197英国英格兰伦敦网友评分!
来自于60.246.51.76澳门特别行政区网友评分!
来自于43.249.50.166印度网友评分!
来自于106.113.13.179河北省石家庄市 电信网友评分!
来自于101.94.224.43上海市上海市 电信网友评分!
来自于124.126.3.110北京市北京市 电信网友评分!
来自于106.87.116.73重庆市重庆市 电信网友评分!
来自于49.157.47.254菲律宾网友评分!
来自于183.200.16.191山西省太原市 移动网友评分!
来自于111.58.68.171广西壮族自治区贵港市 移动网友评分!
来自于94.66.59.128希腊网友评分!
来自于94.66.59.128希腊网友评分!
来自于103.151.173.102亚太地区网友评分!
来自于39.109.191.32新加坡网友评分!
来自于106.87.116.73重庆市重庆市 电信网友评分!
来自于106.87.116.73重庆市重庆市 电信网友评分!
来自于153.3.60.41江苏省南京市 联通网友评分!
来自于3.112.41.223日本东京网友评分!
来自于104.251.178.50美国德克萨斯达拉斯网友评分!
来自于104.251.178.50美国德克萨斯达拉斯网友评分!
来自于111.55.11.245中国 移动网友评分!
来自于103.205.179.169巴基斯坦网友评分!
来自于183.200.16.191山西省太原市 移动网友评分!
来自于183.200.16.191山西省太原市 移动网友评分!
来自于176.97.73.32英国网友评分!
来自于46.232.121.89俄罗斯莫斯科网友评分!
来自于114.45.39.108台湾省台北市网友评分!
来自于164.155.132.208南非网友评分!