2017-01-02 6 views
2

私はIncome/ExpenseプロジェクトのためにTelegram Botを書いています。Python Telegram Bot会話方法が動作しない

私はpython-telegram-botを使用してこのコードを持っている:

#!/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() 

私は/startを使用する場合ボットは言うまでそれが動作:

Ok

Now Send Me Your Username

そして、それは返す必要があることの後にRegistering Your Usernameですが、そうではありません。

しかし、/cancelコマンドにアクセスできます。 私はこのスクリプトがregUser機能を呼び出さない理由を知る必要がありますか?

答えて

0

私の問題を解決した2つのエラーが見つかりました。 regUser

:最初

私は、二重引用符の間chat_idを使用 と第二私は資本Uの代わりupdaterUpdaterを使用。

関連する問題