examples
json
{"ID":"SendMessage", "chat_id_":1007779878, "reply_to_message_id_":0, "disable_notification_":0, "from_background_":0, "input_message_content_":{"ID":"InputMessageText", "text_":"Test text here", "disable_web_preview_":0, "clear_draft_":0, "entities_":[]}}
config
# This is an empty config file
# Feel free to put something here
default_profile = "binlog";
test_dc1 = {
config_directory = ".telegram-cli/test_dc1";
test = true;
msg_num = true;
log_level = 2;
logname = "log.txt";
verbosity = 100;
};
binlog = {
#config_directory = ".telegram-cli/binlog";
test = false;
msg_num = true;
lua_script = "script.lua";
log_level = 2;
logname = "log.txt";
verbosity = 100;
wait_dialog_list = true;
};
sample LUA script
function vardump(value, depth, key)
local linePrefix = ""
local spaces = ""
if key ~= nil then
linePrefix = "["..key.."] = "
end
if depth == nil then
depth = 0
else
depth = depth + 1
for i=1, depth do spaces = spaces .. " " end
end
if type(value) == 'table' then
mTable = getmetatable(value)
if mTable == nil then
print(spaces ..linePrefix.."(table) ")
else
print(spaces .."(metatable) ")
value = mTable
end
for tableKey, tableValue in pairs(value) do
vardump(tableValue, depth, tableKey)
end
elseif type(value) == 'function' or
type(value) == 'thread' or
type(value) == 'userdata' or
value == nil
then
print(spaces..tostring(value))
else
print(spaces..linePrefix.."("..type(value)..") "..tostring(value))
end
end
local lgi = require ('lgi')
local notify = lgi.require('Notify')
notify.init ("Telegram updates")
chats = {}
function do_notify (user, msg)
--local n = notify.Notification.new("message", "" .. user .. "
".. msg .. "")
local n = notify.Notification.new(user, msg)
n:show ()
end
function dl_cb (arg, data)
end
function tdcli_update_callback (data)
if (data.ID == "UpdateNewMessage") then
local msg = data.message_
local d = data.disable_notification_
local chat = chats[msg.chat_id_]
if ((not d) and chat) then
if msg.content_.ID == "MessageText" then
do_notify (chat.title_, msg.content_.text_)
else
do_notify (chat.title_, msg.content_.ID)
end
end
if msg.content_.ID == "MessageText" then
if msg.content_.text_ == "ping" then
tdcli_function ({ID="SendMessage", chat_id_=msg.chat_id_, reply_to_message_id_=msg.id_, disable_notification_=0, from_background_=1, reply_markup_=nil, input_message_content_={ID="InputMessageText", text_="pong", disable_web_page_preview_=1, clear_draft_=0, entities_={}}}, dl_cb, nil)
elseif msg.content_.text_ == "PING" then
tdcli_function ({ID="SendMessage", chat_id_=msg.chat_id_, reply_to_message_id_=msg.id_, disable_notification_=0, from_background_=1, reply_markup_=nil, input_message_content_={ID="InputMessageText", text_="pong", disable_web_page_preview_=1, clear_draft_=0, entities_={[0]={ID="MessageEntityBold", offset_=0, length_=4}}}}, dl_cb, nil)
end
end
elseif (data.ID == "UpdateChat") then
chat = data.chat_
chats[chat.id_] = chat
elseif (data.ID == "UpdateOption" and data.name_ == "my_id") then
tdcli_function ({ID="GetChats", offset_order_="9223372036854775807", offset_chat_id_=0, limit_=20}, dl_cb, nil)
end
end