Giter VIP home page Giter VIP logo

zhabogram's Introduction

Unofficial Mirror (latest pull 2020-11-01)

From: https://dev.narayana.im/narayana/zhabogram (All PRs and issues need to be added there)

Dependencies

  • Ruby >= 2.4
  • xmpp4r == 0.5.6
  • tdlib-ruby == 2.2 with pre-compiled libtdjson.so (1.6)

There is pre-compiled libtdjson.so for Debian Stretch x64 in repository.
For any other distro you need to manually compile tdlib and place libtdjson.so to relative lib/ directory (or LD_LIBRARY_PATH).

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 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.

zhabogram's People

Contributors

povoq avatar snoopcatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

zhabogram's Issues

Не могу настроить zhabogram

Уже несколько дней не могу запустить этот транспорт. xmpp сервер использую ejabberd он поднят в docker контейнере. Для zhabogram тоже сделал отдельный контейнер. Собственно соединение с xmpp сервером есть, но насколько я понимаю дальше ничего не происходит.

Я не знаю ruby, но пытаясь разобраться я нашёл что telegramclient не стартует т.к. массив (может не массив, сорри) db[:sessions] пуст. Может быть дело и не в этом, помогите разобраться.


class XMPPComponent

    ##  initialize zhabogram 
    def initialize(**config)
       # ...
        @db = YAML::Store.new(config[:db])
        @db.transaction do @db[:sessions] ||= {} end  
    end

    ##  connect to XMPP server 
    def connect() 
        begin
           # ...
           # Вот тут не происходитт итерация по @db[:sessions] - т.к. там пусто
            @db.transaction do  @db[:sessions].each do |jid, session| @sessions[jid] = TelegramClient.new(self, jid, session) end end # probe all known sessions
         #  ...
        end
    end

Когда я запускаю Zhabogram в логах видно вот это:

ejabberd log:

ejabberd_1  | 2020-04-10 05:46:21.953123+00:00 [info] (<0.870.0>) Accepted connection [::ffff:192.168.0.1]:45570 -> [::ffff:192.168.0.3]:8899
ejabberd_1  | 2020-04-10 05:46:21.958909+00:00 [info] (tcp|<0.870.0>) Accepted external component handshake authentication for telegram from ::ffff:192.168.0.1

zhabogram log:

telegram_1  | [dry-types] Dry::Types.module is deprecated and will be removed in the next major version
telegram_1  | Use Dry.Types() instead. Beware, it exports strict types by default, for old behavior use Dry.Types(default: :nominal). See more options in the changelog
telegram_1  | /zhabogram/zhabogram.rb:9:in `<main>'
telegram_1  | W, [2020-04-10T05:45:23.016811 #1]  WARN -- XMPPComponent: Connected to XMPP server

zhabogram config.yaml:

:telegram:
  :loglevel: :warn
  :content:
    :path: '/usr/docker/xmpp/ejabberd_files/upload/' # webserver workdir 
    :link: 'https://my_server.com:5443/upload' # webserver public address
    :upload: 'https://127.0.0.1:5443/upload' # xmpp http upload address
  :tdlib_verbosity: 1
  :tdlib:
    :lib_path: '/td-1.6.0/build/'
    :client:
      :api_id: 'my_app_id'
      :api_hash: 'my_api_hash'
      :device_model: 'zhabogram'
      :application_version: '2.0'
      :use_chat_info_database: false

:xmpp:
  :loglevel: :warn
  :jid: 'telegram'
  :host: 'my_server.com'
  :port: 8899
  :password: 'secret'
  :db: 'sessions.dat'

ejabberd.yaml

listen:
  -
    port: 8899
    module: ejabberd_service
    access:  all
    shaper_rule: fast
    ip: "::"
    #service_check_from: false
    hosts:
      "telegram":
        password: "secret"

Dockerfile for zhabogram:

FROM alpine:3.11
RUN apk update --quiet

RUN apk upgrade --update && apk add --quiet curl autoconf dpkg-dev dpkg file g++ gcc libc-dev make pkgconf libressl cmake gperf zlib-dev libressl-dev linux-headers readline-dev alpine-sdk linux-headers git zlib-dev openssl-dev gperf php php-ctype cmake && rm -rf /var/cache/apk/*

RUN curl -sSL https://github.com/tdlib/td/archive/v1.6.0.tar.gz | tar xz

RUN mkdir /td-1.6.0/build

WORKDIR /td-1.6.0/build

RUN cmake -DCMAKE_BUILD_TYPE=Release ..

RUN cmake --build .
RUN make install

RUN apk add --quiet ruby ruby-dev ruby-bigdecimal ruby-etc ruby-irb ruby-io-console
RUN gem install rdoc
RUN gem install rake
RUN gem install tdlib-ruby
RUN gem install json

WORKDIR /
RUN gem install xmpp4r

#RUN curl -sSL https://dev.narayana.im/narayana/zhabogram/archive/v2.2.8.tar.gz | tar xz
RUN git clone https://git.narayana.im/narayana/zhabogram.git
WORKDIR /zhabogram
RUN git checkout master

VOLUME /zhabogram/config.yml

CMD ruby /zhabogram/zhabogram.rb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.