~libqtelegram-team/telegram-app/telegram-app-dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python3

import json
import sys

f1, f2 = sys.argv[1:3]
infile = open(f1)
outfile = open(f2, "w")

json_data = infile.read()
data = json.loads(json_data)

message = data['message']

key = message['loc_key'] if 'loc_key' in message else ''
#args = message['loc_args']
custom = message['custom']
#isChat = 'loc_key' in message and message['loc_key'] == 'CHAT_MESSAGE_TEXT'
chatId = str(custom['from_id']) if 'from_id' in custom else '0'
chatId = str(custom['chat_id']) if 'chat_id' in custom else chatId
uri = 'telegram://chat/{0}'.format(chatId)

oldCard = data['notification']['card']

card = dict()
card['summary'] = oldCard['summary'] if 'summary' in oldCard else ''
if len(card['summary']) == 0:
    card['summary'] = 'Telegram'
card['body'] = oldCard['body'] if 'body' in oldCard else ''
if key == 'ENCRYPTION_REQUEST':
    card['body'] = 'New secret chat'
card['actions'] = [ uri ]
card['popup'] = True
card['persist'] = True

emblem = dict()
emblem['count'] = data['notification']['emblem-counter']['count']
emblem['visible'] = True if int(emblem['count']) > 0 else False

notification = dict()
notification['tag'] = chatId
notification['card'] = card
notification['emblem-counter'] = emblem
notification['sound'] = True
notification['vibrate'] = True

output = dict()
output['notification'] = notification

open(f2, "w").write(json.dumps(output))