matrixgpt / matrix-chatgpt-bot

Talk to ChatGPT via any Matrix client!
GNU Affero General Public License v3.0
234 stars 63 forks source link

I can bridge to matrix.org, but not to my local dendrite server. #131

Closed mwnu closed 10 months ago

mwnu commented 1 year ago

Setting MATRIX_HOMESERVER_URL to my main domain generates an interruption error on the first run:

yarn run v1.22.19
$ node --enable-source-maps dist/index.js
Thu, 09 Mar 2023 14:01:43 GMT [ERROR] [MatrixHttpClient] (REQ-1)
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<IncomingMessage>".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

My main domain has well-known configuration and connects normally with other servers and clients. If I configure MATRIX_HOMESERVER_URL directly to my dendrite server address, It can generate a MATRIX_ACCESS_TOKEN, but after changing MATRIX_BOT_PASSWORD to MATRIX_ACCESS_TOKEN, the log repeatedly produces errors and cannot be run after restarting:

Wed, 08 Mar 2023 18:37:15 GMT [ERROR] [MatrixHttpClient] (REQ-3) { errcode: 'M_NOT_FOUND', error: 'data not found' }
Wed, 08 Mar 2023 18:37:15 GMT [INFO] [MatrixClientLite] End-to-end encryption enabled
Wed, 08 Mar 2023 18:37:15 GMT [INFO] [index] Bot started!
Wed, 08 Mar 2023 18:37:15 GMT [ERROR] [MatrixHttpClient] (REQ-9) {
  '@chatgptbot:example.com': {
    'vS8yI-Zk': {
      error: 'user_id or device_id mismatch: users:  - @chatgptbot:example.com, devices:  - vS8yI-Zk'
    }
  }
}
Wed, 08 Mar 2023 18:37:15 GMT [ERROR] [MatrixClientLite] Error handling sync [object Object]
Wed, 08 Mar 2023 18:37:15 GMT [INFO] [MatrixClientLite] Backing off for 9472.12990515016ms

Whether I remove "@ and :DOMAIN" from MATRIX_BOT_USERNAME, or change the MATRIX_HOMESERVER_URL, or use a new account that has never logged in before, I don't know if this bot is incompatible with dendrite or if there is a problem with my server configuration?

mwnu commented 1 year ago

I found out where the problem is. Matrix E2EE must not be enabled (MATRIX_ENCRYPTION=false), otherwise there will be an error: 'user_id or device_id mismatch'. It means that the ChatGPT bot cannot automatically reply based on context in the thread or be privately messaged because the private chat rooms are end-to-end encrypted. The only way to trigger the bot is using !chatgpt PREFIX and mention @ .

ReggieMarr commented 1 year ago

I noticed this as well. So what did you do, just invite the bot to an unencrypted room and mention it ?

mwnu commented 1 year ago

I noticed this as well. So what did you do, just invite the bot to an unencrypted room and mention it ?

Yes, that's the only way to use it.

frandavid100 commented 1 year ago

I'm also getting a similar error. journalctl -fu matrix-bot-chatgpt says:

