基于shell命令TG机器人信息,在GitHub上有1K多的代码片段,因此可供参考的案例很多很多。可以非常方便的推送信息给用户,有些自动部署、气象预报、自助授权等等,都是基于此完成。为此特别汇总了一些关于TG机器人的shell命令。
1.推送文本信息
TOKEN=XXXX:XXXXXXXXXXXXXX #TG机器人token
chat_ID=XXXXX #用户ID或频道、群ID
message_text="xxxxx" #要发送的信息
MODE='HTML' #解析模式,可选HTML或Markdown
URL="https://api.telegram.org/bot${TOKEN}/sendMessage" #api接口
测试1:终端有日志
curl -s -X POST $URL -d chat_id=${chat_ID} -d parse_mode=${MODE} -d text="${message_text}"
测试2:终端无日志
curl -s -o /dev/null -X POST $URL -d chat_id=${chat_ID} -d text="${message_text}"
2.推送贴图
curl -s -X POST https://api.telegram.org/bot$BOT_API_KEY/sendSticker -d sticker="CAADAgAD3QADMNSdEY1VJRWnGm6vFgQ" -d chat_id=$CHAT_ID
效果截图:
3.推送任意文件
curl -F chat_id=$chat_ID -F document=@"v2.sh" https://api.telegram.org/bot$TOKEN/sendDocument
4.推送照片
curl -s -X POST "https://api.telegram.org/bot${TOKEN}/sendPhoto" -F chat_id=$chat_ID -F photo="@baiyue.jpg"
5.其他推送
/sendVideo
/sendVoice
/sendLocation
/sendVenue
/sendChatAction
----
6.其他API
请参考:https://core.telegram.org/bots