Use 2 docker containers for bot and webservice
This commit is contained in:
17
telegram_bot/Dockerfile
Normal file
17
telegram_bot/Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM python:3.10-alpine
|
||||
|
||||
WORKDIR /srv/flask_app
|
||||
|
||||
COPY requirements.txt /srv/flask_app/
|
||||
|
||||
RUN pip install -r requirements.txt --src /usr/local/src --no-warn-script-location
|
||||
|
||||
COPY .. /srv/flask_app
|
||||
RUN chmod +x ./deploy/start.sh
|
||||
RUN chmod +x ./deploy/healthcheck.sh
|
||||
|
||||
# HEALTHCHECK --interval=15s --timeout=2s CMD ["./deploy/healthcheck.sh"]
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["./deploy/start.sh"]
|
52
telegram_bot/bot.py
Normal file
52
telegram_bot/bot.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# Work in Progress
|
||||
# Api-Key: 5228016873:AAGFrh0P6brag7oD3gxXjCh5gnLLE8JMvMs
|
||||
# text bot at t.me/projektaktienbot
|
||||
# API Documentation https://core.telegram.org/bots/api
|
||||
# Code examples https://github.com/eternnoir/pyTelegramBotAPI#getting-started
|
||||
import os
|
||||
|
||||
import telebot
|
||||
import time
|
||||
import sys
|
||||
import logging
|
||||
from telebot import types
|
||||
|
||||
bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
|
||||
|
||||
|
||||
@bot.message_handler(commands=['start', 'help'])
|
||||
def send_welcome(message):
|
||||
bot.reply_to(message, "Thank you for using this bot")
|
||||
|
||||
|
||||
@bot.message_handler(func=lambda message: True)
|
||||
def echo_all(message):
|
||||
answer = message.text + ' ID: ' + str(message.from_user.id)
|
||||
bot.reply_to(message, answer)
|
||||
|
||||
|
||||
telebot.logger.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
@bot.inline_handler(lambda query: query.query == 'text')
|
||||
def query_text(inline_query):
|
||||
try:
|
||||
r = types.InlineQueryResultArticle('1', 'Result1', types.InputTextMessageContent('hi'))
|
||||
r2 = types.InlineQueryResultArticle('2', 'Result2', types.InputTextMessageContent('hi'))
|
||||
bot.answer_inline_query(inline_query.id, [r, r2])
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
def main_loop():
|
||||
bot.infinity_polling()
|
||||
while 1:
|
||||
time.sleep(3)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main_loop()
|
||||
except KeyboardInterrupt:
|
||||
print('\nExiting by user request.\n')
|
||||
sys.exit(0)
|
2
telegram_bot/deploy/healthcheck.sh
Normal file
2
telegram_bot/deploy/healthcheck.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env sh
|
||||
curl -s http://localhost:80/ -o /dev/null || exit 1
|
2
telegram_bot/deploy/start.sh
Normal file
2
telegram_bot/deploy/start.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env sh
|
||||
python bot.py
|
1
telegram_bot/requirements.txt
Normal file
1
telegram_bot/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
pyTelegramBotAPI~=4.4.0
|
Reference in New Issue
Block a user