mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
Feat. Api send
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import AppError from "../../errors/AppError";
|
||||
import Setting from "../../models/Setting";
|
||||
|
||||
interface Response {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
const ListSettingByKeyService = async (
|
||||
value: string
|
||||
): Promise<Response | undefined> => {
|
||||
const settings = await Setting.findOne({
|
||||
where: { value }
|
||||
});
|
||||
|
||||
if (!settings) {
|
||||
throw new AppError("ERR_NO_API_TOKEN_FOUND", 404);
|
||||
}
|
||||
|
||||
return { key: settings.key, value: settings.value };
|
||||
};
|
||||
|
||||
export default ListSettingByKeyService;
|
||||
@@ -7,24 +7,28 @@ import Ticket from "../../models/Ticket";
|
||||
interface Request {
|
||||
media: Express.Multer.File;
|
||||
ticket: Ticket;
|
||||
body?: string;
|
||||
}
|
||||
|
||||
const SendWhatsAppMedia = async ({
|
||||
media,
|
||||
ticket
|
||||
ticket,
|
||||
body
|
||||
}: Request): Promise<WbotMessage> => {
|
||||
try {
|
||||
const wbot = await GetTicketWbot(ticket);
|
||||
|
||||
const newMedia = MessageMedia.fromFilePath(media.path);
|
||||
|
||||
const sentMessage = await wbot.sendMessage(
|
||||
`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`,
|
||||
newMedia,
|
||||
{ sendAudioAsVoice: true }
|
||||
{
|
||||
caption: body,
|
||||
sendAudioAsVoice: true
|
||||
}
|
||||
);
|
||||
|
||||
await ticket.update({ lastMessage: media.filename });
|
||||
await ticket.update({ lastMessage: body || media.filename });
|
||||
|
||||
fs.unlinkSync(media.path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user