2
소득/지출 프로젝트에 Telegram Bot
을 쓰고 있습니다.Python Telegram Bot 대화 방식이 작동하지 않습니다.
이 코드는 python-telegram-bot
를 사용하여이 : 나는 /start
를 사용하는 경우
#!/usr/bin/python
# -*- Coding : UTF-8 -*-
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, ConversationHandler
from settings.conf import conf
conf = conf()
updater = Updater(str(conf.token()))
SETUP ,USERNAME = range(2)
def start_method(bot, update):
""" Start Command """
startList = [["Register New Account","Integrate An Account"]]
chat_id = update.message.chat_id
replyText = update.message.text
text = """Hello And Welcome To [Bestoon](http://bestoon.ir).
This Bot Helps You Easily Access Your [Bestoon](http://bestoon.ir) Account.
Now, How Can I Help You?
"""
bot.sendChatAction(chat_id, "TYPING")
update.message.reply_text(text, parse_mode="Markdown",reply_markup=ReplyKeyboardMarkup(startList, one_time_keyboard=True))
return SETUP
def setup(bot, update):
"""Initialize The User Account For The First Time"""
chat_id = update.message.chat_id
if update.message.text == "Register New Account":
bot.sendChatAction(chat_id, "TYPING")
register_text = """Ok.
Now Send Me Your Bestoon Username.
"""
update.message.reply_text(register_text,reply_markup=ReplyKeyboardRemove())
print "Going For Username"
return USERNAME
elif update.message.text == "Integrate An Account":
bot.sendChatAction(chat_id, "TYPING")
update.message.reply_text("Sorry, Can\'t Integrate Now!", reply_markup=ReplyKeyboardRemove())
bot.sendMessage(update.message.chat_id, "Bye!")
return ConversationHandler.END
else:
bot.sendChatAction(chat_id, "TYPING")
update.message.reply_text("Invalid Command!")
def regUser(bot, Update):
chat_id = update.message.chat_id
bot.sendChatAction("chat_id", "TYPING")
update.message.reply_text("Registering Your Username")
return ConversationHandler.END
def cancel(bot, update):
bot.sendMessage(update.message.chat_id, "Bye!")
return ConversationHandler.END
conv_handler = ConversationHandler(
entry_points = [CommandHandler('start', start_method)],
states = {
SETUP: [MessageHandler(Filters.text, setup)],
USERNAME: [MessageHandler(Filters.text, regUser)]
},
fallbacks = [CommandHandler('cancel', cancel)]
)
updater.dispatcher.add_handler(conv_handler)
########## Starting Bot ##########
updater.start_polling()
updater.idle()
그것은 봇 말한다 작품까지 :
Ok
Now Send Me Your Username
그리고 그것을 반환 할 필요가 후 Registering Your Username
하지만 그렇지 않습니다.
하지만 /cancel
명령에 액세스 할 수 있습니다. 이 스크립트가 regUser
기능을 호출하지 않는 이유를 알아야합니까?