TelegramAktienBot/telegram_bot/bot.py

55 lines
1.7 KiB
Python
Raw Normal View History

2022-03-12 16:20:33 +00:00
# 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
2022-03-12 18:44:58 +00:00
import os
import telebot
2022-03-12 18:24:25 +00:00
import time
import sys
import logging
from telebot import types
2022-03-12 18:44:58 +00:00
bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
2022-03-13 08:05:44 +00:00
bot.reply_to(message, "/id or /auth for authentication. For further details see aktienbot.flokaiser.com")
@bot.message_handler(commands=['id', 'auth'])
def send_id(message):
answer = 'Your ID/Authentication Code is: ' + str(message.from_user.id) + '. Enter this code in the settings on aktienbot.flokaiser.com to get updates on your shares.'
bot.reply_to(message, answer)
@bot.message_handler(func=lambda message: True)
def echo_all(message):
2022-03-13 08:05:44 +00:00
answer = 'Do not know this command or text: ' + message.text
2022-03-12 18:44:58 +00:00
bot.reply_to(message, answer)
2022-03-12 18:24:25 +00:00
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)
2022-03-12 18:44:58 +00:00
2022-03-12 18:24:25 +00:00
def main_loop():
bot.infinity_polling()
while 1:
time.sleep(3)
2022-03-12 18:24:25 +00:00
if __name__ == '__main__':
try:
main_loop()
except KeyboardInterrupt:
print('\nExiting by user request.\n')
sys.exit(0)