Answer the question
In order to leave comments, you need to log in
How to make the bot greet a new participant in a conversation?
I need to at the entrance to the conversation. My bot wrote something like "Greetings, First Name Last Name".
When someone enters the conversation, it says:
'action': {'type': 'chat_invite_user', 'member_id': 249297542}. How can this be implemented?
The script is written on the vk_api library using LongPoll. Script example:
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import vk_api
from datetime import datetime
import random
import time
import data
vk_session = vk_api.VkApi(token='токен')
session_api = vk_session.get_api()
longpoll = VkBotLongPoll(vk_session, #АЙДИ СООБЩЕСТВА )
def send_message( session_api, peer_id, message=None, attachment=None, keyboard=None, payload=None):
session_api.messages.send(peer_id=peer_id, message=message, random_id=random.randint(-2147483648, +2147483648),
attachment=attachment, keyboard=keyboard, payload=payload)
#photo-177397209_456239021
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
# ДЛЯ СООБЩЕНИЙ ИЗ БЕСЕДОК
response = event.obj.text.lower()
if event.obj.peer_id != event.obj.from_id:
sender_name = list(filter(lambda name: name['id'] == event.obj.from_id, [name for name in session_api.messages.getConversationMembers(peer_id=event.obj.peer_id, fields='profiles')['profiles']]))[0]
last_and_first_name = str(sender_name['first_name']) + ' ' + str(sender_name['last_name'])
if response == 'привет':
send_message(session_api,peer_id=event.obj.peer_id, message='Привет, {0}!'.format(last_and_first_name),attachment="АЙДИ КАРТИНКИ")
#обращение по именни и фамилии
print(event)
print('-' * 30)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question