answer method

Future<bool> answer({
  1. required String type,
  2. String? text,
  3. String? link,
  4. int? appId,
  5. int? ownerId,
  6. String? hash,
})

Sends an event with the action that will occur when the callback button is clicked. Calls the messages.send method, with the properties eventId, peerId, userId. The type property accepts only one of these values: show_snackbar, open_link, open_app. If the type is unknown or the required properties are unknown, an ArgumentError will be thrown.

Will return true upon successful execution.

See: https://dev.vk.com/ru/api/bots/development/keyboard#Типы%20действий

Sample Example:

vkdart
    .onMessageEvent()
    .listen((event) => event.answer(type: 'show_snackbar', text: 'Hello world!'));

Implementation

Future<bool> answer(
    {required String type,
    String? text,
    String? link,
    int? appId,
    int? ownerId,
    String? hash}) {
  /// ignore: non_constant_identifier_names
  final event_data = <String, dynamic>{'type': type};

  switch (type) {
    case 'show_snackbar':
      event_data['text'] = ArgumentError.checkNotNull(text, 'text');
    case 'open_link':
      event_data['link'] = ArgumentError.checkNotNull(link, 'link');
    case 'open_app':
      event_data
        ..['app_id'] = ArgumentError.checkNotNull(appId, 'appId')
        ..['owner_id'] = ArgumentError.checkNotNull(ownerId, 'ownerId')
        ..['hash'] = ArgumentError.checkNotNull(hash, 'hash');
    default:
      throw ArgumentError.value(type, 'type',
          'only 3 values are possible: show_snackbar, open_link, open_app');
  }

  return _vkontakte.request('messages.sendMessageEventAnswer', {
    'event_id': eventId,
    'peer_id': peerId,
    'user_id': userId,
    'event_data': event_data
  }).then((value) => checkBoolUtil(value)!);
}