local cjson = require "cjson" counters = {} local handle = io.popen("cat counters.json") local json_text = handle:read("*a") handle:close() counters = cjson.decode(json_text) function on_msg_receive(msg) if(counters[msg.from.phone] == nil) then counters[msg.from.phone] = 1 else counters[msg.from.phone] = counters[msg.from.phone] + 1 local f = assert(io.open("counters.json", "w")) local t = f:write(cjson.encode(counters)) f:close() end end