如何在Java中获取Telegram Bot用户名?

发布于 2025-02-04 11:53:36 字数 69 浏览 3 评论 0原文

我知道如何获取向机器人发送更新或消息的用户的用户名,但是如何在不诉诸Botfather的情况下获取机器人的用户名和/或名称?

I know how to get the username of a user that send an update or message to my bot but how can I get the username and/or name of my bot without resorting to BotFather?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情独悲 2025-02-11 11:53:36

我如何获得bot的用户名和/或名称

telegram bot api 提供a <代码> getme 方法:

一种用于测试机器人身份验证令牌的简单方法。不需要参数。 以a



因此,如果您发送请求之类的请求:

api.telegram.org/bot<MY-BOT-TOKEN>/getMe

您将获得以下答复:

{
    "ok": true,
    "result": {
        "id": 12346798,
        "is_bot": true,
        "first_name": "my_test_bot",
        "username": "my_test_bot",
        "can_join_groups": true,
        "can_read_all_group_messages": false,
        "supports_inline_queries": false
    }
}

How can I get the username and/or name of my bot

The Telegram Bot API provides a getMe method that:

A simple method for testing your bot's authentication token. Requires no parameters. Returns basic information about the bot in form of a User object.


So, if you'd send a request like:

api.telegram.org/bot<MY-BOT-TOKEN>/getMe

You'll get the following response:

{
    "ok": true,
    "result": {
        "id": 12346798,
        "is_bot": true,
        "first_name": "my_test_bot",
        "username": "my_test_bot",
        "can_join_groups": true,
        "can_read_all_group_messages": false,
        "supports_inline_queries": false
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文