Browse Source

Notification on errors while sending message

Fixed Location messages
Updated config example
Updated README
master
annelin 2 months ago
parent
commit
d1f58a02dc
3 changed files with 30 additions and 25 deletions
  1. 15
    10
      README.md
  2. 13
    13
      config.yml.example
  3. 2
    2
      inc/telegramclient.rb

+ 15
- 10
README.md View File

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

+ 13
- 13
config.yml.example View File

@@ -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'

+ 2
- 2
inc/telegramclient.rb 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::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)

Loading…
Cancel
Save