from telegram.ext import Updater
from telegram.ext import CommandHandler
from telegram.ext import MessageHandler, Filters
def start(bot, update):
# Your bot will send this message when users first talk to it, or when they use the /start command
bot.sendMessage(chat_id=update.message.chat_id,
text="Hi. Send me any English text and I'll summarize it for you.")
def summarize(bot, update):
try:
# Get the text the user sent
text = update.message.text
bot.sendMessage(chat_id=update.message.chat_id,
text=text)
#print(text)
# Run it through the summarizer
except UnicodeEncodeError:
bot.sendMessage(chat_id=update.message.chat_id,
text="Sorry, but I can't summarise your text.")
updater = Updater(token=my_token)
dp = updater.dispatcher
summarize_handler = MessageHandler(Filters.text, summarize)
start_handler = CommandHandler('start', start)
dp.add_handler(summarize_handler)
dp.add_handler(start_handler)
dp.bot.sendMessage('사람 id',text="himan")
updater.start_polling(timeout=3,clean=True)
updater.idle()
Commandhander를 앞에 /나 @에 반응한다.
참고 : https://blog.psangwoo.com/coding/2018/01/09/python-telegram-bot-3.html
'Phython' 카테고리의 다른 글
beautifulsoup에서 링크만 빼는법 (0) | 2019.05.28 |
---|---|
시놀리지에서 vpn client 사용하는 방법 (0) | 2019.05.28 |
python 글로벌 변수 메소드에서 사용방법 (0) | 2019.05.21 |
파이썬 simple json 파싱 (0) | 2019.05.17 |
파이썬 web request (0) | 2019.05.17 |