sendFileMessage method
send file messages using sendFileMessage
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
Implementation
Future 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,
}) async {
String base64Image = base64Encode(fileBytes);
String mimeType = mimetype ?? getMimeType(fileType, fileName, fileBytes);
String fileData = "data:$mimeType;base64,$base64Image";
String fileTypeName = "image";
if (mimeType.split("/").length > 1) {
fileTypeName = mimeType.split("/").first;
}
// Check for video file type
if (fileTypeName == "video") {
fileTypeName = "video"; // Set the correct file type for videos
}
String? replyTextId = replyMessageId?.serialized;
String? buttonsText = buttons?.map((e) => e.toJson()).toList().toString();
String source = '''WPP.chat.sendFileMessage(${phone.phoneParse},${fileData.jsParse},{
type: ${fileTypeName.jsParse},
isPtt: ${audioAsPtt.jsParse},
isViewOnce: ${isViewOnce.jsParse},
filename: ${fileName.jsParse},
caption: ${caption.jsParse},
quotedMsg: ${replyTextId.jsParse},
useTemplateButtons: ${useTemplate.jsParse},
buttons:$buttonsText,
title: ${templateTitle.jsParse},
footer: ${templateFooter.jsParse}
});''';
var sendResult = await wpClient.evaluateJs(source);
WhatsappLogger.log("SendResult : $sendResult");
return sendResult;
}