V
V
Vovan20052020-02-10 17:04:22
Python
Vovan2005, 2020-02-10 17:04:22

How to process a user's message after calling a particular function from a Telegram bot in Python?

I am writing a bot in python using telegram.ext. I'm having a problem implementing an idea that is about processing the message that the user will send after calling \function. For example, I call \function, after which I send my name to the bot and then, having received it, it sends it to me (something like an echo). This is a simple example, but the bottom line is that when I run \function, I have to process the message and give a response to the user.

from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, RegexHandler
from telegram import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery, ReplyKeyboardMarkup, KeyboardButton, ReplyKeyboardRemove
import os
import time
import apiai, json

TOKEN = os.environ["TOKEN"]


updater = Updater(token=TOKEN)
dispatcher = updater.dispatcher


def startCommand(bot, update):
    bot.send_message(chat_id=update.message.chat_id, text='Привет!')


def functionCommand(bot, update):
    bot.send_message(chat_id=update.message.chat_id, text="Отправь мне своё имя!")
    #здесь нужно получитить сообщение, которое отправит пользователь после вызова этой функции






function_Command_handler = CommandHandler('function', functionCommand)
start_command_handler = CommandHandler('start', startCommand)


dispatcher.add_handler(function_Command_handler)
dispatcher.add_handler(start_command_handler)


updater.start_polling(clean=True)

updater.idle()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question