Skip to content

Commit 3b9ed6a

Browse files
committed
Add webhook example
1 parent 0732418 commit 3b9ed6a

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ tnt-tg-bot - это библиотека, написанная на Lua для
2424

2525
### Автоматическая
2626
1. Установите `git`, `curl`, `lua 5.1` и `luarocks`.
27-
2. (опционально) если потребуется работа с Web App:
28-
Потребуется установить rock пакет `luaossl`, для него в вашем дистрибутиве -
27+
2. (опционально) если потребуется работа с Web App: </br>
28+
Потребуется установить rock пакет `luaossl`, для него в вашем дистрибутиве - </br>
2929
установите заголовочные файлы для `lua 5.1` и `openssl`.
3030
2. Установите [tarantool](https://www.tarantool.io/ru/download/os-installation)
3131
3. Выполните скрипт автоматической установки необходимых пакетов

README_EN.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ bash tnt-tg-bot.pre-build.sh
3535
5. If issues occur, proceed with the manual installation.
3636

3737
> [!NOTE]
38-
> To successfully build luaossl (OpenSSL bindings), development headers for OpenSSL and Lua 5.1 are required.
39-
> On Ubuntu, install them with:
40-
> sudo apt install libssl-dev liblua5.1-0-dev
38+
> To successfully build luaossl (OpenSSL bindings), development headers for `OpenSSL` and `Lua 5.1` are required. </br>
39+
> On Ubuntu, install them with: `sudo apt install libssl-dev liblua5.1-0-dev` </br>
4140
> luaossl is required by the module bot/libs/parseInitData.lua, which handles Telegram Mini App initialization data.
4241
> https://core.telegram.org/bots/webapps#validating-data-received-via-the-mini-app
4342

examples/echo-bot-webhook.lua

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
-- Example of echo bot via webhook
2+
--
3+
local log = require('log')
4+
local bot = require('bot')
5+
local parse_mode = require('bot.enums.parse_mode')
6+
local methods = require('bot.enums.methods')
7+
8+
bot:cfg({
9+
token = os.getenv('BOT_TOKEN'),
10+
parse_mode = parse_mode.HTML
11+
})
12+
13+
function bot.events.onGetUpdate(ctx)
14+
local text = ctx:getText()
15+
local chatId = ctx:getChatId()
16+
17+
local _, err = bot.call(methods.sendMessage, {
18+
text = text,
19+
chat_id = chatId
20+
})
21+
22+
if err then
23+
log.error({
24+
error = err
25+
})
26+
end
27+
end
28+
29+
bot:startWebHook({
30+
-- Server setup
31+
host = '0.0.0.0',
32+
port = 8077,
33+
34+
-- Bot setup
35+
drop_pending_updates = true,
36+
allowed_updates = {
37+
"message",
38+
"chat_member", "my_chat_member",
39+
"callback_query",
40+
"pre_checkout_query"
41+
},
42+
43+
bot_url = 'https://sitename.io/bots/mybot'
44+
45+
-- If you don't have a domain name
46+
-- you will need to use a self-signed certificate
47+
-- https://core.telegram.org/bots/self-signed
48+
--
49+
--
50+
-- bot_url = 'https://180.10.120.240/bots/mybot',
51+
-- path to custom certificate
52+
-- certificate = '/etc/www/cert/public.pem'
53+
})

0 commit comments

Comments
 (0)