D
D
duduychvbk992021-08-02 13:06:12
Bots
duduychvbk99, 2021-08-02 13:06:12

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

2 answer(s)
B
billy_herington, 2021-08-02
@billy_herington

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

R
RINAMI, 2021-08-02
@RINAMI

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})

The function works, instead of "your avatar" you can put any text.
6107d28f5c944691071595.png
In order for all this to work, the user must write something in the chat!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question