Skip to content

Instantly share code, notes, and snippets.

@hiddentribe
Forked from d-Rickyy-b/main.py
Created April 16, 2018 05:28
Show Gist options
  • Select an option

  • Save hiddentribe/d1e24825a7d1d22a5cd705fb25c8fea0 to your computer and use it in GitHub Desktop.

Select an option

Save hiddentribe/d1e24825a7d1d22a5cd705fb25c8fea0 to your computer and use it in GitHub Desktop.
Introduction to bot programming
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Source: https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/echobot2.py"""
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import logging
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
# Define a few command handlers. These usually take the two arguments bot and
# update. Error handlers also receive the raised TelegramError object in error.
def start(bot, update):
"""Send a message when the command /start is issued."""
update.message.reply_text('Hi!')
def echo(bot, update):
"""Echo the user message."""
update.message.reply_text(update.message.text)
"""Start the bot."""
# Create the EventHandler and pass it your bot's token.
updater = Updater("TOKEN")
# 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))
# Start the Bot
updater.start_polling()
updater.idle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment