<?php
/*
Plugin Name: Telegram Bot & Channel (Custom)
Description: My Custom Telegram Plugin
Author: My name
Version: 1
*/

add_action('telegram_parse','telegramcustom_parse', 10, 2);

function telegramcustom_parse( $telegram_user_id, $text ) {
    $plugin_post_id = telegram_getid( $telegram_user_id );

    if ( !$plugin_post_id ) {
        return;
    }

    if ( get_post_meta( $plugin_post_id, 'telegram_custom_state' ) && get_post_meta( $plugin_post_id, 'telegram_custom_state' ) == 'age_wait' ) {
        if ( is_numeric( $text) && $text < 100 ) { //Do you want 101-years old people?
            $age = sanitize_text_field( $text );
            update_post_meta( $plugin_post_id, 'telegram_custom_age', $age )
            delete_post_meta( $plugin_post_id, 'telegram_custom_state' ); //Or set "telegram_custom_state" to something else
        } else {
            telegram_sendmessage( $telegram_user_id, 'Wrong input. What is your age?');
        }
    }

    if ( !get_post_meta( $plugin_post_id, 'telegram_custom_age' ) {
        telegram_sendmessage( $telegram_user_id, 'What is your age?');
        update_post_meta( $plugin_post_id, 'telegram_custom_state', 'age_wait' );
        //die(); //You can uncomment this if you want to parse other commands
    }

    return;
}

?>