0

I'm creating a Telegram Bot using Telebot.

bot.get_me()

get_me() is the same as getme() in Telegram Bot Api. I need to get the bot's first name.

Code above gives me:

{
   "id":5519834543,
   "is_bot":true,
   "first_name":"BOTtle",
   "username":"SomethingnotsurewhatBot",
   "last_name":"None",
   "language_code":"None",
   "can_join_groups":true,
   "can_read_all_group_messages":false,
   "supports_inline_queries":false
}

In Telegram Bot Api's documentation it says that getme() returns a JSON object: https://core.telegram.org/bots/api#available-types

How do I ask it to return only first_name or username?

0stone0
  • 34,288
  • 4
  • 39
  • 64
Daria
  • 5
  • 3

1 Answers1

0

Apparently you can use regex

import re
import telebot


bot=telebot.TeleBot(token="ur token")
resp=str(bot.get_me())
match=re.findall("'first_name': '(.*)', 'user",resp)
print(match[0])

Here I m using telebot so regex may differ a bit as per your json response it should be like this

match=re.findall(r'"first_name":"(.*)"',resp)
You can refer to this regex cheatsheat for detailed regex info here
SKB
  • 17
  • 7