turt2live / matrix-bot-sdk

TypeScript/JavaScript SDK for Matrix bots
MIT License
194 stars 68 forks source link

Messages are not decrypted in the bot #324

Closed shahabes closed 1 year ago

shahabes commented 1 year ago

Hello friends. I'm developing a bot with node js. It's my source code.

const sdk = require("matrix-bot-sdk");
const MatrixClient = sdk.MatrixClient;
const SimpleFsStorageProvider = sdk.SimpleFsStorageProvider;
const AutojoinRoomsMixin = sdk.AutojoinRoomsMixin;
const RustSdkCryptoStorageProvider = sdk.RustSdkCryptoStorageProvider;

const homeserverUrl = "https://msg.test.com";
const accessToken = "************";

const storage = new SimpleFsStorageProvider("bot.json");

const cryptoProvider = new RustSdkCryptoStorageProvider("./crypto_test");

const client = new MatrixClient(
  homeserverUrl,
  accessToken,
  storage,
  cryptoProvider
);

AutojoinRoomsMixin.setupOnClient(client);

client.start().then(async () => {
  const roomId = await client.joinRoom("#test:msg.test.com");
});

client.on("room.message", async (roomId, event) => {
  const sender = event["sender"];
  const body = event["content"]["body"];
  console.log(`${roomId}: ${sender} says '${body}`);
});

When I received an event, a problem occurs in decrypting the event. Following error is return.

MatrixClientLite Decryption error on !ilyRhAAhVtTKOzFvys:msg.test.com $ODax0x9inouwio-I8IywEH8oTdupXY7TvrIKYr8wFhk [Error: Can't find the room key to decrypt the event] {
  code: 'GenericFailure'
}

what should I do?

turt2live commented 1 year ago

Please don't cross-post.