Change WP attachment name to postid during upload only for post type

I’m really sorry. I fixed my problem after few minutes I post this question. So I added my working code here for future help if anyone need this.

add_action('add_attachment', 'rename_attacment');

function rename_attacment($post_ID){
 if ( get_post_type( $_REQUEST['post_id'] ) === 'post_type_1' OR get_post_type( $_REQUEST['post_id'] ) === 'post_type_2' OR get_post_type( $_REQUEST['post_id'] ) === 'post_type_3' ){
    $post = get_post($post_ID);
    $file = get_attached_file($post_ID);
    $path = pathinfo($file);
        //dirname   = File Path
        //basename  = Filename.Extension
        //extension = Extension
        //filename  = Filename

    $newfilename = "NEW FILE NAME HERE";
    $newfile = $path['dirname']."https://wordpress.stackexchange.com/".$newfilename.".".$path['extension'];

    rename($file, $newfile);    
    update_attached_file( $post_ID, $newfile );
 }
}

Thanks to Everyone.

error code: 523