Skip to content

Commit

Permalink
login & logout command
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Mar 2, 2020
1 parent 0a4d49d commit 797d404
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
19 changes: 14 additions & 5 deletions README.md
Expand Up @@ -65,28 +65,37 @@ Copy [config/config.sample.yaml](https://github.com/chatie/matrix-appservice-wec
After we setup the `config.yaml`, then we can generate the `wechaty-registration.yaml` file for registing to the home server:

```sh
export APP_SERVER_ENDPOINT='http://localhost:8788'
export APP_SERVICE_ENDPOINT='http://localhost:8788'

matrix-appservice-wechaty \
--config config.yaml \
--url "$APP_SERVER_ENDPOINT" \
--url "$APP_SERVICE_ENDPOINT" \
--generate-registration
```

Note: The URL `APP_SERVER_ENDPIOINT` is used by the home server to communite with appservice, in this example is: `http://localhost:8788`. If you have other appservices, or other requirements, pick an appropriate hostname and port.
Note: The URL `APP_SERVICE_ENDPIOINT` is used by the home server to communite with appservice, in this example is: `http://localhost:8788`. If you have other appservices, or other requirements, pick an appropriate hostname and port.

### 3 Register the App Service

Edit your `homeserver.yaml` file and update the `app_service_config_files` entry with the path to the `wechaty-registration.yaml` file.

```json
app_service_config_files: ["wechaty-registration.yaml"]
app_service_config_files: ["/data/wechaty-registration.yaml"]
```

### 4 Restart Home Server (Synapse)

You will then need to restart the synapse server.

For docker users:

```sh
export SYNAPSE_CONTAINER_ID=$(docker ps | grep synapse | awk '{print $1}')
docker restart $SYNAPSE_CONTAINER_ID
```

Or if you are not using docker:

```sh
synctl restart
```
Expand Down Expand Up @@ -261,7 +270,7 @@ Distill steps to setup the matrix server from <https://github.com/spantaleev/mat
### v0.8 Mar 1, 2020

1. Code Refactoring
1. Add `!logout` command
1. Add `!login`, `!logout` command with help message
1. Tested with iPad API([wechaty-puppet-padplus](https://github.com/wechaty/wechaty-puppet-padplus))

### v0.6 (Beta) Feb 25, 2020
Expand Down
4 changes: 2 additions & 2 deletions scripts/appservice-generate.sh
Expand Up @@ -2,9 +2,9 @@

set -eo pipefail

source .env
source ../.env

ts-node ../bin/matrix-appservice-wechaty \
--config config.yaml \
--generate-registration \
--url "$APP_SERVER_ENDPOINT"
--url "$APP_SERVICE_ENDPOINT"
7 changes: 4 additions & 3 deletions scripts/appservice-launch.sh
Expand Up @@ -2,11 +2,12 @@

set -eo pipefail

source .env
source ../.env

export WECHATY_LOG=silly
export WECHATY_PUPPET=wechaty-puppet-padplus
# export WECHATY_PUPPET=wechaty-puppet-padplus
# export WECHATY_PUPPET_PADPLUS_TOKEN=xxxx

ts-node ../bin/matrix-appservice-wechaty \
--config config.yaml \
--file wechaty-registration.yaml
--file wechaty-registration.yaml
21 changes: 20 additions & 1 deletion src/dialog-manager.ts
Expand Up @@ -89,8 +89,18 @@ export class DialogManager extends Manager {
log.verbose('MatrixHandler', 'gotoSetupDialog() text: "%s"', text)

if (/^!logout$/i.test(text)) {

log.verbose('MatrixHandler', 'gotoSetupDialog() !logout')
await wechaty.logout()
if (wechaty.logonoff()) {
await wechaty.logout()
}
await wechaty.stop()

await this.appserviceManager.sendMessage(
'logout success.',
superEvent.room(),
)

} else if (/^!login$/i.test(text)) {
log.verbose('MatrixHandler', 'gotoSetupDialog() !login')
await this.appserviceManager.sendMessage(
Expand All @@ -103,6 +113,15 @@ export class DialogManager extends Manager {
superEvent.room(),
)

} else {
const help = [
'Avaiable commands: !login, !logout',
].join('')

await this.appserviceManager.sendMessage(
help,
superEvent.room(),
)
}
}

Expand Down

0 comments on commit 797d404

Please sign in to comment.