Zde je jednoduchý návod krok za krokem, jak zprovoznit váš Telegram bot:
- Otevřete Telegram a vyhledejte @BotFather
- Pošlete mu příkaz
/newbot - Zadejte jméno bota a uživatelské jméno (musí končit na "bot")
- BotFather vám pošle token - ten si uložte
- Pošlete zprávu svému botovi nebo ho přidejte do skupiny
- Navštivte URL:
https://api.telegram.org/bot<VÁŠ_TOKEN>/getUpdates - V odpovědi najdete
chat_idpro vaše konverzace
Upravte soubor config/settings.yml:
telegram:
bot_token: "VÁŠ_TELEGRAM_BOT_TOKEN"
chat_ids:
- 123456789 # ID prvního chatu
- 987654321 # ID druhého chatu (pokud potřebujete)
users:
- username: "admin"
password: "bezpečné_heslo_1"
- username: "user2"
password: "bezpečné_heslo_2" # Volitelné
cd /var/www/crucio.cz/bot
bundle install
Vytvořte soubor /etc/systemd/system/telegram-bot.service
[Unit]
Description=Telegram Bot Service
After=network.target
[Service]
User=www-data
WorkingDirectory=/var/www/crucio.cz/bot
ExecStart=/usr/local/bin/bundle exec puma
Restart=always
Environment=RACK_ENV=production
[Install]
WantedBy=multi-user.target
systemctl enable telegram-bot
systemctl start telegram-bot
<VirtualHost *:80>
ServerName bot.crucio.cz
Redirect permanent / https://bot.crucio.cz/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName bot.crucio.cz
ErrorLog ${APACHE_LOG_DIR}/bot.crucio.cz-ssl-error.log
CustomLog ${APACHE_LOG_DIR}/bot.crucio.cz-ssl-access.log combined
ProxyPass / http://localhost:4567/
ProxyPassReverse / http://localhost:4567/
SSLEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/bot.crucio.cz/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/bot.crucio.cz/privkey.pem
</VirtualHost>
</IfModule>
a2enmod proxy proxy_http ssl rewrite
a2ensite bot.crucio.cz.conf bot.crucio.cz-le-ssl.conf
systemctl restart apache2
curl -X GET http://localhost:4567/health
curl -X POST http://localhost:4567/send_message \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"bezpečné_heslo_1","message":"Testovací zpráva"}'
# Test zdraví služby
curl -X GET https://bot.crucio.cz/health
# Test odeslání zprávy
curl -X POST https://bot.crucio.cz/send_message \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"bezpečné_heslo_1","message":"Testovací zpráva přes doménu"}'