sendFileMessage method

Future<Message?> sendFileMessage({
  1. required String phone,
  2. required WhatsappFileType fileType,
  3. required List<int> fileBytes,
  4. String? fileName,
  5. String? caption,
  6. String? mimetype,
  7. MessageId? replyMessageId,
  8. String? templateTitle,
  9. String? templateFooter,
  10. bool useTemplate = false,
  11. bool isViewOnce = false,
  12. bool audioAsPtt = false,
  13. List<MessageButtons>? buttons,
  14. Duration timeout = const Duration(seconds: 120),
})

send file messages using sendFileMessage returns Message object if sent successfully make sure to send fileType , we can also pass optional mimeType replyMessageId will send a quote message to the given messageId add caption to attach a text with the file

On Windows WebView2, this method bypasses WPP.chat.sendFileMessage and uses low-level WPP internals because the high-level API has an internal Promise that hangs due to chat.msgs.on('add') never firing.

Implementation

Future<Message?> sendFileMessage({
  required String phone,
  required WhatsappFileType fileType,
  required List<int> fileBytes,
  String? fileName,
  String? caption,
  String? mimetype,
  MessageId? replyMessageId,
  String? templateTitle,
  String? templateFooter,
  bool useTemplate = false,
  bool isViewOnce = false,
  bool audioAsPtt = false,
  List<MessageButtons>? buttons,
  Duration timeout = const Duration(seconds: 120),
}) {
  _checkButtons(buttons, useTemplate);
  final previous = _fileSendQueue;
  final done = Completer<void>();
  _fileSendQueue = done.future;
  return previous
      .then((_) => _sendFileMessage(
            phone: phone,
            fileType: fileType,
            fileBytes: fileBytes,
            fileName: fileName,
            caption: caption,
            mimetype: mimetype,
            replyMessageId: replyMessageId,
            templateTitle: templateTitle,
            templateFooter: templateFooter,
            useTemplate: useTemplate,
            isViewOnce: isViewOnce,
            audioAsPtt: audioAsPtt,
            buttons: buttons,
            timeout: timeout,
          ))
      .whenComplete(done.complete);
}