Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while using client.crypto.decryptRoomEvent #368

Open
alexgaill opened this issue Aug 19, 2024 · 0 comments
Open

Error while using client.crypto.decryptRoomEvent #368

alexgaill opened this issue Aug 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@alexgaill
Copy link

Describe the bug
I want to get the event history of a room and call matrix api: "GET", /_matrix/client/v3/rooms/{roomId}/messages
After that, i need to decrypt every m.room.encrypted and use MatrixClient().crypto.decryptRoomEvent.

I got this error:

Error: Expect value to be String, but received Undefined
at CryptoClient.decryptRoomEvent (C:\Users\Alexandre\Desktop\dev\minint\bot\node_modules\matrix-bot-sdk\lib\e2ee\CryptoClient.js:195:53)
at descriptor.value (C:\Users\Alexandre\Desktop\dev\minint\bot\node_modules\matrix-bot-sdk\lib\e2ee\decorators.js:33:35)
at getRoomEvents (file:///C:/Users/Alexandre/Desktop/dev/minint/bot/dist/commands/domain/exportRoom.js:29:70)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async exportRoom (file:///C:/Users/Alexandre/Desktop/dev/minint/bot/dist/commands/domain/exportRoom.js:2:20) {
code: 'InvalidArg'
}

To Reproduce
My code:

async function getRoomEvents(client: MatrixClient, roomId: string): Promise<RoomEvent[]> {
  let events: RoomEvent[] = [];
  try {
    let endToken = undefined;
    do {
      const response = await client.doRequest("GET", `/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/messages`, {
        from: endToken,
        dir: "b",
        limit: 100
      });
      for (const event of response.chunk) {
        if (event.type === 'm.room.encrypted') {
          const decryptedMessage = await client.crypto.decryptRoomEvent(event, roomId);
          event.push(decryptedMessage)
        } else {
          events.push(event);
        }
      }
      endToken = response.end;
    } while (endToken != null);
  } catch (error: any) {
    console.error(`Erreur lors de la récupération des événements :`, error);
  }
  return events;
}

Expected behavior
Get decrypted messages event.

@alexgaill alexgaill added the bug Something isn't working label Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant