在函数内部获取更新(Telegram bot,Python3,python-telegram-bot库)

问题描述 投票:0回答:1

我正在尝试使用python3中的https://github.com/python-telegram-bot/python-telegram-bot库制作电报机器人。

我想制作一个邮件发件人机器人。现在这是我的代码:

#!/usr/bin/env python
"""#==============================# Imports #==============================#"""
import logging, time, telegram
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from datetime import datetime

"""#==============================# Enable logging #==============================#"""
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.WARN)#DEBUG)
logger = logging.getLogger(__name__)

"""#==============================# Log error #==============================#"""

def error(update, context):
    #Log Errors caused by Updates.
    logger.warning("Update '%s' caused error '%s'", update, context.error)


"""#==============================# Bot commands #==============================#"""

def start(update, context):
    update.message.reply_text("Bot joined the conversation!")

def get_additional_updates(update, message):
***My Problem***


"""#==============================# MAIN #==============================#"""

def main():
    updater = Updater("<TOKEN>", use_context=True)

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # on different commands - answer in Telegram
    dp.add_handler(CommandHandler("start", start)
    dp.add_handler(CommandHandler("send", get_additional_updates)

    # log all errors
    dp.add_error_handler(error)
    # Start the Bot
    updater.start_polling()
    updater.idle()


if __name__ == '__main__':
    main()

我不知道应该怎么做才能在'get_additional_updates'函数中获取更新。我想要做的是:我输入/ send,在此之后,机器人等待我的消息,然后输入我的消息并发送。问题是,我无法弄清楚如何将第二条消息(消息本身)发送到“ get_additional_updates”功能。

我在文档中找不到它,而且我对编程也很陌生。

请帮助我输入需要在此处输入的代码,以获取其他消息。如果您无法理解我的问题,请告诉我,我会尽力向您解释。

非常感谢!

P.S .:对不起,如果我的英语不好,我也会尝试将其升级。

python python-3.x telegram python-telegram-bot
1个回答
0
投票

您应该使用对话机器人,请检查示例here

© www.soinside.com 2019 - 2024. All rights reserved.