• Hi
    I want to take images from users and send it back to them. Is it possible? Do I need to make a new extension or not?
    Best regards

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

    (@milmor)

    Hello,
    here is the code.

    The best way to integrate and add functions is to create another plugin. For example, create a file called telegram-bot-custom.php and upload it to wp-content/plugins, then activate it. Write the file as follows:

    <?php
    /*
    Plugin Name: Telegram Bot & Channel (Custom)
    Description: My Custom Telegram Plugin
    Author: My name
    Version: 1
    */
    
    function telegram_parse_photo_s ( $telegram_user_id, $photo  ) {
    
      $plugin_post_id = telegram_getid( $telegram_user_id );
    
      $url = telegram_download_file( $telegram_user_id, $photo[2]['file_id'] );
    
      if ( $url ) {
          telegram_sendphoto( $telegram_user_id, $caption, $url);
          telegram_sendmessage( $telegram_user_id, 'Was this your photo?');
      }
    } add_action('telegram_parse_photo','telegram_parse_photo_s', 10, 2);
    
    ?>

    I wasn’t able to send $caption, but will check asap. For now, leave it empty (you can still send a simple message after the photo).

    The $photo variable defines different sizes. [2] is a good mix between weight and resolutions. You can check for the size of array and get an higher one if you want more resolution.

    • This reply was modified 8 years, 2 months ago by Marco Milesi.
    Thread Starter vahidtk

    (@vahidtk)

    Thanks a lot
    And there is another question.
    Is it possible to make a ‘step by step bot’ with the extension? something like step by step forms that user should answer some questions respectively.

    Plugin Author Marco Milesi

    (@milmor)

    Yes, you just have to save a “telegram state field” with
    get_post_meta( $plugin_post_id, 'telegram_custom_state' );
    (You can use a different field name, create another db table, or something else you need…)

    You can find my code for a “civic” bot here:
    github.com/milesimarco/terremotocentroitalia-bot-telegram

    (The example parses locations, messages and photos)

    • This reply was modified 8 years, 2 months ago by Marco Milesi.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Take image from user in bot and forward it back’ is closed to new replies.