Skip to content

Commit

Permalink
fix: Fixed return for client.sendPollMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Oct 23, 2022
1 parent a518ea8 commit 0876eba
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/api/layers/sender.layer.ts
Expand Up @@ -1244,18 +1244,33 @@ 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,
choices,
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(<message>))` 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
Expand Down

0 comments on commit 0876eba

Please sign in to comment.