mirror of
https://github.com/matrixgpt/matrix-chatgpt-bot.git
synced 2024-10-01 01:25:41 -04:00
Fix storage, e2e and add feature flags
This commit is contained in:
parent
9bd97b2453
commit
f33d01e531
@ -66,6 +66,8 @@ RUN npm install puppeteer@19.4.1 \
|
|||||||
&& chown -R pptruser:pptruser /home/pptruser
|
&& chown -R pptruser:pptruser /home/pptruser
|
||||||
USER pptruser
|
USER pptruser
|
||||||
|
|
||||||
|
VOLUME /storage
|
||||||
|
|
||||||
# We run a fake display and run our script.
|
# We run a fake display and run our script.
|
||||||
# Start script on Xvfb
|
# Start script on Xvfb
|
||||||
CMD xvfb-run --server-args="-screen 0 1024x768x24" yarn start
|
CMD xvfb-run --server-args="-screen 0 1024x768x24" yarn start
|
@ -18,7 +18,7 @@ You should not be using this ChatGPT account while the bot is using it, because
|
|||||||
If your OpenAI account uses Google Auth, you shouldn't encounter any of the more complicated Recaptchas — and can avoid using paid third-party CAPTCHA solving providers. To use Google auth, make sure your OpenAI account is using Google and then set IS_GOOGLE_LOGIN to true.
|
If your OpenAI account uses Google Auth, you shouldn't encounter any of the more complicated Recaptchas — and can avoid using paid third-party CAPTCHA solving providers. To use Google auth, make sure your OpenAI account is using Google and then set IS_GOOGLE_LOGIN to true.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
- Create an unencrypted room
|
- Create an (encrypted if enabled) room
|
||||||
- Add the bot
|
- Add the bot
|
||||||
- Start chatting away!
|
- Start chatting away!
|
||||||
|
|
||||||
@ -44,6 +44,11 @@ IS_GOOGLE_LOGIN=true
|
|||||||
# With the @ and :DOMAIN, ie @SOMETHING:DOMAIN
|
# With the @ and :DOMAIN, ie @SOMETHING:DOMAIN
|
||||||
MATRIX_BOT_USERNAME=
|
MATRIX_BOT_USERNAME=
|
||||||
MATRIX_BOT_PASSWORD=
|
MATRIX_BOT_PASSWORD=
|
||||||
|
MATRIX_AUTO_JOIN=true
|
||||||
|
MATRIX_ENCRYPTION=true
|
||||||
|
|
||||||
|
# needs to be ./storage/ if you aren't using Docker or /storage/ if you are.
|
||||||
|
DATA_PATH=/storage/
|
||||||
```
|
```
|
||||||
|
|
||||||
# Discussion
|
# Discussion
|
||||||
@ -65,7 +70,7 @@ recomend following the prompts at https://element.io/get-started to download and
|
|||||||
|
|
||||||
```
|
```
|
||||||
docker build . -t matrix-chatgpt-bot
|
docker build . -t matrix-chatgpt-bot
|
||||||
docker run --cap-add=SYS_ADMIN -it matrix-chatgpt-bot
|
docker run --cap-add=SYS_ADMIN -it -v ./storage:/storage matrix-chatgpt-bot
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: Without -it flags in the command above you won't be able to stop the container using Ctrl-C
|
Note: Without -it flags in the command above you won't be able to stop the container using Ctrl-C
|
||||||
|
@ -12,6 +12,10 @@ export const homeserverUrl = process.env.MATRIX_HOMESERVER_URL as string;
|
|||||||
/** The full username: eg @bot:server.com */
|
/** The full username: eg @bot:server.com */
|
||||||
export const matrixBotUsername = process.env.MATRIX_BOT_USERNAME as string;
|
export const matrixBotUsername = process.env.MATRIX_BOT_USERNAME as string;
|
||||||
export const matrixBotPassword = process.env.MATRIX_BOT_PASSWORD as string;
|
export const matrixBotPassword = process.env.MATRIX_BOT_PASSWORD as string;
|
||||||
|
export const matrixAutojoin = process.env.MATRIX_AUTO_JOIN && process.env.MATRIX_AUTO_JOIN.toLowerCase() === "true" as string;
|
||||||
|
export const matrixEncryption = process.env.MATRIX_ENCRYPTION && process.env.MATRIX_ENCRYPTION.toLowerCase() === "true" as string;
|
||||||
|
|
||||||
|
export const dataPath = process.env.DATA_PATH as string;
|
||||||
|
|
||||||
/** ChatGPT specific stuff */
|
/** ChatGPT specific stuff */
|
||||||
export const openAiEmail = process.env.OPENAI_EMAIL as string;
|
export const openAiEmail = process.env.OPENAI_EMAIL as string;
|
||||||
@ -22,6 +26,10 @@ if(accessToken === undefined) {
|
|||||||
console.error("MATRIX_ACCESS_TOKEN env variable is undefined");
|
console.error("MATRIX_ACCESS_TOKEN env variable is undefined");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
if(dataPath === undefined) {
|
||||||
|
console.error("DATA_PATH env variable is undefined");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
if(homeserverUrl === undefined) {
|
if(homeserverUrl === undefined) {
|
||||||
console.error("MATRIX_HOMESERVER_URL env variable is undefined");
|
console.error("MATRIX_HOMESERVER_URL env variable is undefined");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@ -34,6 +42,14 @@ if(matrixBotPassword === undefined) {
|
|||||||
console.error("MATRIX_BOT_PASSWORD env variable is undefined");
|
console.error("MATRIX_BOT_PASSWORD env variable is undefined");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
if(matrixAutojoin === undefined) {
|
||||||
|
console.error("MATRIX_AUTO_JOIN env variable is undefined");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
if(matrixEncryption === undefined) {
|
||||||
|
console.error("MATRIX_ENCRYPTION env variable is undefined");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
if(openAiEmail === undefined) {
|
if(openAiEmail === undefined) {
|
||||||
console.error("OPENAI_EMAIL env variable is undefined");
|
console.error("OPENAI_EMAIL env variable is undefined");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
21
src/index.ts
21
src/index.ts
@ -2,9 +2,11 @@ import {
|
|||||||
MatrixAuth, MatrixClient, SimpleFsStorageProvider, AutojoinRoomsMixin,
|
MatrixAuth, MatrixClient, SimpleFsStorageProvider, AutojoinRoomsMixin,
|
||||||
LogService, LogLevel,
|
LogService, LogLevel,
|
||||||
RichConsoleLogger,
|
RichConsoleLogger,
|
||||||
// RustSdkCryptoStorageProvider,
|
ICryptoStorageProvider,
|
||||||
|
RustSdkCryptoStorageProvider,
|
||||||
} from "matrix-bot-sdk";
|
} from "matrix-bot-sdk";
|
||||||
import { openAiEmail, openAiPassword, isGoogleLogin, homeserverUrl, matrixBotPassword, matrixBotUsername } from './config.js'
|
import * as path from "path";
|
||||||
|
import { dataPath, openAiEmail, openAiPassword, isGoogleLogin, homeserverUrl, accessToken, matrixAutojoin, matrixBotPassword, matrixBotUsername, matrixEncryption } from './config.js'
|
||||||
import { parseMatrixUsernamePretty } from './utils.js';
|
import { parseMatrixUsernamePretty } from './utils.js';
|
||||||
import { handleRoomEvent } from './handlers.js';
|
import { handleRoomEvent } from './handlers.js';
|
||||||
import { ChatGPTAPIBrowser } from 'chatgpt'
|
import { ChatGPTAPIBrowser } from 'chatgpt'
|
||||||
@ -19,10 +21,13 @@ LogService.setLevel(LogLevel.INFO);
|
|||||||
// LogService.muteModule("Metrics");
|
// LogService.muteModule("Metrics");
|
||||||
LogService.trace = LogService.debug;
|
LogService.trace = LogService.debug;
|
||||||
|
|
||||||
const storage = new SimpleFsStorageProvider("./storage/bot.json");
|
const storage = new SimpleFsStorageProvider(path.join(dataPath, "bot.json")); // /storage/bot.json
|
||||||
|
|
||||||
// Still fails to decrypt sometimes
|
// Prepare a crypto store if we need that
|
||||||
// const cryptoProvider = new RustSdkCryptoStorageProvider("./crypto/");
|
let cryptoStore: ICryptoStorageProvider;
|
||||||
|
if (matrixEncryption) {
|
||||||
|
cryptoStore = new RustSdkCryptoStorageProvider(path.join(dataPath, "encrypted")); // /storage/encrypted
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const botUsernameWithoutDomain = parseMatrixUsernamePretty(matrixBotUsername);
|
const botUsernameWithoutDomain = parseMatrixUsernamePretty(matrixBotUsername);
|
||||||
@ -38,7 +43,9 @@ async function main() {
|
|||||||
await chatGPT.initSession()
|
await chatGPT.initSession()
|
||||||
|
|
||||||
// Automatically join rooms the bot is invited to
|
// Automatically join rooms the bot is invited to
|
||||||
AutojoinRoomsMixin.setupOnClient(client);
|
if (matrixAutojoin) {
|
||||||
|
AutojoinRoomsMixin.setupOnClient(client);
|
||||||
|
}
|
||||||
|
|
||||||
client.on("room.failed_decryption", async (roomId, event, error) => {
|
client.on("room.failed_decryption", async (roomId, event, error) => {
|
||||||
// handle `m.room.encrypted` event that could not be decrypted
|
// handle `m.room.encrypted` event that could not be decrypted
|
||||||
@ -51,7 +58,7 @@ async function main() {
|
|||||||
|
|
||||||
await client.sendMessage(roomId, {
|
await client.sendMessage(roomId, {
|
||||||
"msgtype": "m.notice",
|
"msgtype": "m.notice",
|
||||||
"body": `👋 Hello, I'm the ChatGPT bot! I only work in unencrypted rooms at the moment.`,
|
"body": `👋 Hello, I'm the ChatGPT bot! Encrypted message support: ${ matrixEncryption }`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user