Skip to content

Commit

Permalink
add option to send link previews through API - defaults to false -
Browse files Browse the repository at this point in the history
relates to #270
  • Loading branch information
allgood committed Jan 2, 2025
1 parent 4596611 commit fe24347
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
14 changes: 3 additions & 11 deletions backend/src/controllers/MessageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import AppError from "../errors/AppError";

import SetTicketMessagesAsRead from "../helpers/SetTicketMessagesAsRead";
import { getIO } from "../libs/socket";
import Message from "../models/Message";
import Queue from "../models/Queue";
import User from "../models/User";
import Whatsapp from "../models/Whatsapp";
Expand All @@ -19,21 +18,13 @@ import EditWhatsAppMessage from "../services/WbotServices/EditWhatsAppMessage";
import { sendFacebookMessageMedia } from "../services/FacebookServices/sendFacebookMessageMedia";
import sendFaceMessage from "../services/FacebookServices/sendFacebookMessage";
import { logger } from "../utils/logger";
import { MessageData } from "../helpers/SendMessage";

type IndexQuery = {
pageNumber: string;
markAsRead: string;
};

type MessageData = {
body: string;
fromMe: boolean;
read: boolean;
quotedMsg?: Message;
number?: string;
saveOnTicket?: boolean;
};

export const index = async (req: Request, res: Response): Promise<Response> => {
const { ticketId } = req.params;
const { pageNumber, markAsRead } = req.query as IndexQuery;
Expand Down Expand Up @@ -161,7 +152,7 @@ export const send = async (req: Request, res: Response): Promise<Response> => {

try {
let { number } = messageData;
const { body } = messageData;
const { body, linkPreview } = messageData;
const saveOnTicket = !!messageData.saveOnTicket;

if (!number.includes("@")) {
Expand Down Expand Up @@ -203,6 +194,7 @@ export const send = async (req: Request, res: Response): Promise<Response> => {
data: {
number,
body,
linkPreview,
saveOnTicket
}
},
Expand Down
15 changes: 13 additions & 2 deletions backend/src/helpers/SendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import Whatsapp from "../models/Whatsapp";
import GetWhatsappWbot from "./GetWhatsappWbot";
import { getMessageOptions } from "../services/WbotServices/SendWhatsAppMedia";
import { handleMessage } from "../services/WbotServices/wbotMessageListener";
import Message from "../models/Message";

export type MessageData = {
number: number | string;
number: string;
body: string;
mediaPath?: string;
saveOnTicket?: boolean;
fromMe?: boolean;
read?: boolean;
quotedMsg?: Message;
linkPreview?: any;
};

export const SendMessage = async (
Expand All @@ -32,7 +37,13 @@ export const SendMessage = async (
});
}
} else {
message = await wbot.sendMessage(chatId, { text: body });
message = await wbot.sendMessage(chatId, {
text: body,
linkPreview:
messageData.linkPreview === true
? undefined
: messageData.linkPreview || false
});
}

if (messageData.saveOnTicket) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/MessagesAPI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const MessagesAPI = () => {
<b>Endpoint: </b> {getEndpoint()} <br />
<b>Método: </b> POST <br />
<b>Headers: </b> Authorization ("Bearer " + token cadastrado) e Content-Type (application/json) <br />
<b>Body: </b> {"{ \"number\": \"558599999999\", \"body\": \"Sua mensagem\", \"saveOnTicket\": true }"}
<b>Body: </b> {"{ \"number\": \"558599999999\", \"body\": \"Sua mensagem\", \"saveOnTicket\": true, \"linkPreview\": true }"}
</Typography>
</Grid>
<Grid item xs={12} sm={6}>
Expand Down

0 comments on commit fe24347

Please sign in to comment.