Skip to content

Commit

Permalink
fix: Updated reply method to use WA-JS (fix #627)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Nov 6, 2021
1 parent b4b2680 commit fbb30dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
15 changes: 8 additions & 7 deletions src/api/layers/sender.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,22 +276,23 @@ export class SenderLayer extends ListenerLayer {
content: string,
quotedMsg: string
): Promise<Message> {
const messageId: string = await evaluateAndReturn(
const result = await evaluateAndReturn(
this.page,
({ to, content, quotedMsg }) => {
return WAPI.reply(to, content, quotedMsg);
return WPP.chat.sendTextMessage(to, content, { quotedMsg });
},
{ to, content, quotedMsg }
);
const result = (await evaluateAndReturn(

const message = (await evaluateAndReturn(
this.page,
(messageId: any) => WAPI.getMessageById(messageId),
messageId
result.id
)) as Message;
if (result['erro'] == true) {
throw result;
if (message['erro'] == true) {
throw message;
}
return result;
return message;
}

/**
Expand Down
34 changes: 4 additions & 30 deletions src/lib/wapi/functions/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,10 @@
* along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
*/

import { getMessageById } from './get-message-by-id';

export async function reply(chatId, content, quotedMessageId) {
const chat = Store.Chat.get(chatId);

let quotedMsgOptions = {};
if (quotedMessageId) {
let quotedMessage = await getMessageById(quotedMessageId, null, false);
if (quotedMessage && quotedMessage.canReply()) {
quotedMsgOptions = quotedMessage.msgContextInfo(chat);
}
}

const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const fromwWid = await Store.UserPrefs.getMaybeMeUser();
const message = {
id: newMsgId,
ack: 0,
body: content,
from: fromwWid,
to: chat.id,
local: !0,
self: 'out',
t: parseInt(new Date().getTime() / 1000),
isNewMsg: !0,
type: 'chat',
...quotedMsgOptions,
};

await window.Store.addAndSendMsgToChat(chat, message);
const result = await WPP.chat.sendTextMessage(chatId, content, {
quotedMsg: quotedMessageId,
});

return newMsgId._serialized;
return result.id.toString();
}

0 comments on commit fbb30dd

Please sign in to comment.