K
K
kollfun2021-01-02 03:33:41
Python
kollfun, 2021-01-02 03:33:41

How to refer to a function element without its interaction?

@dp.message_handler()
    async def search_for_film(message: types.Message) -> None:
        await send_result(message)
    
    async def send_result() -> None:
        response = api_client.films.send_search_by_keyword_request(SearchByKeywordRequest(message.text))
        id = response.films[0].film_id
        response = api_client.films.send_film_request(FilmRequest(id))
        fx = \
            f"*{response.film.name_ru}* ({response.film.year})\n" \
            f"Рейтинг: *{response.film.rating_kinopoisk}*⭐\n\n" \
            f"{response.film.short_description}" 
    
        await bot.send_photo(message.chat.id, response.film.poster_url, fx, reply_markup=kb.inline_kb_full,
                                 parse_mode=types.ParseMode.MARKDOWN)
    
    
    @dp.callback_query_handler(lambda c: c.data == 'fulldscr')
    async def show(callback_query: types.CallbackQuery):
        await bot.send_message(callback_query.from_user.id, response.film.description)


The essence is this: the user enters the name of the movie and `response` is found on it.

@dp.callback_query_handler(lambda c: c.data == 'fulldscr')
    async def show(callback_query: types.CallbackQuery):
        await bot.send_message(callback_query.from_user.id, response.film.description)


This is a test for pressing an inline button. How do I replace this `response.film.description` to make it work?
(I don't really understand python, so when I try to append something like `response = send_result()`, the function needs a new value of type `message`.)

How do I take the `response` value from the `send_result` function and insert it in `@dp.callback_query_handler`?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kadabrov, 2021-01-02
@Kadabrov

in the function
async def send_result() -> None:
, store the data you need in the FSMContext store
Finite State Machines (FSM)
and in the function

async def show(callback_query: types.CallbackQuery):

get the data you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question