前言:
在NASTool里添加Telegram机器人发送影片姓名现自动搜索下载,以及通过菜单导航单控。
一、创建Telegram机器人
1-1、Telegram里面搜索 BotFather机器人
打开与它的聊天界面 机器人url: https://t.me/BotFather 打开与它的聊天界面,不论是 Windows mac 还是 Android iOS 的 telegram 客户端。
1-2、输入 /newbot 后回车 它会回你以下内容
Alright, a new bot. How are we going to call it? Please choose a name for your bot. |
这个名字是显示名称 (display name),不是唯一识别码,现在随便设置一下,之后可以通过
1-3、输入: /setname 修改 比如设置成 Zhang san's sweety bot 接着会让你设置唯一名称。字符串必须 endsWith bot,比如 abc_bot 或 HelloWorldbot 都是合法的。如果你设置的名字已经被占用需要重新设置。
比如你设置成了 test_bot
Good. Now let's choose a username for your bot. It must end in bot. Like this, for example: TetrisBot or tetris_bot. |
1-4、恭喜!设置成功。会返回给你重要的 API token,务必要保存好它。另外你的 bot 的唯一 url 就已经生成:https://t.me/test_bot
Done! Congratulations on your new bot. You will find it at t.me/test_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this. Use this token to access the HTTP API: 12345678:sdfsfadsfasdfasdfasdfgdfhdfghfgh Keep your token secure and store it safely, it can be used by anyone to control your bot. For a description of the Bot API, see this page: https://core.telegram.org/bots/api |
1-5、一些其他必要的命令
/setdescription 帮助你设置 bot 的描述
/setuserpic 设置 bot 的头像。 |
上传的图片 size 需要大于等于 150x150。而且上传图片需要选择压缩,不能上传文件! 此时你的 bot 很快就可以使用了。
二、获取 chatId
观察这个 URL https://api.telegram.org/bot{token}/getUpdates
使用第二步获得的 token 替换上述 url 中的 {token} 然后得到新的 url,复制粘贴到浏览器地址栏,回车请求。不出意外你会得到如下 response
{ "ok": true, "result": []
}
很好。这时搜索你的机器人,随便和它说一句话,比如给它发一句 "Hello World",然后重新请求一遍上述的 url(替换过 token 的),不出意外你收到的 response 是这样了
{ "ok": true, "result": [
{ "update_id": 123456, "message": { "message_id": 56, "from": { "id": 72384234234, "is_bot": false, "first_name": "sdfsdf", "last_name": "sdfsdf", "username": "sdfsdf", "language_code": "en"
}, "chat": { "id": 123456789, "first_name": "sdfsdf", "last_name": "sdfsdf", "username": "sdfsdf", "type": "private"
}, "date": 1212121212, "text": "/start", "entities": [
{ "offset": 0, "length": 6, "type": "bot_command"
}
]
}
},
{ "update_id": 123456, "message": { "message_id": 6, "from": { "id": 23232323, "is_bot": false, "first_name": "sdfsdfsdf", "last_name": "sdfsdfsdf", "username": "sdfsdfsdf", "language_code": "en"
}, "chat": { "id": 123456, "first_name": "sdfsdfsdf", "last_name": "sdfsfdsdf", "username": "sdfsdfsdf", "type": "private"
}, "date": 1234567, "text": "Hello World"
}
}
]
}
其中的 result[0].message.chat.id 的值就是 chatId 也就是 123456789 知道了 token 和 chatId 就可以使用 bot 了。
三、获取自己账号的chat.ID
我们只要打开 getidsbot 这个机器人的聊天窗口发送 随便发送一句话就会返回
第一项中的id就是自己的chat.ID
现在我们知道了自己和机器人的chat.ID 以及机器人的token to access the HTTP API
四、NASTool中添加消息通知
打开NASTool—设置—消息通知
1、添加机器人的 api密钥:12345678:sdfsfadsfasdfasdfasdfgdfhdfghfgh(比如这样的)
2、是我们获取到机器人的Chat ID:123456789 (比如这样的)
3、添加自己在 getidsbot 或获取的Chat ID
到这里,我们已经完成了99%了,就差最后一步(给机器人添加命令)
五、给机器人添加NASTool命令
我们回到 @BotFather 聊天窗口。发送 /mybots ,查询你创建过的机器人。选择我们刚刚建立的那个私聊机器人。
选择 Edit Bt 在选择 Edit Commands
再输入下面内容:
rss-RSS订阅
ptt-下载文件转移 ptr-删种 pts-站点签到 rst-目录同步 db-豆瓣想看 |
Comments NOTHING