From 0876eba4b9060ae593af917265fdf3a3e7946de7 Mon Sep 17 00:00:00 2001 From: Cleiton Carvalho Date: Sun, 23 Oct 2022 18:51:09 -0300 Subject: [PATCH] fix: Fixed return for client.sendPollMessage --- src/api/layers/sender.layer.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/api/layers/sender.layer.ts b/src/api/layers/sender.layer.ts index c226b5ca1..c805ac3fd 100644 --- a/src/api/layers/sender.layer.ts +++ b/src/api/layers/sender.layer.ts @@ -1244,11 +1244,10 @@ export class SenderLayer extends ListenerLayer { choices: string[], options?: PoolMessageOptions ) { - return await evaluateAndReturn( + const sendResult = await evaluateAndReturn( this.page, - ({ chatId, name, choices, options }) => { - WPP.chat.sendCreatePollMessage(chatId, name, choices, options); - }, + ({ chatId, name, choices, options }) => + WPP.chat.sendCreatePollMessage(chatId, name, choices, options), { chatId, name, @@ -1256,6 +1255,22 @@ export class SenderLayer extends ListenerLayer { options: options as unknown as JSONObject, } ); + + // I don't know why the evaluate is returning undefined for direct call + // To solve that, I added `JSON.parse(JSON.stringify())` to solve that + const result = (await evaluateAndReturn( + this.page, + async ({ messageId }) => { + return JSON.parse(JSON.stringify(await WAPI.getMessageById(messageId))); + }, + { messageId: sendResult.id } + )) as Message; + + if (result['erro'] == true) { + throw result; + } + + return result; } /** * Sets the chat state