Skip to content

Commit

Permalink
feat: Added sendPtt from file
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias authored and joaosouz4dev committed Feb 24, 2021
1 parent 2a8b476 commit ae38c8e
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/api/layers/sender.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export class SenderLayer extends ListenerLayer {
}

/**
* Sends file
* Sends ptt audio
* base64 parameter should have mime type already defined
* @param to Chat id
* @param base64 base64 data
Expand All @@ -291,6 +291,55 @@ export class SenderLayer extends ListenerLayer {
);
}

/**
* Sends ptt audio from path
* @param to Chat id
* @param filePath File path
* @param filename
* @param caption
*/
public async sendPtt(
to: string,
filePath: string,
filename?: string,
caption?: string
) {
return new Promise(async (resolve, reject) => {
let base64 = await downloadFileToBase64(filePath, [
'audio/3gpp',
'audio/3gpp2',
'audio/aac',
'audio/midi',
'audio/mpeg',
'audio/ogg',
'audio/webm',
'audio/x-wav',
]),
obj: { erro: boolean; to: string; text: string };

if (!base64) {
base64 = await fileToBase64(filePath);
}

if (!base64) {
obj = {
erro: true,
to: to,
text: 'No such file or directory, open "' + filePath + '"',
};
return reject(obj);
}

if (!filename) {
filename = path.basename(filePath);
}

return this.sendPttFromBase64(to, base64, filename, caption)
.then(resolve)
.catch(reject);
});
}

/**
* Sends file
* base64 parameter should have mime type already defined
Expand Down

0 comments on commit ae38c8e

Please sign in to comment.