Notification on errors while sending message

Fixed Location messages
Updated config example
Updated README
This commit is contained in:
annelin 2019-08-24 14:19:15 +03:00
parent a34f10b78a
commit d1f58a02dc
3 changed files with 30 additions and 25 deletions

View file

@ -31,13 +31,13 @@ Next, rename **config.yml.example** to **config.yml** and edit **xmpp** section
``` ```
xmpp: :xmpp:
db_path: 'users.db' db 'users.db'
jid: 'tlgrm.localhost' jid: 'tlgrm.localhost'
host: 'localhost' host: 'localhost'
port: 8888 port: 8888
secret: 'secret' secret: 'secret'
loglevel: 0 loglevel: :warn
``` ```
### Configuration ### ### 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**: 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: :telegram:
api_id: '845316' # telegram API ID (my.telegram.org) # :tdlib:
api_hash: '27fe5224bc822bf3a45e015b4f9dfdb7' # telegram API HASH (my.telegram.org) # :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 `: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 `:link:` according to server_name (for our example it will be `http://tlgrm.localhost`)
### How to send files to Telegram chats ### ### 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. 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: Example nginx config:
``` /```
server { server {
listen 80; listen 80;
listen 443 ssl; listen 443 ssl;
@ -115,3 +118,5 @@ server {
} }
``` ```
Finally, update `:upload:` in your config.yml to match `server_name` in nginx config.

View file

@ -1,23 +1,23 @@
:telegram: :telegram:
:lib_path: 'lib/'
:verbosity: 1
:loglevel: :warn :loglevel: :warn
:client:
:api_id: '17349'
:api_hash: '344583e45741c457fe1862106095a5eb'
:device_model: 'zhabogram'
:application_version: '2.0'
:use_chat_info_database: false
:content: :content:
:path: '/var/www/zhabogram/media' # webserver workdir :path: '/var/www/zhabogram/content' # webserver workdir
:link: 'http://localhost/zhabogram/media' # webserver public address :link: 'http://tlgrm.localhost/content' # webserver public address
:upload: 'https://localhost/upload' # xmpp http upload 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: :xmpp:
:debug: false
:loglevel: :warn :loglevel: :warn
:jid: 'tlgrm.localhost'
:host: '127.0.0.1' :host: '127.0.0.1'
:port: 8899 :port: 8899
:jid: 'tlgrm.localhost'
:password: 'password' :password: 'password'
:db: 'sessions.dat' :db: 'sessions.dat'

View file

@ -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::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::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::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::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::Text then content.text.text
when TD::Types::MessageContent::VoiceNote then content.caption.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 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 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 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 end
## /commands (some telegram actions) ## /commands (some telegram actions)