Jabber transport to Telegram network
This repository has been archived on 2024-05-28. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
annelin 3fe34d6c1a Release 0.8.1
[UPD] renamed config param xmpp:secret to xmpp:password according to ejabberd config name
[UPD] updated README.md and config example
2019-04-16 09:22:59 +03:00
inc Release 0.8.1 2019-04-16 09:22:59 +03:00
lib Added libtdjson build for Debian Stretch x64 2019-04-07 22:19:20 +03:00
config.yml.example Release 0.8.1 2019-04-16 09:22:59 +03:00
LICENSE Added README.md & license 2019-04-16 07:53:31 +03:00
README.md Release 0.8.1 2019-04-16 09:22:59 +03:00
zhabogram.rb Release 0.4 2019-04-13 17:42:56 +03:00

Dependencies

  • Ruby >= 1.9
  • ruby-sqlite3 >= 1.3
  • xmpp4r == 0.5.6
  • tdlib-ruby == 2.0 with pre-compiled libtdjson.so

(there is pre-compiled libtdjson.so for Debian Stretch x64 in repository)

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, move config.yml.example to and config.yml and edit xmpp section to match component listener:

xmpp:
	db_path: 'users.db'  
	jid: 'tlgrm.localhost'  
	host: 'localhost'  
	port: 8888  
	secret: 'secret'  
	loglevel: 0   

Configuration

Feel free to edit config.yml, options are commented and with clear names. It is good idea to obtain Telegram API ID from my.telegram.org to remove demo key requests limit.

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 content_link in config.yml.

Set content_path according to location (for our example it will be /var/zhabogram/content).
Set content_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 do not allowing URLs with non-default 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;
        }	

}