Skip to content

Instantly share code, notes, and snippets.

@khapota
Last active March 9, 2016 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khapota/da99dd964cef7e82fc82 to your computer and use it in GitHub Desktop.
Save khapota/da99dd964cef7e82fc82 to your computer and use it in GitHub Desktop.
Telegram CLI (tg) mac os notify script
import tgl
import os
# This is a python script that run with tg and notify when get new message
# Using terminal-notifier https://github.com/julienXX/terminal-notifier
# The notifier function
def notify(title, subtitle, message):
t = '-title "%s"' % title
s = '-subtitle "%s"' % subtitle
m = '-message "%s"' % message
sender = '-sender ru.keepcoder.Telegram'
o = ''
if message.find("http") == 0:
firstSpace = message.find(" ")
url = message
if firstSpace != -1:
url = message[:firstSpace+1]
o = '-open "%s"' % url
sender = ''
end = ' > /dev/null 2>&1'
os.system('terminal-notifier -group Telegram {}'.format(' '.join([m, t, s, o, sender, end])))
# Calling the function
def on_msg_receive(msg):
title = "Telegram %s" % msg.dest.name.encode('utf-8')
subtitle = msg.src.name.encode('utf-8')
try:
message = msg.text.encode('utf-8')
except:
message = None
if not msg.out and message != None:
notify(title, subtitle, message)
# Finish replaying bin log
def on_binlog_replay_end():
tgl.set_on_get_difference_end(on_get_difference_end)
def on_chat_update(peer, changed):
pass
# After get old message
def on_get_difference_end():
print("done differ")
tgl.set_on_msg_receive(on_msg_receive)
tgl.set_on_chat_update(on_chat_update)
tgl.set_on_binlog_replay_end(on_binlog_replay_end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment