D
D
Dmitry Skryabin2017-09-26 23:46:18
In contact with
Dmitry Skryabin, 2017-09-26 23:46:18

How to send messages from VK community apps?

I want to send messages to users from a community application (application - iframe).
I request permission to send using the showAllowMessagesFromCommunityBox method, but then when I try to send a message using the secure.sendNotification method (from the server), I get the error "Permission to perform this action is denied". That is, it seems like there are no rights, although the user gave permission when calling the showAllowMessagesFromCommunityBox method.
What is the correct way to send messages after getting permission via showAllowMessagesFromCommunityBox?
It doesn't matter to me where to send it from - from the server, or from the client.
I also tried the messages.send method, but there you need to additionally request permission to manage messages, so this is not it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Skryabin, 2017-09-28
@SkryabinD

I put my knowledge in order, I answer my own question.
To send messages from community apps, you need 2 permissions:
1. For the community administrator to allow the app to send messages on its behalf.
2. For the user to allow the application to send him messages.
In order for an application to send messages on behalf of a community, the application must obtain a token to do so. To do this, the client-side application must ask the administrator for permission to manage messages:
VK.callMethod("showGroupSettingsBox", 4096); //4096 is just message control, other permissions can be added here.
When the administrator has confirmed the rights, the onGroupSettingsChanged event is called, where the second parameter is the token that will need to be used to send messages, that is, it must be transferred to the server and used in the future.
The second is a request for permission from the user. Using the received token on the server side, using the messages.isMessagesFromGroupAllowed method, you need to check if the user has allowed sending messages. If there is no permission, then on the client side to request permission, call the showAllowMessagesFromCommunityBox method. And then send messages on the server side using the messages.send method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question