diff --git a/README.md b/README.md index 8b8aad2..0fb12fc 100644 --- a/README.md +++ b/README.md @@ -410,6 +410,7 @@ await client.sendMessage({ body: './file.jpg', // you can use a directory or use a url options: { type: 'sendImage', // shipping type + caption: 'image text' // image text } }).then((result) => { console.log(result); // message result @@ -454,7 +455,7 @@ await client.sendAudioBase64("0000000000@c.us", base64MP3) }); // Send image message -await client.sendImage("0000000000@c.us", './file.jpg') +await client.sendImage("0000000000@c.us", './file.jpg', { caption: 'image text' }) .then((result) => { console.log(result); // message result }).catch((error) => { diff --git a/docs/getting-started/send_functions.md b/docs/getting-started/send_functions.md index ddc05a1..36c4215 100644 --- a/docs/getting-started/send_functions.md +++ b/docs/getting-started/send_functions.md @@ -71,7 +71,7 @@ await client.sendAudioBase64("0000000000@c.us", base64MP3) Send image message ```javascript -await client.sendImage("0000000000@c.us", './file.jpg') +await client.sendImage("0000000000@c.us", './file.jpg', { caption: 'image text' }) .then((result) => { console.log(result); // message result }).catch((error) => { diff --git a/docs/getting-started/send_options.md b/docs/getting-started/send_options.md index f7f7b98..fa8778d 100644 --- a/docs/getting-started/send_options.md +++ b/docs/getting-started/send_options.md @@ -92,6 +92,7 @@ await client.sendMessage({ body: './file.jpg', // you can use a directory or use a url options: { type: 'sendImage', // shipping type + caption: 'image text' // image text } }).then((result) => { console.log(result); // message result diff --git a/src/webpack/api/layes/sender.layes.ts b/src/webpack/api/layes/sender.layes.ts index 8c10e0a..6db7d59 100644 --- a/src/webpack/api/layes/sender.layes.ts +++ b/src/webpack/api/layes/sender.layes.ts @@ -28,6 +28,7 @@ export class SenderLayer extends RetrieverLayer { */ public async sendImage(to: string, filePath: string, options: any = {}) { return new Promise(async (resolve, reject) => { + Object.assign(options, { type: FunctionType.sendImage }); let base64 = await downloadFileToBase64(filePath, [ 'image/gif', 'image/png', diff --git a/src/webpack/assets/functions/send-message.js b/src/webpack/assets/functions/send-message.js index 36fd887..3e6e174 100644 --- a/src/webpack/assets/functions/send-message.js +++ b/src/webpack/assets/functions/send-message.js @@ -6,7 +6,7 @@ */ export async function sendMessage(to, body, options = {}) { - const types = ['sendText', 'sendAudioBase64', 'sendAudio', 'sendFile']; + const types = ['sendText', 'sendAudioBase64', 'sendAudio', 'sendFile', 'sendImage']; let typesObj; types.reduce((a, v) => typesObj = ({ ...a, @@ -36,7 +36,8 @@ export async function sendMessage(to, body, options = {}) { if ( options.type === typesObj.sendAudioBase64 || options.type === typesObj.sendAudio || - options.type === typesObj.sendFile + options.type === typesObj.sendFile || + options.type === typesObj.sendImage ) { let result = await Store.Chat.find(chat.id); @@ -46,7 +47,7 @@ export async function sendMessage(to, body, options = {}) { const media = mc._models[0]; let enc, type; - if (options.type === typesObj.sendFile) { + if (options.type === typesObj.sendFile || options.type === typesObj.sendImage) { type = media.type; merge.caption = options?.caption; merge.filename = options?.filename;