vkdart

Форк
0

README.md

VkDart

Pub Version Pub Popularity Pub Points

The package helps to simplify the work with VK API.

A chat room to discuss how the package works - https://t.me/vk_dart

Features

  1. Reliability. Package functionality is wrapped in unit tests.
  2. Supports events. Supports Callback API, Longpoll API
  3. Development. Functionality is becoming more and more every day!
  4. Easy to use. Very easy to use!
  5. Model support. There is a description of event, attachment and object models.

Usage

Initialization:

import 'package:vkdart/vkdart.dart';
void main() async {
final TOKEN = '';
final GROUP_ID = 1;
final myFetcher = Longpoll(GROUP_ID); // or Webhook (CallbackAPI).
final vkdart = VkDart(TOKEN, fetcher: myFetcher);
vkdart.start();
}

Using API:

await vkdart.request('groups.getById', {'group_id': 1}); // List<Map<String, dynamic>>

Events

VkDart base class contains functions for processing VK API events. Some events are combined into a single handler, consider this example:

/// message_new, message_reply, message_reply.
vkdart.onMessage().listen((event) { ... });

In this case the events message_new, message_reply, message_edit will be processed in this listen. In order to filter the necessary events, you can modify Stream:

vkdart
.onMessage()
.where((event) => event.isNew && event.isChat)
.listen((event) { ... });

Due to the fact that VK API is also updated, new events are added, there is a handler onUnsupportedEvent. If you have caught such an event, please report it to our chat.

vkdart.onUnsupportedEvent().listen((event) {
print(
'An unsupported event has arrived!\n'
'It is necessary to inform the chat https://t.me/vk_dart\n\n'
'Type of event ${event.eventType}\n'
'Event Object: ${event.object}',
);
});

Each event handler, has its own functions, fields and other useful features. All update models can be found on this page.

All event handlers can be found on this page.

Keyboard

The package includes a keyboard builder:

import 'package:vkdart/util.dart' show VkDartKeyboard, VkDartKeyboardColor;
final keyboard = VkDartKeyboard(
oneTime: true, // default value
inline: false // default value
);

Warning! The keyboard grid has limitations:

  • For conventional keyboard size: 5 × 10, maximum number of keys: 40
  • For inline keyboard size: 5 × 6, maximum number of keys: 10

Text button:

keyboard.addButtonText('Hello world!', color: VkDartKeyboardColor.primary, payload: {'button': 'text'});

The payload will be available in message_new event, in the messagePayload property.

URL button:

keyboard.addButtonLink('mysite.com', 'My Site');

Location button:

keyboard.addButtonLocation(payload: {'button': 'location'});

The payload will be available in message_new event, in the messagePayload property.

Vk Pay button:

keyboard.addButtonVkPay("action=transfer-to-group&group_id=1&aid=10");

Open APP button:

keyboard.addButtonApp(6232540, -157525928, hash: "123", appName: 'LiveWidget');

Callback button:

keyboard.addButtonCallback(
'Hello world!',
color: VkDartKeyboard.secondary, // default value
payload: {'button': 'callback'}
);

The payload will be available in the message_event event, in the eventPayload property.

Move on to the next row:

keyboard
..addButtonText('1 row: Hello world!')
..nextRow()
..addButtonText('2 row: Hello world!');

Usage in the messages.send method:

vkdart.messages.send({
'peer_id': PEER_ID,
'message': 'Hello world!',
'random_id': RANDOM_ID,
'keyboard': keyboard.toJson()
});

Button Colors:

FieldDescriptionColor
VkDartKeyboardColor.primaryMain ActionBlue
VkDartKeyboardColor.secondaryIt's just a buttonWhite
VkDartKeyboardColor.negativeDangerous Action or FailureRed
VkDartKeyboardColor.positive"Agree," "Confirm."Green

Attachments

There are two types of class:

final customAttachment = CustomAttachmentModel({
'owner_id': 1,
'id': 2,
// 'access_key': 'ACCESS_KEY'
}, attachType: 'photo');

In VK there is a format of attachments, let's say to send it in private messages, for convenience the CustomAttachmentModel class has an overridden function toString(), which will return this format.

customAttachment.toString(); // photo1_2 and photo1_2_ACCESS_KEY (if access != null)
[customAttachment, customAttachment].join(',') // photo1_2,photo1_2

Suppose we have an attachment object in Map format, in order to convert it into the necessary model, we will use the fromSpecificModel constructor:

AttachmentModel.fromSpecificModel({
'owner_id': 1,
'id': 2
}, attachType: 'photo'); // PhotoAttachmentModel

Convert the attachment string to a model:

CustomAttachment.fromString('photo1_2'); // PhotoAttachmentModel

Future plans

  • Release models of VK API objects. ✔
  • Release a class that makes keyboarding easier. ✔
  • Release features, for chatbot commands.

Bugs and feature requests

Please send a bug report to issue tracker

Описание

Package helps simplify working with the VK API. Completely wraps VK methods, has event support and much more.

https://pub.dev/packages/vkdart

Языки

Dart

Сообщить о нарушении

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.