M
M
mrdarkness2020-12-23 17:08:18
Python
mrdarkness, 2020-12-23 17:08:18

How to make a function to forward a message from one user to another in vk_api?

I need the bot to forward the messages of this user with the content of his screenshot to another user at a certain stage of the dialogue with one user.

That is, the user, in response to the bot's question, must send the bot a screenshot, and the bot must forward this message with the screenshot to another user.

At the moment, this part of the code looks like this:

def step2():
                    msg = responses_session.get('step2')  # предыдущий ответ пользователя со скриншотом
                    global screenshot
                    screenshot = True
                    global ytAttach
                    ytAttach = event.attachments

                    u = vk.users.get(user_ids=[str(event.user_id)])

                    vk.messages.send(
                        random_id=randomGen(1, 9999),
                        user_id=event.user_id,
                        message=msg
                    )
                    print(msgSent(event.user_id, randId, msg))

                    vk.messages.send(
                        forward={
                            'owner_id': event.user_id,
                            'peer_id': event.peer_id,
                            'message_ids': event.message_id,
                            # 'conversation_message_ids': event.message_id,
                        },
                        random_id=randomGen(1, 9999),
                        user_id=224453696,
                        message=partnerRequest(ytLink, event.user_id, u[0]['first_name'], u[0]['last_name']),
                        attachment=ytAttach,
                        keyboard=json.dumps(keyboard_yes_no, ensure_ascii=False)
                    )


This code throws an error:
vk_api.exceptions.ApiError: [100] One of the parameters specified was missing or invalid: forward contains incorrect JSON

Working with this documentation: https://vk.com/dev/messages.send

I don't understand what format or JSON content it expects from me. Help me to understand.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mrdarkness, 2020-12-25
@mrdarkness

Found a solution to my problem. I really don't know how reliable it is.
Should have used forward_messages=event.message_id

S
soremix, 2020-12-23
@SoreMix

Perhaps so

import json
forward=json.dump({
                            'owner_id': event.user_id,
                            'peer_id': event.peer_id,
                            'message_ids': event.message_id,
                            # 'conversation_message_ids': event.message_id,
                        })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question