mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 12:19:16 +00:00
migrated receive message logic to typescript
This commit is contained in:
25
backend/src/services/WbotServices/SendWhatsAppMessage.ts
Normal file
25
backend/src/services/WbotServices/SendWhatsAppMessage.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Message as WbotMessage } from "whatsapp-web.js";
|
||||
import GetTicketWbot from "../../helpers/GetTicketWbot";
|
||||
import Ticket from "../../models/Ticket";
|
||||
|
||||
interface Request {
|
||||
body: string;
|
||||
ticket: Ticket;
|
||||
}
|
||||
|
||||
const SendWhatsAppMessage = async ({
|
||||
body,
|
||||
ticket
|
||||
}: Request): Promise<WbotMessage> => {
|
||||
const wbot = await GetTicketWbot(ticket);
|
||||
|
||||
const sentMessage = await wbot.sendMessage(
|
||||
`${ticket.contact.number}@c.us`,
|
||||
body
|
||||
);
|
||||
|
||||
await ticket.update({ lastMessage: body });
|
||||
return sentMessage;
|
||||
};
|
||||
|
||||
export default SendWhatsAppMessage;
|
||||
Reference in New Issue
Block a user