diff --git a/chatbot/README.md b/chatbot/README.md index c9008ca11..38c11c18e 100644 --- a/chatbot/README.md +++ b/chatbot/README.md @@ -14,26 +14,32 @@ python -m grpc_tools.protoc -I../pbx --python_out=. --grpc_python_out=. ../pbx/m ### Using Docker -1. Follow [instructions](../docker/README.md) to build and run dockerized Tinode chat server up to an including step 3. +1. Follow [instructions](../docker/README.md) to build and run dockerized Tinode chat server up to an including _step 4_. -2. In step 4 add the following parameter to the command line `--vol botdata:/botdata`. It will create and mount a volume `botdata` where Tino's (chatbot's) credentials are stored. +2. In the _step 5_ add the following parameter to the command line: `--volume botdata:/botdata`. It will create and mount a volume `botdata` where Tino's (chatbot's) credentials are stored. + ``` + docker run --rm --name tinode-init-db --network tinode-net --volume botdata:/botdata tinode-init-db + ``` -3. Run Tinode server with the following command: +3. In the _step 6_ add the following parameter to the command line: `--env PLUGIN_PYTHON_CHAT_BOT_ENABLED=true`. For instance, for MySQL the buld command will like like this: ``` - $ docker run -p 6060:18080 -d --name tinode-srv --network tinode-net --env PLUGIN_PYTHON_CHAT_BOT_ENABLED=true tinode-srv + $ docker build --tag=tinode-srv --build-arg TARGET_DB=mysql tinode-server ``` -4. If this folder is `chat/chatbot`, then the Dockerfile is located in `chat/docker/chatbot` folder; `cd ../docker` and build the chat bot image +4. Run the Tinode server according to _step 7_. + + +5. If this folder is `chat/chatbot`, then the Dockerfile is located in `chat/docker/chatbot` folder; `cd ../docker` and build the chat bot image ``` $ docker build --tag=tinode-bot chatbot ``` -5. Run the chatbot +6. Run the chatbot ``` - $ docker run -d --name tinode-bot --network tinode-net --vol botdata:/botdata tinode-bot + $ docker run -d --name tinode-bot --network tinode-net --volume botdata:/botdata tinode-bot ``` -6. Test that the bot is functional by pointing your browser to [http://localhost:6060/x/](http://localhost:6060/x/), login and talk to user `Tino`. The user should respond to every message with a random quote. +7. Test that the bot is functional by pointing your browser to [http://localhost:6060/x/](http://localhost:6060/x/), login and talk to user `Tino`. The user should respond to every message with a random quote. ### Building from Source @@ -58,7 +64,7 @@ nohup python chatbot.py --login-basic=alice:alice123 & ``` Run `python chatbot.py -h` for more options. -If you are using python 2.7, keep in mind that `condition.wait()` [is buggy](https://bugs.python.org/issue8844). It ignores SIGINT. As a consequence of this bug the bot cannot be terminated with a SIGINT. It has to be stopped with a SIGKILL. +If you are using python 2.7, keep in mind that `condition.wait()` [is forever buggy](https://bugs.python.org/issue8844). As a consequence of this bug the bot cannot be terminated with a SIGINT. It has to be stopped with a SIGKILL. You can use cookie file to store credentials. Sample cookie files are provided as `basic-cookie.sample` and `token-cookie.sample`. Once authenticated the bot will attempt to store the token in the cookie file, `.tn-cookie` by default. If you have a cookie file with the default name, you can run the bot with no parameters: ``` diff --git a/docker/README.md b/docker/README.md index 795ce27a1..9dc4c8a9d 100644 --- a/docker/README.md +++ b/docker/README.md @@ -62,6 +62,10 @@ 8. Test the installation by pointing your browser to [http://localhost:6060/x/](http://localhost:6060/x/). +## Optional + +### Resetting the data + If you want to reset the data in the database, shut down the server container ``` $ docker stop tinode-srv @@ -70,3 +74,8 @@ then repeat step 5 then restart the server ``` $ docker start tinode-srv ``` + +### Running the chatbot + +See [instructions](../chatbot/). + diff --git a/docker/init-db/Dockerfile b/docker/init-db/Dockerfile index 3771e974f..9dd051a6f 100644 --- a/docker/init-db/Dockerfile +++ b/docker/init-db/Dockerfile @@ -23,10 +23,9 @@ RUN go get -tags $TARGET_DB github.com/tinode/chat/tinode-db \ COPY config.template / COPY entrypoint.sh / -COPY credentials.sh / RUN chmod +x /entrypoint.sh -RUN chmod +x /credentials.sh +RUN chmod +x /go/src/github.com/tinode/chat/tinode-db/credentials.sh RUN mkdir /botdata diff --git a/docker/init-db/entrypoint.sh b/docker/init-db/entrypoint.sh index 90935b32e..12be03d93 100644 --- a/docker/init-db/entrypoint.sh +++ b/docker/init-db/entrypoint.sh @@ -17,5 +17,5 @@ done < /config.template /go/bin/tinode-db --reset --config=/config --data=/go/src/github.com/tinode/chat/tinode-db/data.json | grep "usr;tino;" > /botdata/tino-password # Convert Tino's authentication credentials into a cookie file. -/credentials.sh < /botdata/tino-password > /botdata/.tn-cookie +/go/src/github.com/tinode/chat/tinode-db/credentials.sh < /botdata/tino-password > /botdata/.tn-cookie