Created
December 12, 2017 17:06
-
-
Save afonsoaugusto/2ce173c1bd68cf6f28d713b61010082d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#sudo ap-get update | |
#sudo pip install python-telegram-bot --upgrade | |
#https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-Your-first-Bot | |
from sys import path | |
from configparser import ConfigParser | |
from telegram import ParseMode, Emoji | |
from telegram.ext import Updater, CommandHandler | |
from telegram.ext import MessageHandler, Filters | |
import logging | |
# Bot Configuration | |
config = ConfigParser() | |
config.read('config.ini') | |
# Connecting the telegram API | |
# Updater will take the information and dispatcher connect the message to | |
# the bot | |
tk=config.get('DEFAULT','token') | |
updater = Updater(token=tk) | |
dispatcher = updater.dispatcher | |
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',level=logging.INFO) | |
def start(bot, update): | |
bot.sendMessage(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!") | |
def echo(bot, update): | |
bot.sendMessage(chat_id=update.message.chat_id, text=update.message.text) | |
start_handler = CommandHandler('start', start) | |
dispatcher.add_handler(start_handler) | |
echo_handler = MessageHandler([Filters.text], echo) | |
dispatcher.add_handler(echo_handler) | |
updater.start_polling() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment