像 t.me/username 一样发送内联键盘,但对于电报中的用户 ID php
send inline keyboard like t.me/username but for userid in telegram php
我想发送一个内联键盘,让用户进入某人与他 chat_id
的聊天。我知道我可以为内联键盘设置 Url,例如:t.me/username
但类似的东西不适用于
chat_id : t.me/123456
怎么做?
只需在 InlineKeyboardButton
的 url
开头使用 https://
前缀。
因此 sendMessage 方法的 reply_markup
参数应如下所示:
"reply_markup": {"inline_keyboard": [[{"text": "button text...", "url": "https://t.me/<chat_id or name of another user>"}]]}
.
完整示例 curl
:
curl -v -H "Content-Type: application/json" -d '{"chat_id": 123456, "text": "here is your chat with <USERNAME>", "reply_markup": {"inline_keyboard": [[{"text": "here is your link to another user", "url": "https://t.me/<USERNAME>"}]]}}' https://api.telegram.org/bot<BOT_ID>:<BOT_TOKEN>/sendMessage
此行向 id
= 123456 的用户发送 Message
。Message
包含带有一个 InlineKeyboardButton
的内联键盘。此按钮有一个 link,用于与 ID 为 <USERNAME>
且相应页面为 URL https://t.me/<USERNAME>
的另一个用户聊天。
更新
很遗憾,如果您要查找的用户没有用户名,您将无法创建 t.me
link,因此您无法联系到他:
You can write to people who are in your phone contacts and have Telegram. Another way of contacting people is to type their Telegam username into the search field.
...
You can set up a public username on Telegram. It then becomes possible for other users to find you by that username — you will appear in contacts search under ‘global results’. Please note that people who find you will be able to send you messages, even if they don't know your number. If you are not comfortable with this, we advise against setting up a username in Telegram.
看来这里唯一的解决办法是确保每个需要的联系人都有用户名。
我想发送一个内联键盘,让用户进入某人与他 chat_id
的聊天。我知道我可以为内联键盘设置 Url,例如:t.me/username
但类似的东西不适用于
chat_id : t.me/123456
怎么做?
只需在 InlineKeyboardButton
的 url
开头使用 https://
前缀。
因此 sendMessage 方法的 reply_markup
参数应如下所示:
"reply_markup": {"inline_keyboard": [[{"text": "button text...", "url": "https://t.me/<chat_id or name of another user>"}]]}
.
完整示例 curl
:
curl -v -H "Content-Type: application/json" -d '{"chat_id": 123456, "text": "here is your chat with <USERNAME>", "reply_markup": {"inline_keyboard": [[{"text": "here is your link to another user", "url": "https://t.me/<USERNAME>"}]]}}' https://api.telegram.org/bot<BOT_ID>:<BOT_TOKEN>/sendMessage
此行向 id
= 123456 的用户发送 Message
。Message
包含带有一个 InlineKeyboardButton
的内联键盘。此按钮有一个 link,用于与 ID 为 <USERNAME>
且相应页面为 URL https://t.me/<USERNAME>
的另一个用户聊天。
更新
很遗憾,如果您要查找的用户没有用户名,您将无法创建 t.me
link,因此您无法联系到他:
You can write to people who are in your phone contacts and have Telegram. Another way of contacting people is to type their Telegam username into the search field.
...
You can set up a public username on Telegram. It then becomes possible for other users to find you by that username — you will appear in contacts search under ‘global results’. Please note that people who find you will be able to send you messages, even if they don't know your number. If you are not comfortable with this, we advise against setting up a username in Telegram.
看来这里唯一的解决办法是确保每个需要的联系人都有用户名。