forked from wrxck/telegram-bot-lua
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.lua
53 lines (46 loc) · 1.14 KB
/
example.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
#!/usr/bin/env tarantool
--[[
This example will echo messages back to the user who sent them, with an inline keyboard
which tells the user the JSON for the callback_query.from object.
]]
local log = require('log')
local api = require('telegram-bot')
local json = require('json')
if not arg[1] then
log.error('Usage: %s TOKEN', arg[0])
log.error('You can get one from @BotFather')
os.exit(1)
end
local ok, err = api.configure(arg[1])
if not ok then
log.error('%s', err)
os.exit(1)
end
function api.on_update(update)
log.info('< %s', json.encode(update))
end
function api.on_message(message)
if message.text then
api.send_message(
message,
message.text,
nil,
true,
false,
nil,
api.inline_keyboard():row(
api.row():callback_data_button(
'Button',
'callback_data'
)
)
)
end
end
function api.on_callback_query(callback_query)
api.answer_callback_query(
callback_query.id,
json.encode(callback_query.from)
)
end
api.run()