You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
#Mau mau das wird der Funi Bot
|
|
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
|
|
import logging
|
|
|
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def start(update, context):
|
|
"""Send a message when the command /start is issued."""
|
|
update.message.reply_text('Hallo! Ich bin dein Echo-Bot. Sende mir eine Nachricht und ich werde sie wiederholen.')
|
|
|
|
def echo(update, context):
|
|
"""Echo the user message."""
|
|
update.message.reply_text(update.message.text)
|
|
|
|
def error(update, context):
|
|
"""Log Errors caused by Updates."""
|
|
logger.warning('Update "%s" caused error "%s"', update, context.error)
|
|
|
|
def main():
|
|
"""Start the bot."""
|
|
# Ersetzen Sie 'YOUR_TOKEN' mit Ihrem Bot-Token
|
|
updater = Updater("6885365398:AAHhgMRbUGfeS0VzKRmJvjKxSHfi18xESC4", use_context=True)
|
|
|
|
# Get the dispatcher to register handlers
|
|
dp = updater.dispatcher
|
|
|
|
# on different commands - answer in Telegram
|
|
dp.add_handler(CommandHandler("start", start))
|
|
|
|
# on noncommand i.e message - echo the message on Telegram
|
|
dp.add_handler(MessageHandler(Filters.text, echo))
|
|
|
|
# log all errors
|
|
dp.add_error_handler(error)
|
|
|
|
# Start the Bot
|
|
updater.start_polling()
|
|
|
|
# Run the bot until you press Ctrl-C or the process receives SIGINT,
|
|
# SIGTERM or SIGABRT. This should be used most of the time, since
|
|
# start_polling() is non-blocking and will stop the bot gracefully.
|
|
updater.idle()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|