From d1f58a02dc52b1d94dcdc751855eac34dfb92f84 Mon Sep 17 00:00:00 2001 From: annelin Date: Sat, 24 Aug 2019 14:19:15 +0300 Subject: [PATCH] Notification on errors while sending message Fixed Location messages Updated config example Updated README --- README.md | 25 +++++++++++++++---------- config.yml.example | 26 +++++++++++++------------- inc/telegramclient.rb | 4 ++-- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index b973ecb..02738d0 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,13 @@ Next, rename **config.yml.example** to **config.yml** and edit **xmpp** section ``` -xmpp: - db_path: 'users.db' +:xmpp: + db 'users.db' jid: 'tlgrm.localhost' host: 'localhost' port: 8888 secret: 'secret' - loglevel: 0 + loglevel: :warn ``` ### Configuration ### @@ -45,9 +45,12 @@ xmpp: 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: - api_id: '845316' # telegram API ID (my.telegram.org) # - api_hash: '27fe5224bc822bf3a45e015b4f9dfdb7' # telegram API HASH (my.telegram.org) # +:telegram: + :tdlib: + :lib_path: 'lib/' + :client: + :api_id: '845316' # telegram API ID (my.telegram.org) # + :api_hash: '27fe5224bc822bf3a45e015b4f9dfdb7' # telegram API HASH (my.telegram.org) # ... ``` @@ -66,10 +69,10 @@ server { } ``` -You need to set `content_path` and `content_link` in **config.yml**. +You need to set `:content: → :path: and :link:` **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`) +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 ### @@ -93,7 +96,7 @@ modules: 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; @@ -115,3 +118,5 @@ server { } ``` + +Finally, update `:upload:` in your config.yml to match `server_name` in nginx config. diff --git a/config.yml.example b/config.yml.example index cd8ed62..d614547 100644 --- a/config.yml.example +++ b/config.yml.example @@ -1,23 +1,23 @@ :telegram: - :lib_path: 'lib/' - :verbosity: 1 :loglevel: :warn - :client: - :api_id: '17349' - :api_hash: '344583e45741c457fe1862106095a5eb' - :device_model: 'zhabogram' - :application_version: '2.0' - :use_chat_info_database: false :content: - :path: '/var/www/zhabogram/media' # webserver workdir - :link: 'http://localhost/zhabogram/media' # webserver public address - :upload: 'https://localhost/upload' # xmpp http upload address + :path: '/var/www/zhabogram/content' # webserver workdir + :link: 'http://tlgrm.localhost/content' # webserver public address + :upload: 'https:///xmppfiles.localhost' # xmpp http upload address + :tdlib_verbosity: 1 + :tdlib: + :lib_path: 'lib/' + :client: + :api_id: '17349' + :api_hash: '344583e45741c457fe1862106095a5eb' + :device_model: 'zhabogram' + :application_version: '2.0' + :use_chat_info_database: false :xmpp: - :debug: false :loglevel: :warn + :jid: 'tlgrm.localhost' :host: '127.0.0.1' :port: 8899 - :jid: 'tlgrm.localhost' :password: 'password' :db: 'sessions.dat' diff --git a/inc/telegramclient.rb b/inc/telegramclient.rb index 267980b..d9d0d31 100644 --- a/inc/telegramclient.rb +++ b/inc/telegramclient.rb @@ -126,7 +126,7 @@ class TelegramClient when TD::Types::MessageContent::ChatDeleteMember then "kicked %s" % self.format_contact(update.message.content.user_id) when TD::Types::MessageContent::PinMessage then "pinned message: %s" % self.format_message(update.message.chat_id, content.message_id) when TD::Types::MessageContent::ChatChangeTitle then "chat title set to: %s" % update.message.content.title - when TD::Types::MessageContent::Location then "coordinates: %s | https://www.google.com/maps/search/%s,%s/" % [content.location.latitude, content.location.longitude] + when TD::Types::MessageContent::Location then "coordinates: %{latitude},%{longitude} | https://www.google.com/maps/search/%{latitude},%{longitude}/" % content.location.to_h when TD::Types::MessageContent::Photo, TD::Types::MessageContent::Audio, TD::Types::MessageContent::Video, TD::Types::MessageContent::Document then content.caption.text when TD::Types::MessageContent::Text then content.text.text when TD::Types::MessageContent::VoiceNote then content.caption.text @@ -241,7 +241,7 @@ class TelegramClient text = TD::Types::FormattedText.new(text: (reply or file) ? text.lines[1..-1].join : text, entities: []) # remove first line from text message = TD::Types::InputMessageContent::Text.new(text: text, disable_web_page_preview: false, clear_draft: false) # compile our message document = TD::Types::InputMessageContent::Document.new(document: file, caption: text) if file # we can try to send a document - message_id ? @telegram.edit_message_text(chat_id, message_id, message) : @telegram.send_message(chat_id, document || message, reply_to_message_id: reply || 0).rescue{@telegram.send_message(chat_id, message, 0)} + message_id ? @telegram.edit_message_text(chat_id, message_id, message) : @telegram.send_message(chat_id,document||message, reply_to_message_id: reply||0).rescue{|why| @xmpp.send_message(@jid, chat_id,"Message not sent: %s" % why)} end ## /commands (some telegram actions)