Infer attachment type from file mime type and change endpoint accordingly.
This commit is contained in:
parent
6af2d4a1ea
commit
5cfd51fdb6
3 changed files with 9 additions and 5 deletions
2
app.js
2
app.js
|
|
@ -290,6 +290,8 @@ async function sendMessage() {
|
||||||
async function sendFileMessage(file) {
|
async function sendFileMessage(file) {
|
||||||
try {
|
try {
|
||||||
const result = await waha.sendFileMessage(activeChatState.id, file);
|
const result = await waha.sendFileMessage(activeChatState.id, file);
|
||||||
|
console.log(result)
|
||||||
|
// ui.appendSingleMessage(result, activeChatState.name, userInfo.id, activeChatState.id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message);
|
console.error(error.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
ui.js
1
ui.js
|
|
@ -147,7 +147,6 @@ export const ui = {
|
||||||
},
|
},
|
||||||
|
|
||||||
generateMessage(msg, activeChatName, userID, chatId) {
|
generateMessage(msg, activeChatName, userID, chatId) {
|
||||||
console.log(msg)
|
|
||||||
const isOutgoing = msg.fromMe || msg.sender === 'me';
|
const isOutgoing = msg.fromMe || msg.sender === 'me';
|
||||||
|
|
||||||
const groupDiv = document.createElement('div');
|
const groupDiv = document.createElement('div');
|
||||||
|
|
|
||||||
11
waha.js
11
waha.js
|
|
@ -144,7 +144,6 @@ export const waha = {
|
||||||
|
|
||||||
async sendFileMessage(chatId, file) {
|
async sendFileMessage(chatId, file) {
|
||||||
const fileBase64 = await getBase64(file);
|
const fileBase64 = await getBase64(file);
|
||||||
console.log(fileBase64)
|
|
||||||
const body = {
|
const body = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
@ -157,9 +156,13 @@ export const waha = {
|
||||||
session: config.session
|
session: config.session
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
console.log(body);
|
|
||||||
const result = await request('/api/sendFile', body);
|
let endpoint = "/api/sendFile";
|
||||||
console.log(result);
|
|
||||||
|
if (file.type.startsWith('image/')) endpoint = '/api/sendImage';
|
||||||
|
if (file.type.startsWith('video/')) endpoint = '/api/sendVideo';
|
||||||
|
|
||||||
|
const result = await request(endpoint, body);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue