--incom_tgmessage
local json = require('cjson')
local cURL = require "cURL"


function callback(extra, success, result)
 if success then
    print('File downloaded to:', result)
  else
    print('Error downloading: '..extra)
  end
end

function on_msg_receive (msg)
    if msg.out then
        return
    end
    if (msg.text=='ping') then
        send_msg (msg.from.print_name, 'pong', ok_cb, false)
    end
		if msg.media then
			if msg.media.type == 'photo' then
				print('Loading photo'..msg.id.."\n")

				local loadans = load_photo(msg.id,callback,msg.id)

				print('Receiving Photo:[')
				print(loadans)
				print(']')
				
				--postpone (cb_function, cb_extra, 100);
			end
		end 
		--[[
        mtb = json.encode(msg)
        cURL.easy()
        :setopt_url('http://127.0.0.1:8888/bitrix/tools/alovoice/receiver.php')
        :setopt_writefunction(io.write)
        :setopt_httppost(cURL.form() -- Lua-cURL guarantee that form will be alive
			:add_content('tgevent', 'incom_tgmessage', text_plain)
			:add_content('datas', mtb, "text/plain")
        )
        :perform()
        :close()
		]]--
--    :add_buffer("test_file", "filename", "text data", "text/plain", {
--      "Description: my file description"
--    })
--    :add_file("test_file2", "BuildLog.htm", "application/octet-stream", {
--      "Description: my file description"
--    })
    --os.execute("/usr/bin/php /home/kulya/inc.php msg " .. mtb)
    --os.execute("/usr/bin/php /home/kulya/inc.php msg " .. msg.from.print_name )
    --os.execute("/usr/bin/php /home/kulya/upd.php msg " .. mtb )
end

function on_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
