aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: cb8091454d24b75c46e0454cc6cdc36c1f46dd1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
## Telegabber: like Zhabogram, but in Go! ##

Now it's native, more asynchronous, and does not require to mess your server up with a monstrous third-party interpreter.

The configuration file is compatible with Zhabogram 2.0, so you can easily copy your existing `config.yml`.

### Build ###

Prerequisites: Go links the binary against the `glibc` version present in the system where the build process happens, so it should be less or equal to the version of `glibc` in the system where Telegabber will run.

* Build TDLib according to [TDLib build instructions](https://tdlib.github.io/td/build.html). The 1.5.0 version is needed currently; for switching to it, run this after `cd td`:
```
git fetch --all --tags --prune
git checkout tags/v1.5.0
```
* Install Go (tested with 1.13, but may work with earlier versions too).
* Open the source dir in a new shell (to make sure that `$GOPATH` works) and run `make`. Dependencies will be installed automatically.

After a successful build, you get a single binary to deploy on your server.

In the deploy directory, you need only three files:
* `telegabber` (the binary)
* `config.yml`
* `config_schema.json` (copy it from the repo)

### Installation ###

First of all, you need to create component listener on your Jabber server. 
For example, for ejabberd in **/etc/ejabberd/ejabberd.yml**:

```
listen:  
  -  
    port: 8888  
    module: ejabberd_service  
    access: all  
    shaper_rule: fast  
    ip: "127.0.0.1"  
    service_check_from: false  
    hosts:  
        "tlgrm.localhost":  
            password: "secret"
```


Next, rename **config.yml.example** to **config.yml** and edit **xmpp** section to match your component listener:


```
:xmpp:
	db 'users.db'  
	jid: 'tlgrm.localhost'  
	host: 'localhost'  
	port: 8888  
	secret: 'secret'  
	loglevel: :warn   
```

### Configuration ###

It is good idea to obtain Telegram API ID from [**https://my.telegram.org**](https://my.telegram.org) to remove demo key requests limit, and then edit in **config.yml**:

```
:telegram:
    :tdlib:
        :lib_path: 'lib/'
        :client:
            :api_id: '845316' # telegram API ID (my.telegram.org) #
            :api_hash: '27fe5224bc822bf3a45e015b4f9dfdb7' # telegram API HASH (my.telegram.org) #
    ...
```

### How to receive files from Telegram ###

First of all, you need to set up web server that will serve some directory in your filesystem.
Example nginx config: 

```
server {
	listen 80;
	server_name tlgrm.localhost;
	location /content {
		alias /var/zhabogram;
	}
}
```

You need to set `:content: → :path: and :link:` **config.yml**.  
  
Set `:path:` according to location (for our example it will be `/var/zhabogram/content`).  
Set `:link:` according to server_name (for our example it will be `http://tlgrm.localhost`)  


### How to send files to Telegram chats ###

You need to setup `mod_http_upload` for your XMPP server.  
For example, for ejabberd in **/etc/ejabberd/ejabberd.yml**

```
modules:
  mod_http_upload:
    docroot: "/var/ejabberd/upload" # this must be a valid path, user ownership and SELinux flags must be set accordingly
    put_url: "https://xmpp.localhost:5443/upload/@HOST@"
    get_url: "https://xmppfiles.localhost/upload/@HOST@"
    access: local
    max_size: 500000000 #500 MByte
    thumbnail: false
    file_mode: "0644"
    dir_mode: "0744"
```

Then you need to setup nginx proxy that will serve `get_url` path, because Telegram will not handle URLs with non-default http(s) ports.  
Example nginx config:  

/```
server {
	listen 80;
	listen 443 ssl;

	server_name xmppfiles.localhost;

        # SSL settigns #
        keepalive_timeout   60;
        ssl_certificate      /etc/ssl/domain.crt;
        ssl_certificate_key  /etc/ssl/domain.key;
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers  "RC4:HIGH:!aNULL:!MD5:!kEDH";
        add_header Strict-Transport-Security 'max-age=604800';

        location / {
            proxy_pass https://xmpp.localhost:5443;
        }	

}

```

Finally, update `:upload:` in your config.yml to match `server_name` in nginx config.