A simple bot for Telegram that reproduces the Markov Chain. You can chat with him and he will respond based on your text. It is not a perfect interlocutor yet, but from time to time he can give you adequate answer.
Expected that all above software available as a global in terminal.
Node.js available as a node
, Python available as a python3
.
If you want to host this server somewhere, then you need install additional software. See your host installation guide.
This app is not intended for production! This app is only for demonstrating the approach.
All subsequent guidelines is about Unix systems (particular is about Linux). You may need make some changes on your own if you work on Windows.
- Clone this repository.
git clone https://github.com/Amaimersion/Markov-Chain-Telegram-Bot.git
cd Markov-Chain-Telegram-Bot
git submodule update --init
- Install packages and build.
yarn
- Create pre-generated Markov Chain file and place that file in the
./src/markov-chain/generated-chains
directory. See this for details. Then open./src/markov-chain/main.py
and change file path and window number.
~20: chain.chain = extensions.file.json.read("<file path>")
~29: start_text = handle_input_text(start_text, <window number>)
Current main.py
developed for JSON base. If you want to use another format, then you should make changes for this. See this for details.
- Choose a way from these two how you want to use this server:
-
Create
.env
file and fill out it. See.env.example
for example. -
Make sure your deployed server is running. If not, then you can do that with that command (you should type in the deployed server console, not local)
yarn run start
curl --data "url=<your server url>" https://api.telegram.org/bot<your bot token>/setWebhook
Russians users may need a proxy
curl --data "url=<your server url>" --proxy <[protocol://][user:password@][proxyhost][:port]> https://api.telegram.org/bot<your bot token>/setWebhook
Make sure you specify a right url. For example, in current server configuration Telegram requests can be handled on /telegram
url. So, you should specify something like this --data "url=https://example.com/telegram".
- And now you can chat with your own friend!
- Start the server in development mode
yarn run watch-server
-
Open another terminal and
cd
in the server directory. -
Give the permission
chmod +x ./tests/shell/test-message.sh
- Send request to local server
./tests/shell/test-message.sh
- In the first terminal you can see the generated message. And now you can chat with ownself!
For example i pick Heroku. However, on another PaaS platforms this actions almost similar.
-
Install Heroku.
-
Make sure you in project directory. Create another branch
git checkout -b heroku
-
Create
.env
file if you didn't do that on the master branch. -
In the
.gitignore
removesrc/markov-chain/generated-chains/*
and.env
. This files is required. -
Upload files on Heroku
git push heroku heroku:master
Now doesn't support python3
out of the box.
In order to install native packages (non npm modules) in your deployment you need to use Docker. There you will be able to install both Node and Python 3 and run your application. - Sergio XalambrĂ, Support Engineer at ZEIT
Try to speak with the bot @MarkovChain_Bot. For now this bot speaks only on Russian.
MIT.