# AutoResponder TG
### Setup
* `sudo apt update`
* [Installing node.js v14](https://computingforgeeks.com/install-node-js-14-on-ubuntu-debian-linux/ "Installing node.js v14")
* Installing git `sudo apt install git`
* Cloning project
`git clone git@github.com:impythonist/autoresponder_tg.git`
* [Installing docker](https://docs.docker.com/engine/install/ubuntu/ "Installing docker")
* Change your current directory to project dir example `cd /root/autoresponder_tg`
* After that you need to create image from current version of program
`docker build . -t autoresponder_tg`
* Now you need to setup your profile
First you should create api_id/api_hash, for that we visit site https://my.telegram.org/auth?to=apps next intuitively clear what to do.
Now in our project directory we will call our CLI
`node cli.js setup_account <profile_name>`, replace the <profile_name> with your new profile name (profile name should start with alphabet character).
Next step is authentication
`node cli.js auth <profile_name>`
* Now you need setup your configuration and triggers (all configuration in json).
Calling cli with these arguments will show you how to open config editor for profile
` node cli.js edit_config <profile_name>`
### Configuration
* About all triggers
Key `"usedTags"` is mapping of keys `"name"`, `"username"` with boolean arguments, Example if you using both tags in one of your reply messages you must give to keys `true` argument.
Key `"reply"` is array of reply messages which in turn are objects with these keys
`"type"` - it can be `"msg-text"`, `"msg-text-image"`, `"msg-text-video"`,
`"text"` - If you want to send text message pass text into these argument if not give to it empty string - `""`,
In text you can use tags `-username-` will replaces to current user username, `-name-` with user first name,
`"mediaPath"` - If you sending image or video you must set to this key URL from the internet.
`"sleep"` - give seconds to this key, will sleep N seconds before sending current reply message,
`"typingDelay"` - give seconds to this key, will show `Typing...` status N seconds before sending the message (be careful with this key, by default it shows 1 second),
**All messages in `"reply"` key will send consistently.1.**
* About welcome trigger
You need to pass to it `"welcome": true`, which means that trigger is for welcome messages,
Welcome trigger key is `"welcomeHandler"`.
Everything else is similar to the general conclusion about all triggers.
* About on reply to welcome message handler
Trigger key is `"welcomeOnReplyHandler"`, it is object.
Everything else is similar to the general conclusion about all triggers.
* About on unreplied welcome messages handler
Key is `"welcomeOnUnrepliedHandler"`, it is object.
`"waitForReply"` - give seconds to this key, will wait N seconds before sending message.
Everything else is similar to the general conclusion about all triggers.
* Other handlers
Key is `"handlers"`.
Is array of handler which is object.
Handlers can have a several types (`"type"`), `"includes"` - it means that received message must include some anchor text to be processed by a specific handler. `"full_match"` - it means that received message must be fully matched with one of anchor textes `"percental"` - it means that recieved message must mutch to one of anchor textes with determined percent to be processed by a specefic trigger. In percental triggers you must specify `"percentageMatch"` (it is number).
`"anchors"` it is array of trigger textes.
Example if you want to handle messages `test` and `test2` with full match you need to set handler `"type"` to `"full_match"` and `"anchors "` to `["test","test2"]`.
`"caseSensitive"` - it is boolean key.
Everything else is similar to the general conclusion about all triggers.
Example of configuration.
```
{
"welcomeHandler": {
"welcome": true,
"usedTags": {
"name": true,
"username": true
},
"reply": [
{
"type": "msg-text",
"text": "Hello -name- this is my test welcome reply.",
"sleep": 1
},
{
"type": "msg-text",
"text": "Hello -username- this is my test welcome reply 2.",
"sleep": 10
}
]
},
"welcomeOnReplyHandler": {
"usedTags": {
"name": true,
"username": true
},
"reply": [
{
"type": "msg-text",
"text": "Hello -name- this is my test welcome reply on your message.",
"sleep": 1
},
{
"type": "msg-text",
"text": "Hello -name- this is my test welcome reply on your message 2.",
"sleep": 1
}
]
},
"welcomeOnUnrepliedHandler": {
"usedTags": {
"name": true,
"username": true
},
"waitForReply": 20,
"reply": [
{
"type": "msg-text",
"text": "Hello -name- this is my test welcome reply waited.",
"sleep": 1,
"typingDelay": 1
},
{
"type": "msg-text",
"text": "Hello -name- this is my test welcome reply waited 2.",
"sleep": 1,
"typingDelay": 2
}
]
},
"handlers": [
{
"type": "includes",
"anchors": [
"test"
],
"caseSensitive": false,
"usedTags": {
"name": true,
"username": true
},
"reply": [
{
"type": "msg-text",
"text": "Hello -name- this is my test reply.",
"sleep": 1,
"typingDelay": 2
},
{
"type": "msg-text",
"text": "Hello @-username- this is my test reply 2."
},
{
"type": "msg-text-image",
"text": "Hello @-username- this is my test reply with image.",
"mediaPath": "https://lelolobi.com/wp-content/uploads/2021/11/Test-Logo-Small-Black-transparent-1-1.png"
},
{
"type": "msg-text-video",
"text": "Hello @-username- this is my test reply with video.",
"mediaPath": "https://www.learningcontainer.com/download/sample-mp4-video-file-download-for-testing/?wpdmdl=2727&refresh=62dcf803d15e91658648579"
}
]
},
{
"type": "full_match",
"anchors": [
"smss",
"lll"
],
"caseSensitive": false,
"usedTags": {
"name": true,
"username": true
},
"reply": [
{
"type": "msg-text",
"text": "-name- @-username- full match."
}
]
},
{
"type": "percental",
"anchors": [
"bbb"
],
"percentageMatch": 50,
"caseSensitive": false,
"usedTags": {
"name": true,
"username": true
},
"reply": [
{
"type": "msg-text",
"text": "-name- @-username- Percental match."
}
]
},
{
"type": "percental",
"anchors": [
"hello",
"hi"
],
"percentageMatch": 50,
"caseSensitive": false,
"usedTags": {
"name": true,
"username": true
},
"reply": [
{
"type": "msg-text",
"text": "Hello dear @-username-."
}
]
},
{
"type": "percental",
"anchors": ["how are you"],
"percentageMatch": 50,
"caseSensitive": false,
"usedTags": {
"name": true,
"username": true
},
"reply": [
{
"type": "msg-text",
"text": "Fine dear -name-, and you?"
}
]
}
]
}
```
### Setup media server for media files
* We need to install nginx server
`sudo apt install nginx`
* Create media folder on any place of your server, example `<mediaPath>`.
Replace all `<mediaPath>` s with your media path.
```
server {
listen 80;
location /media {
root <mediaPath>;
}
}
```
If you want to get media file from your you can go to this url.
`http://<serverIp>/media/<fileNameFromServer>.<fileExtensionFromServer>`.