• Resolved imyifan1

    (@imyifan1)


    Hi, i really like your plugin ?? however I am facing trouble creating a bot that will change its response according to what people text it. For example:

    Send- /Weather

    Response-
    Monday: Sunny
    Tuesday: Rainy
    Wednesday: Cloudy

    Send- /UpdateWeather

    Response- What do you want to change?
    [Inline Keyboard with 3 options] 1) Monday 2) Tuesday 3) Wednesday

    Send- Monday

    Response- What is the weather on Monday?

    Send- Rainy

    Response- Thank you, your response has been changed.

    Send- /Weather

    Response-
    Monday: Rainy
    Tuesday: Rainy
    Wednesday: Cloudy

    Sorry if it’s really long, but will really appreciate it if you could help me out here ?? thank you!!

Viewing 1 replies (of 1 total)
  • Plugin Author Marco Milesi

    (@milmor)

    Hi,
    have you tried to code the bot? Where do you plan to save weather data?

    This can be done, but first check our https://www.ads-software.com/plugins/telegram-bot/faq/ to learn how responses work. Just try to code it and i’ll help to fix and get it working ??

    Here is a start for you: [NOT TESTED]

    <?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;
        }
    
        } else if ( $text == '/UpdateWeather') {
            telegram_sendmessage( $telegram_user_id, 'What do you want to change?!', telegram_build_reply_markup( 'Monday,Tuesday,Wednesday', true ));
            delete_post_meta( $plugin_post_id, 'telegram_custom_state' );
        } else if ( $text == 'Monday') {
            telegram_sendmessage( $telegram_user_id, 'What is the weather on Monday?');
            update_post_meta( $plugin_post_id, 'telegram_custom_state', 'wait_monday' );
        } else if ( get_post_meta( $plugin_post_id, 'telegram_custom_state', true ) == 'wait_monday' ) {
            //SAVE DATA TO YOUR DB
            telegram_sendmessage( $telegram_user_id, 'Thank you, your response has been changed.');
            delete_post_meta( $plugin_post_id, 'telegram_custom_state' );
        }        
        return;
    }
    
    ?>
    • This reply was modified 8 years, 4 months ago by Marco Milesi.
Viewing 1 replies (of 1 total)
  • The topic ‘Creating a Bot that Changes Response’ is closed to new replies.