Skip to content

Commit

Permalink
Merge pull request #56 from tmmsartor/unix-socket
Browse files Browse the repository at this point in the history
Add option for unix-socket in config.yml
  • Loading branch information
tvdstaaij authored Dec 2, 2016
2 parents cc492bd + a8a902a commit de70e2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 9 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@

## Technical options ##

# Use a unix socket to communicate with telegram-cli
# Should match the path passed to telegram-cli with the -S option
#
# NB: Setting tg_sock to some not false value will cause the script
# to ignore the next options about TCP connection

# tg_sock: "/var/run/telegram.sock"
tg_sock: null

# Address of the machine you are running telegram-cli on
# If this is not localhost telegram-cli must be invoked with --accept-any-tcp
tg_host: 'localhost'
Expand Down
12 changes: 9 additions & 3 deletions telegram-history-dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@

def connect_socket
return if defined?($sock) && $sock
$log.info('Attaching to telegram-cli control socket at %s:%d' %
[$config['tg_host'], $config['tg_port']])
$sock = TCPSocket.open($config['tg_host'], $config['tg_port'])

if $config['tg_sock']
$log.info('Attaching to telegram-cli control socket at /var/run/telegram.sock')
$sock = UNIXSocket.new($config['tg_sock'])
else
$log.info('Attaching to telegram-cli control socket at %s:%d' %
[$config['tg_host'], $config['tg_port']])
$sock = TCPSocket.open($config['tg_host'], $config['tg_port'])
end
end

def disconnect_socket
Expand Down

0 comments on commit de70e2c

Please sign in to comment.