Skip to content

Commit

Permalink
Merge pull request #18 from web-tech-tw/arona
Browse files Browse the repository at this point in the history
Merge Arona branch
  • Loading branch information
supersonictw authored Jul 6, 2024
2 parents ff0364e + be05b5a commit 85d8273
Show file tree
Hide file tree
Showing 82 changed files with 3,951 additions and 1,094 deletions.
15 changes: 0 additions & 15 deletions .env.sample

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
node_modules
/dist
/data
.env
/static/file_*
config.yaml

# Log files
npm-debug.log*
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Arona

使用 [Messaging API](https://developers.line.biz/en/docs/messaging-api/overview/),讓 [LINE](https://line.me) 連接 [Matrix](https://matrix.org) 世界的那座橋樑。

This is the bridge for Matrix to connect with [LINE](https://line.me) via [Messaging API](https://developers.line.biz/en/docs/messaging-api/overview/).
The perfectest bridging for every messenger.

[Bridge](https://matrix.org/bridges/) is the idea makes **[Matrix](https://matrix.org)** cross connecting every Instant Message Providers.

Expand Down
96 changes: 81 additions & 15 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,85 @@
import "dotenv/config";
// Purpose: Main entry point for the application.

// Import the configuration.
import {
loopEvent as httpServerLoop,
} from "./src/http_server";
httpConfig,
} from "./src/config";

// Import the application.
import {
loopEvent as matrixListenerLoop,
} from "./src/provider/matrix/listener";

(async () => {
const events = [
httpServerLoop,
matrixListenerLoop,
];
await Promise.all(
events.map((e) => e()),
);
})();
app,
indexHandler,
heartHandler,
staticHandler,
checkHeartCode,
} from "./src/server";

// Import listen providers.
import MatrixListen from "./src/providers/matrix/listen";
import DiscordListen from "./src/providers/discord/listen";
import TelegramListen from "./src/providers/telegram/listen";

// Import hook providers.
import LINEHook from "./src/providers/line/hook";

// Import send providers.
import LINESend from "./src/providers/line/send";
import MatrixSend from "./src/providers/matrix/send";
import DiscordSend from "./src/providers/discord/send";
import TelegramSend from "./src/providers/telegram/send";
import OpenaiSend from "./src/providers/openai/send";

import {
hookRouter,
registerSendProviders,
registerHookProviders,
registerListenProviders,
} from "./src/registry";

// Register all senders.
await registerSendProviders([
new LINESend(),
new MatrixSend(),
new DiscordSend(),
new TelegramSend(),
new OpenaiSend(),
]);

// Register all listeners.
await registerListenProviders([
new MatrixListen(),
new DiscordListen(),
new TelegramListen(),
]);

// Register all Hookers.
await registerHookProviders([
new LINEHook(),
]);

// This route is used to handle the index.
app.get("/", indexHandler);

// This route is used to serve static files.
app.use("/static", staticHandler);

// This route is used to handle the heart.
app.get("/heart", heartHandler);

// This route is used to handle the hooks.
app.use("/hooks", hookRouter);

// Define the port to expose the application on.
const {
bindHost,
bindPort,
} = httpConfig();

// Create a server and listen to it.
app.listen(bindPort, bindHost, () => {
console.info("Arona");
console.info("===");
console.info("The perfectest bridging for every messenger.");
console.info(`Listening on http://${bindHost}:${bindPort}`);
checkHeartCode();
});
44 changes: 44 additions & 0 deletions config.sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
deviceName: "Arona"

http:
bindHost: 127.0.0.1
bindPort: 3000
baseUrl: "http://example.com"

bridge:
public: true

bridgeProvider:
# OpenAI
openai:
enable: true
# https://github.com/ai-tech-tw/openai
baseUrl: "https://web-tech-tw.eu.org/openai/v1"
apiKey: "YourGeminiApiKey"
chatModel: "gpt-3.5-turbo"

# LINE
line:
enable: true
channelAccessToken: "YourChannelAccessToken"
channelSecret: "YourChannelSecret"
useNotify: true
notifyClientId: "YourClientID"
notifyClientSecret: "YourClientSecret"

# Matrix
matrix:
enable: true
homeserverUrl: "https://matrix.org"
accessToken: "YourSecretAccessToken"

# Discord
discord:
enable: false
appId: "YourAppId"
botToken: "YourBotToken"

# Telegram
telegram:
enable: false
botToken: "YourBotToken"
18 changes: 12 additions & 6 deletions matrix_access.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import "dotenv/config";
import {
bridgeProviderConfig,
} from "./src/config";

import {
MatrixAuth,
} from "matrix-bot-sdk";

import {
homeserverUrl,
} from "./src/provider/matrix";

import inquirer from "inquirer";

const {
matrix: matrixConfig,
} = bridgeProviderConfig();

const {
homeserverUrl,
} = matrixConfig;

const auth = new MatrixAuth(homeserverUrl);

const questions = [{
Expand All @@ -28,7 +34,7 @@ console.info(
"\n",
);
inquirer.prompt(questions).then(({username, password}) => {
console.log();
console.info();
auth.passwordLogin(username, password).then((client) => {
console.info("AccessToken:", client.accessToken);
return client.getUserId();
Expand Down
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,41 @@
"author": "Taiwan Web Technology Promotion Organization",
"license": "MIT",
"main": "app.ts",
"type": "module",
"scripts": {
"dev": "nodemon --watch src/ app.ts",
"start": "ts-node app.ts",
"matrix-access": "ts-node matrix_access.ts",
"dev": "tsx watch app.ts",
"start": "tsx app.ts",
"matrix-access": "tsx matrix_access.ts",
"lint": "eslint \"app.ts\" \"matrix_access.ts\" \"src/**/*.ts\"",
"lint:fix": "eslint \"app.ts\" \"matrix_access.ts\" \"src/**/*.ts\" --fix"
},
"dependencies": {
"@line/bot-sdk": "^9.2.2",
"@matrix-org/matrix-sdk-crypto-nodejs": "0.1.0-beta.6",
"@types/i18n": "^0.13.12",
"@types/node-telegram-bot-api": "^0.64.7",
"axios": "^1.6.8",
"dotenv": "^16.4.5",
"discord.js": "^14.15.3",
"express": "^4.19.2",
"image-type": "^4.1.0",
"images": "^3.2.4",
"inquirer": "^8.2.4",
"lowdb": "^7.0.1",
"matrix-bot-sdk": "^0.7.1",
"ts-node": "^10.9.2"
"nanoid": "^5.0.7",
"node-cache": "^5.1.2",
"node-telegram-bot-api": "^0.66.0",
"openai": "^4.52.0",
"tsx": "^4.15.6",
"yaml": "^2.4.5"
},
"devDependencies": {
"@types/inquirer": "^9.0.7",
"@types/lowdb": "^1.0.15",
"@types/nanoid": "^3.0.0",
"@types/node": "^20.12.12",
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"eslint": "^8.56.0",
"eslint-config-google": "^0.14.0",
"nodemon": "^3.1.0",
"typescript": "^5.4.5"
}
}
Loading

0 comments on commit 85d8273

Please sign in to comment.