Telegram 创建机器人并发消息
步骤
跟 Telegram 的 botfather 机器人进行会话,可以在浏览器或者 Telegram 会话中打开这个链接。
根据提示,/newbot 创建机器人,得到 token。
跟机器人发下消息,然后访问 https://api.telegram.org/bot{{token}}/getUpdates 链接({{token}} 改为你的 token),得到 chat_id。
发送文本消息,可以请求这个链接({{token}} 和 {{chat_id}} 改为实际的) https://api.telegram.org/bot{{token}}/sendMessage?chat_id={{chat_id}}&text=Hello World
也可以用第三方库进行调用 github.com/php-telegram-bot/core
🌰:发送图片带说明和按钮的步骤
按钮
{
"inline_keyboard":[
[
{
"text":"测试按钮",
"switch_inline_query":"share",
"url":"https://example.com"
}
]
]
}
请求
https://api.telegram.org/bot{{token}}/sendPhoto?chat_id={{chat_id}}&photo={{photo_url}}&caption=测试按钮&reply_markup={"inline_keyboard":[[{"text":"测试按钮
","switch_inline_query":"share","url":"https://example.com"}]]}
附录:设置 token
请求(example.com/example 改为你的)
https://api.telegram.org/bot{{token}}/setWebhook?url=https://example.com/example
参见
本作品采用《CC 协议》,转载必须注明作者和本文链接
投身灰色事业了?