correct support for sending files via the bot

This commit is contained in:
Raven Scott
2024-06-15 02:52:20 -04:00
parent 49f4cc88ed
commit 2cf819553a
4 changed files with 46 additions and 20 deletions

View File

@ -1,22 +1,22 @@
import Message from "./Message.js";
class AudioMessage extends Message {
constructor(peerName, peerAvatar, topic, timestamp, audio, audioType) {
constructor(peerName, peerAvatar, topic, timestamp, audioUrl, audioType) {
super("audio", peerName, peerAvatar, topic, timestamp);
this.audio = audio;
this.audioUrl = audioUrl;
this.audioType = audioType;
}
toJsonString() {
return JSON.stringify({
...this.toJson(),
audio: this.audio,
audioUrl: this.audioUrl,
audioType: this.audioType
});
}
static new(bot, audio, audioType) {
return new AudioMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), audio, audioType);
static new(bot, audioUrl, audioType) {
return new AudioMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), audioUrl, audioType);
}
}

View File

@ -1,11 +1,13 @@
import Message from "./Message.js";
import b4a from "b4a";
class FileMessage extends Message {
constructor(peerName, peerAvatar, topic, timestamp, fileName, fileUrl, fileType) {
constructor(peerName, peerAvatar, topic, timestamp, fileName, fileUrl, fileType, fileData) {
super("file", peerName, peerAvatar, topic, timestamp);
this.fileName = fileName;
this.fileUrl = fileUrl;
this.fileType = fileType;
this.fileData = fileData; // Add file data property
}
toJsonString() {
@ -13,12 +15,14 @@ class FileMessage extends Message {
...this.toJson(),
fileName: this.fileName,
fileUrl: this.fileUrl,
fileType: this.fileType
fileType: this.fileType,
file: this.fileData // Include file data in JSON
});
}
static new(bot, fileName, fileUrl, fileType) {
return new FileMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), fileName, fileUrl, fileType);
static new(bot, fileName, fileUrl, fileType, fileBuffer) {
const fileData = b4a.toString(fileBuffer, 'base64'); // Convert file buffer to base64
return new FileMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), fileName, fileUrl, fileType, fileData);
}
}