Answer the question
In order to leave comments, you need to log in
How to get an avatar by id via vkapi and send it to a telegram bot?
I'm making a bot. It is necessary that the avatar be sent by the id of the VKontakte page in the telegram bot to telebot. For example: Your page: id4574835483 and along with this the avatar of this page. I am a teapot.
Answer the question
In order to leave comments, you need to log in
The vk api has a users.get method ( https://vk.com/dev/users.get ), with which you can get an avatar, and then using the telegram bot api and the sendMessage method ( https://core.telegram. org/bots/api#sendmessage ) send a photo
Good afternoon! Here is an example on vk_api BotsLongPoll
#Функция получения аватарки
def get_ava():
ava = vk.method('users.get', {'user_ids': mes.split(' ')[1], 'fields': 'photo_id', 'name_case': 'nom'})[0]['photo_id']
return ava
#Функия отправки аватарки + айди пользователя
id = event.chat_id
mes = event.object.message['text']
def unicalssender(id):
user_id = event.object.message['from_id']
vk.method("messages.send", {'chat_id': id, "message": 'сообщение которое хотите отправить' + ' ' + '\n' + str(user_id) + '\n', 'random_id': 0})
vk.method("messages.send", {"chat_id": id, "message": 'ваша аватарка', 'attachment': 'photo' + str(get_ava()), 'random_id': 0})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question