[title-plane title=”前言”]telegram目前有两种api,
一种是bot api, bot api是基于http访问
第二种是基于mtproto访问,访问需要加密,相对要复杂一些。 后者也可以实现传送讯息等功能
这里我只说第一种bot api[/title-plane]
首先建立一个bot
tg内搜索botfather,开启与之聊天框,然后输入
/newbot
机器人会反馈
Alright, a new bot. How are we going to call it? Please choose a name for your bot.
然后输入你想建立的机器人昵称
回车后你就要输入你需要建立的机器人名字,例如
example_bot
[c-alert type=”warning”]机器人名称必须以_bot结尾
如果名称已被注册会提示Sorry, this username is already taken. Please try something different.
[/c-alert]
成功后机器人会反馈类似如下信息
BotFather, [16.02.17 14:23] Done! Congratulations on your new bot. You will find it at t.me/Gz_David_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: xxx:xxx For a description of the Bot API, see this page: https://core.telegram.org/bots/api
上述信息里API:后边标红的信息就是你的token,我这里只是示例
输入/token
可以重新生成一个token,/revoke
可以撤销一个token
获取UserID
TG内搜索userinfobot
开启聊天后回复/start
机器人的ID就是你需要的ID号码
使用bot
TG内搜索你建立的机器人名称example_bot
开始对话
再需要推送信息的地方填入API以及ID号,在这个机器人就能收到推送了
学习了。