Mar 21 16:02:17 localhost systemd[1]: Starting Matrix chatgpt bot... Mar 21 16:02:18 localhost systemd[1]: Started Matrix chatgpt bot. Mar 21 16:02:20 localhost matrix-bot-chatgpt[106873]: yarn run v1.22.19 Mar 21 16:02:20 localhost matrix-bot-chatgpt[106873]: $ node --enable-source-maps dist/index.js Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: Tue, 21 Mar 2023 16:02:23 GMT [INFO] [index] Starting bot using ChatGPT model: gpt-3.5-turbo Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: Tue, 21 Mar 2023 16:02:23 GMT [INFO] [index] Using promptPrefix: <|im_sep|>Instructions: Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: You are ChatGPT, a large language model trained by OpenAI. Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: Current date: March 21, 2023<|im_sep|> Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: Tue, 21 Mar 2023 16:02:23 GMT [ERROR] [MatrixHttpClient] (REQ-5) { Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: errcode: 'M_NOT_FOUND', Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: error: 'Cannot find state event for "m.room.encryption"' Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: } Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: Tue, 21 Mar 2023 16:02:23 GMT [ERROR] [MatrixHttpClient] (REQ-6) { Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: errcode: 'M_NOT_FOUND', Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: error: 'Cannot find state event for "m.room.encryption"' Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: } Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: Tue, 21 Mar 2023 16:02:23 GMT [ERROR] [MatrixHttpClient] (REQ-7) { Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: '@bot.chatgpt:arada.club': { Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: r2MmDKKj: { Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: error: 'user_id or device_id mismatch: users: - @bot.chatgpt:arada.club, devices: - r2MmDKKj' Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: } Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: } Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: } Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: node:internal/process/promises:289 Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: triggerUncaughtException(err, true / fromPromise /); Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: ^ Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: [UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#".] { Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: code: 'ERR_UNHANDLED_REJECTION' Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: } Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: Node.js v19.7.0 Mar 21 16:02:23 localhost matrix-bot-chatgpt[106873]: error Command failed with exit code 1.

However, there seems no way to make the bot react. Not even inviting it to an unencrypted room and mentioning it works.

Is there any way I can help find out what's wrong?

frandavid100 commented 1 year ago

I found out where the problem is. Matrix E2EE must not be enabled (MATRIX_ENCRYPTION=false), otherwise there will be an error: 'user_id or device_id mismatch'. It means that the ChatGPT bot cannot automatically reply based on context in the thread or be privately messaged because the private chat rooms are end-to-end encrypted. The only way to trigger the bot is using !chatgpt PREFIX and mention @ .

Thanks, I also noticed this problem but didn't know that disabling encryption could be used as a workaround.

By the way, have you tried to use /converttodm after inviting the bot to a private room? Maybe that way you won't have to mention it to get a reply?

mwnu commented 1 year ago

I found out where the problem is. Matrix E2EE must not be enabled (MATRIX_ENCRYPTION=false), otherwise there will be an error: 'user_id or device_id mismatch'. It means that the ChatGPT bot cannot automatically reply based on context in the thread or be privately messaged because the private chat rooms are end-to-end encrypted. The only way to trigger the bot is using !chatgpt PREFIX and mention @ .

Thanks, I also noticed this problem but didn't know that disabling encryption could be used as a workaround.

By the way, have you tried to use /converttodm after inviting the bot to a private room? Maybe that way you won't have to mention it to get a reply?

In an encrypted room, robots cannot read the content.

frandavid100 commented 1 year ago

My bad, i should have specified. I meant after inviting the bot to a private UNENCRYPTED room, and then entering /converttodm.

frandavid100 commented 1 year ago

The ChatGPT bot cannot automatically reply based on context in the thread or be privately messaged because the private chat rooms are end-to-end encrypted. The only way to trigger the bot is using !chatgpt PREFIX and mention @ .

I found a workaround that lets you trigger the bot without having to mention it. If you send it a DM from an unverified session, the private room is unencrypted and the bot replies to everything you write.

mwnu commented 1 year ago

The ChatGPT bot cannot automatically reply based on context in the thread or be privately messaged because the private chat rooms are end-to-end encrypted. The only way to trigger the bot is using !chatgpt PREFIX and mention @ .

I found a workaround that lets you trigger the bot without having to mention it. If you send it a DM from an unverified session, the private room is unencrypted and the bot replies to everything you write.

Private rooms are always encrypted, regardless of whether your client is verified. Unencrypted rooms that have invited bots can only be triggered by using !chatgpt. I don't know what you're referring to.

frandavid100 commented 1 year ago

The ChatGPT bot cannot automatically reply based on context in the thread or be privately messaged because the private chat rooms are end-to-end encrypted. The only way to trigger the bot is using !chatgpt PREFIX and mention @ .

I found a workaround that lets you trigger the bot without having to mention it. If you send it a DM from an unverified session, the private room is unencrypted and the bot replies to everything you write.

Private rooms are always encrypted, regardless of whether your client is verified. Unencrypted rooms that have invited bots can only be triggered by using !chatgpt. I don't know what you're referring to.

Nope, private rooms created by an unverified session are unencrypted. Give it a try.

mwnu commented 1 year ago

I have tried it, and private chats initiated from unencrypted conversations are still in encrypted rooms, but it seems that unencrypted messages can be sent. However, the robot will not respond in a private room.

frandavid100 commented 1 year ago

Maybe it depends on which client you're using. I was using Element Android, and the DM room it created was unencrypted, and the bot replied just fine without having to mention it. Here's a couple screenshots as proof: Screenshot_20230411-093458 Screenshot_20230411-093551

Anyway, at this point this is probably off-topic, so I'll let it be.

mwnu commented 1 year ago

Maybe it depends on which client you're using. I was using Element Android, and the DM room it created was unencrypted, and the bot replied just fine without having to mention it. Here's a couple screenshots as proof:

What I want to say is that I have tried it and it doesn’t work.

bertybuttface commented 1 year ago

Is this issue stale or does this still occur?

MelBourbon commented 1 year ago

Note: I also running the bot with dendrite and need to apply the workaround with inviting the bot to an unencrypted room. But if you remove !chatgpt and keep MATRIX_DEFAULT_PREFIX= in the .env file empty the bot replies to all questions. Limitation is that you can only use the bot in 1:1 chats (rooms).