This is a Telegram bot server which provides some basic message statistics and analysis functions.
It interacts with users in a command-line-like way. Messages starting with '/' or '>' are considered as command.
For example, if you haven't viewed a chat for long time and found there're 1000 unread messages, probably you just want to get a summary instead of viewing the messages one by one. Now you can try the 'keyword' command. Send:
>keyword -n 1000You will get a response like the following:
Keywords of latest 1000 messages
------
11/16 03:34 EST /goto__m_292331
food, restaurant, steak, burger, beef, chicken, sauce, fish,
------
11/19 19:42 EST /goto__m_295920
code, java, c++, python, programming, bug, test, release, build,
------
...
Note: It has NOT been optimized for high QPS, but works well for limited number of chats which is configurable through a chat id whitelist in the config file.
Main commands:
- rank
Computes a rank based on the number of messages of the given type each user sent. - history
Outputs the history of chat titles and commands. - keyword
Computes the keywords of messages in the given time range. - network
Outputs an image to show the reply relationships between users. - goto
Outputs a message which replies to the message you want to go to. - chat
Chat with the bot.
-
Clone and import this project to your machine.
-
Set up database:
This project uses MySQL database.
Please install MySQL and create a database for the bot.
To make it compatible with emoji, please set char set and collation to utf8mb4.
Fill the database URL, username and password to config.ini.
If you don't want to use MySQL, you can create a new class which implements DatabaseInterface and replace MySQLDatabase. -
Set up NLP server:
This project has dependency on NLPUtil (client) which is used for 'keyword' command.
Build the library and import it to this project, as well as set up NLPUtil server (see the README of NLPUtil).
Fill the NLPUtil server host and port to config.ini.
If you don't want to use this library, you can create a new class which implements NLPInterface and replace NLPUtilClientWrapper.
If you don't want to enable 'keyword' command at all, simply remove the corresponding register statement from code. -
Set up Graphviz:
This project has dependency on Graphviz which is used for generating images for 'network' command.
Please install Graphviz and fill the binary path to config.ini.
If you don't want to use this library, you can create a new class which implements GraphVisualizationInterface and replace Graphviz.
If you don't want to enable 'network' command at all, simply remove the corresponding register statement from code. -
Set up Turing Robot:
This project has dependency on Turing Robot which is used as chat bot API for 'chat' command.
Please register Turing Robot and fill the API key to config.ini.
If you don't want to use Turing Robot API, you can create a new class which implements ChatBotInterface and replace TuringRobot.
If you don't want to enable 'chat' command at all, simply remove the corresponding register statement from code. -
Build the bot as runnable jar.
-
Create a new telegram bot (see the instructions here) and fill the bot name and token to config.ini.
-
Fill the numeric ids of the chats you want to serve into ChatWhiteList field in config.ini.
-
Fill the rest of fields in config.ini.
-
Start the bot server.
-
Set up WordCounter which computes word frequency for 'keyword' function. Schedule it to run once per month.
Send:
>helpIt will show you help information.