The translation was generated automatically and may contain mistakes
Allow Community Messages
This widget will allow customers to quickly sign up for notifications in private messages from the community without leaving your site.
This is a convenient way to organize a subscription to a regular newsletter. After receiving consent from the user, the community can send him a message without any time limit.
At any time, the user can prohibit sending messages to him using a button in a dialogue with the community.
Connecting Widget
In the tag <head> On your website, add a link.. openapi.js :
<script src="https://vk.ru/js/api/openapi.js?169" type="text/javascript"></script>Add an element to the body of the page <div> , in which the widget will be displayed, set it to unique id , and add a widget initialization code to it. For example:
<div id="vk_send_message"></div>
<script type="text/javascript">
VK.Widgets.AllowMessagesFromCommunity("vk_send_message", {height: 30}, 127864554);
</script>Additional settings
Method VK.Widgets.AllowMessagesFromCommunity It takes three parameters:
- •
element_id(string), the mandatory parameter is the id of the element that will be the container for the block with the widget. Our default constructor uses a valuevk_send_message. - •
options(object) — block options with widget. An object that can contain fields:- •
height(integerThe height of the block in pixels. Possible values:22,24,30.
- •
- •
group_id(stringCommunity ID.
Events
When you press the button Receive Notifications Widget transmits an event widgets.allowMessagesFromCommunity.allowed . If the user clicks Banned Notifications the event is transmitted and widgets.allowMessagesFromCommunity.denied . You can process these events using Open API . A single parameter, the identifier of the user who performed the action, will be passed to the handler function.
Example of use
<script type="text/javascript" src="https://vk.ru/js/api/openapi.js?169"></script>
<script type="text/javascript">
VK.Widgets.AllowMessagesFromCommunity("vk_send_message", {height: 30}, 1);
VK.Observer.subscribe("widgets.allowMessagesFromCommunity.allowed", function f(userId) {
console.log(userId);
console.log("allowed");
});
VK.Observer.subscribe("widgets.allowMessagesFromCommunity.denied", function f(userId) {
console.log(userId);
console.log("denied");
});
</script>Widget code
To add a widget to your site, simply copy the code to paste to the page you want to place the widget on.