-
Notifications
You must be signed in to change notification settings - Fork 3
/
notify.lua
75 lines (57 loc) · 1.66 KB
/
notify.lua
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
local l2dbus = require("l2dbus")
local l2dbus_ev = require("l2dbus_ev")
local dbt = l2dbus.DbusTypes
local mainLoop = l2dbus_ev.MainLoop.new()
local disp = l2dbus.Dispatcher.new(mainLoop)
assert(nil ~= disp)
local conn = l2dbus.Connection.openStandard(disp, l2dbus.Dbus.BUS_SESSION)
assert(nil ~= conn)
local icon_file = ""
our_id = 0
now = os.time()
function notify(summary, body)
local dbus_msg = l2dbus.Message.newMethodCall({destination="org.freedesktop.Notifications",
path="/org/freedesktop/Notifications",
interface="org.freedesktop.Notifications",
method="Notify"})
-- DBUS Notify signature is (STRING app_name, UINT32 replaces_id, STRING app_icon,
-- STRING summary, STRING body, ARRAY actions, DICT hints, INT32 expire_timeout)
dbus_msg:addArgs("Telegram", dbt.Uint32.new(0), icon_file,
summary, body,
dbt.Array.new({}, "as"),
dbt.Dictionary.new({}, "a{sv}"),
dbt.Int32.new(-1))
local reply, errName, errMsg = conn:sendWithReplyAndBlock(dbus_msg)
if reply == nil then
print("Request Failed => " .. tostring(errName) .. " : " .. tostring(errMsg))
end
end
print ("HI, this is lua script")
function on_msg_receive (msg)
if msg.date < now then
return
end
if msg.out then
return
end
if msg.text == nil then
return
end
if msg.unread == 0 then
return
end
notify("Message from " .. msg.from.print_name, msg.text)
end
function on_our_id (id)
our_id = id
end
function on_secret_chat_created (peer)
end
function on_user_update (user)
end
function on_chat_update (user)
end
function on_get_difference_end ()
end
function on_binlog_replay_end ()
end