From 776039429f03800183cd4ea1424758e12d456114 Mon Sep 17 00:00:00 2001 From: lub Date: Mon, 15 Oct 2018 21:05:02 +0200 Subject: [PATCH] initial code; hello world --- .gitignore | 2 ++ .vscode/launch.json | 11 +++++++++++ config.sample.yaml | 3 +++ config.schema.yaml | 9 +++++++++ index.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 config.sample.yaml create mode 100644 config.schema.yaml diff --git a/.gitignore b/.gitignore index 3c3629e..efb067c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +config.yaml +registration.yaml \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b0a273a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/index.js", + "args": ["--config","config.yaml"] + } + ] +} \ No newline at end of file diff --git a/config.sample.yaml b/config.sample.yaml new file mode 100644 index 0000000..84c4505 --- /dev/null +++ b/config.sample.yaml @@ -0,0 +1,3 @@ +homeserver: 'http://localhost:8008' +domain: 'localhost' +registration: 'registration.yaml' \ No newline at end of file diff --git a/config.schema.yaml b/config.schema.yaml new file mode 100644 index 0000000..eb0552c --- /dev/null +++ b/config.schema.yaml @@ -0,0 +1,9 @@ +type: object +requires: ['homeserver', 'domain', registration] +properties: + homesever: + type: string + domain: + type: string + registration: + type: string \ No newline at end of file diff --git a/index.js b/index.js index e69de29..e1184aa 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,45 @@ +const appservicePort = 9000; +const roomId = '!MQClELEJFefiUVmsNw:imninja.net'; + +//const http = require('http'); +const Cli = require('matrix-appservice-bridge').Cli; +const Bridge = require('matrix-appservice-bridge').Bridge; +const AppServiceRegistration = require("matrix-appservice-bridge").AppServiceRegistration; + +let bridge; + +//http.createServer((request, response) => { +// console.log('http online'); +//}).listen(appservicePort); + +new Cli({ + registrationPath: 'registration.yaml', + generateRegistration: (reg, callback) => { + reg.setId(AppServiceRegistration.generateToken()); + reg.setHomeserverToken(AppServiceRegistration.generateToken()); + reg.setAppServiceToken(AppServiceRegistration.generateToken()); + reg.setSenderLocalpart('_rss'); + reg.addRegexPattern('users', '@_rss_.*', true); + callback(reg); + }, + bridgeConfig: { + schema: 'config.schema.yaml' + }, + run: (port, config) => { + bridge = new Bridge({ + homeserverUrl: config.homeserver, + domain: config.domain, + registration: config.registration, + controller: { + onUserQuery: (queriedUser) => { + return {}; + }, + onEvent: (request, context) => { + return; + } + } + }); + bridge.run(port, config); + bridge.getIntent('@_rss_test0r:imninja.net').sendText(roomId, 'asef :)'); + } +}).run({port: 9000}); \ No newline at end of file