Skip to content

Commit

Permalink
feat: image caption
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Jul 23, 2022
1 parent 2a8c511 commit b4bb5be
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/send_functions.md
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions docs/getting-started/send_options.md
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/webpack/api/layes/sender.layes.ts
Expand Up @@ -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',
Expand Down
7 changes: 4 additions & 3 deletions src/webpack/assets/functions/send-message.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

1 comment on commit b4bb5be

@jonalan7
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#50

Please sign in to comment.