My President Twitter Bot Experiment

by R.B.

Until a few months back, Argentina had a twelve year monarchy-styled government including huge corruption, nepotism and politic violence.  Néstor Kirchner was president for four years.  Then his wife, Cristina Fernandez de Kirchner, was president for the following eight years.  Cristina Fernandez de Kirchner, instead of giving press conferences, used the official Twitter account @CFKArgentina to spread Goebbels-styled propaganda, send threats to opposition, and exalt fanatics of all kinds.

After analyzing the official Twitter account, I decided to make an experiment: a fake Twitter account (@CFKResponde) that responds using a custom made PHP/MySQL chatterbot.

The main idea was to determine the percentage of people who were able to identify that a computer was responsible for the answers in this controlled environment of a political Twitter discussion.

To make this experiment, I have started by populating a database table with a field to detect certain words and expressions, and another field for the answers.  The answers are loaded from presidential speeches and also from politic fanatics' Twitter timelines.

The database is connected to a PHP script, which is executed once per hour with a Linux cron job.  That PHP script uses a Twitter Application Programming Interface (API) to read mentions, parse into words, detect questions, insults, etc., and then match them with the database to preselect the best fit answers.

PHP Code to Detect Mentions Using Twitter API

<?php
require_once('twitter/twitteroauth.php');
$tweet = new TwitterOAuth($userKey, $userSecret, $userToken, $userTokenSecret);
$result = $tweet->get('statuses/mentions_timeline', array('since_id' => 1000, 'cursor' => $cursor, 'count' => 10));
foreach($result as $tweet) {
  call mybot($tweet->text, $tweet->user->screen_name, $tweet->id_str);
}
?>

PHP Code to Match Phrase with Database

<?php
$query = "SELECT answer FROM brain WHERE phrase='".$upperWord."'";
$result = readDatabase($query);
$num = mysql_numrows($result);
$i2 = 0;
while ($i2 < $num) {
  $arrOut[$i][0] = mysql_result($result, $i2, "answer");
  $i++;
  $i2++;
}
?>

From preselected answers, a random number determine the final response, which is posted also using a Twitter API.  All interactions are logged for further analysis and tuning.  If words or expressions are not detected in the database, the bot is able to respond with generic answers and also with a mix of online and offline content   Example: stored database answer combined with an opposition newspaper headline.

PHP Code for Newspaper Headlines

<?php
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
foreach ($x->channel->item as $entry) {
  if ($limit < 5) {
    $myRand = rand (1, 3);
    if ($myRand == 1) {
      $preNews = "Read this headline: ";
    }
    $arrOut[$i][0] = $preNews.utf8_decode($entry->title);
    $i++;
    $limit++;
  }
}
?>

The fake presidential bot has been running for five months, generating thousands of interactions, as well as retweets and likes.  Until this point, not even one person accused @CFKResponde of being a computer program.

While several conclusions can be obtained from this small experiment, I have the strong feeling that this massive deception was anything but a technological merit, since there is no merit in replicating the empty and automated rhetoric that politics have been using in Argentina.

Return to $2600 Index