Phython2019. 5. 21. 12:01

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

 

Posted by 동동(이재동)

댓글을 달아 주세요