Hack 96 Negative Feedback Notification

figs/expert.giffigs/hack96.gif

Have a script notify you whenever you've received negative feedback.

Given the importance of feedback, especially to sellers, it's a good idea to routinely check your feedback profile for complaints or comments that should be addressed, as discussed in [Hack #4]. But doing this every day, especially for sellers who receive dozens or even hundreds of feedback comments every week, can be a chore.

This script routinely scans your feedback profile and notifies you of any new negative or neutral feedback you've received.

#!/usr/bin/perl
require 'ebay.pl';

$localfile = "feedbackalert.txt";
%roles = ('S', 'seller', 'B', 'buyer');

my $rsp = call_api({ Verb => 'GetFeedback',     [1]
              DetailLevel => 1,
                   UserId => $user_id,
                   SiteId => $site_id,
             StartingPage => $page_number,
             ItemsPerPage => 1
});
$totalcomments = $rsp->{Feedback}{FeedbackDetailItemTotal};

$oldtotal = 0;
if (-e "$localdir/$localfile") {
  open (INFILE,"$localdir/$localfile");
    $oldtotal = <INFILE>;     [2]
  close (INFILE);
}

$newcomments = $totalcomments - $oldtotal;     [3]
if ($newcomments == 0) { exit; }

if ($newcomments > 200) {
  $num_pages = int($newcomments / 200) + 1;
  $page_size = 200;
} else {
  $num_pages = 1;
  $page_size = $newcomments;
}

PAGE:
for (my $page_number = 1; $page_number <= $num_pages; $page_number++) {
  my $rsp = call_api({ Verb => 'GetFeedback',     [4]
                DetailLevel => 1,
                     UserId => $user_id,
                     SiteId => $site_id,
               StartingPage => $page_number,
               ItemsPerPage => $page_size
  });

  if ($rsp->{Errors}) {
    print_error($rsp);
    last PAGE;
  }

  FEEDBACK:
  foreach (@{$rsp->{Feedback}{FeedbackDetail}{FeedbackDetailItem}}) {
    my %i = %$_;
    ($text, $type, $from, $item, $id, $role) = @i{qw/CommentText CommentType
                   CommentingUser ItemNumber TransactionId FeedbackRole/};

    if (($type eq "Complaint") || ($type eq "Neutral")) {     [5]
      open (INFILE,"$localdir/$localfile");
        while ( $line = <INFILE> ) {
          if ($line eq "$id\n") { next FEEDBACK; }
        }
      close (INFILE);

      open(MAIL,"|/usr/sbin/sendmail -t");
      print MAIL "To: $selleremail\n";
      print MAIL "From: $selleremail\n";
      print MAIL "Subject: Negative Feedback Alert\n\n";
      print MAIL "A ".$roles{"$role"}.", $from, has left this feedback:\n";
      print MAIL "$type: '$text'\n";
      print MAIL "regarding this transaction:\n";
      print MAIL "$itemurl$item\n";
      close(MAIL);     [6]
    }
  }
}

open (OUTFILE,">$localdir/$localfile");
print OUTFILE $totalcomments;     [7]

close (OUTFILE);

What may seem like an unnecessary extra call at the beginning of the script (line [1]) is actually quite necessary to achieve compliance with eBay's Production Access Rules. This call retrieves a single comment entirely for the purpose of determining the total number of feedback comments in the profile, $totalcomments.

The number of new comments ($newcomments, line [3]) is calculated by subtracting the previous total ($oldtotal, line [2]) from the current total. Then, all new comments are retrieved with the second GetFeedback API call on line [4].

All this needs to be done because GetFeedback doesn't support the EndTimeFrom or EndTimeTo arguments (possibly signifying the dates that feedback comments were left) that are supported by most of the other API calls discussed in this chapter. Paradoxically, adding an extra call (line [1]) prevents the script from issuing too many calls later on. Since the script doesn't need to download the entire feedback profile every time, you also don't need to cache feedback, as eBay suggests.

The script then iterates through the profile and sends an email every time a new negative or neutral feedback comment is encountered. Finally, the script records the new total (line [7]).

To automate this script, schedule it to run regularly (every day, every week, etc.), as described in [Hack #17].

See [Hack #91] for a script to notify you when a user with a negative feedback rating bids on one of your auctions.