Featured Posts

Attention Exchange, a P2P Media-Hijacking Chatbot

//This project is developed as a final for Technology, Media and Democracy 2018 class.

I. Background

The Problem with Commoditizing Attention-Span

With the advent of social media platforms such as Facebook and Twitter, the digital advertising industry has thrived on being able to reach their audience granularly and having greater control over their distribution. Every view, engagement, and click can now be traced and accounted for. Personalizations and micro-targeting were made possible, and platform algorithms are optimizing for maximum eyeballs and attention-spend.

The byproduct of such business model, operating at a scale so large, is the erosion of shared experiences within communities. This has taken form in filter bubbles or echo chambers, as well as media-diet hijacking by politically-motivated and/or bad actors.

Although society at large has recently acknowledged the harmful effects social media platforms have on the practice of democracy, in order to properly define the problem in the first place, it would be prudent to consider the realities of the issue: (1) filter bubbles were created to accommodate our intrinsic social behaviors and preferences, and (2) the platforms still have the biggest power in terms of controlling our media diet.

Filter Bubbles are Hard to Break

It is in our nature to feel good about being “right”, and our default behavior is to reinforce our pre-existing biases[1]. Debunking misinformation in news articles also often backfires, and instead increases the misperception[2].

In a world where people can discover anything by just googling, filter bubbles and echo chambers become really hard to break. With the over-abundance of information, people do not necessarily want to be more discerning. And even if they wanted to, they might be ill-equipped to sustainably do so.

Users Still Have Limited Agency over Their Media Diet

The 2016 US elections had shed light on foreign actors (be it the Russian government or Cambridge Analytica) hijacking the media diet of a large part of the country’s population. Together with various exposé and lawsuits, this has resulted in high-profile hearings, both in the US and Europe, pressuring the platforms to adhere to more user-centric data practices.

However, what does it mean for users to have more control over their personal data? Having the ability to opt out and be “forgotten” by tracking algorithms is definitely better than requiring platforms to be transparent just for transparency’s sake, but understanding the provenance of a piece of content as well as the underlying distribution algorithm remains a daunting task for an everyday user.

I would argue even further that having agency over the news feed is an oxymoron, because a feed is supposed to cater to the user’s subconscious viewing behaviors. Relinquishing control to users would not only be extremely tricky to implement, but also detrimental to these platforms’ business model. They, and by extension the whole digital advertising industry, rely on the ability to move users’ eyeballs to engage with paid content.

Ultimately, users are still at the mercy of the institutions of power. These institutions might be the platforms and their advertisers, in regions where regulations are loose, and these might be government or censoring bodies, if they have enough power to pressure the platforms.

II. The Opportunity

There has been an emerging sentiment that local communities are now more relevant than ever, as people hope to bridge the divide created by partisanship and to be back in touch with what is happening on-ground and around their own vicinity. Perhaps then, the key to bursting the filter bubble is to increase one’s involvement in their immediate communities.

Efforts to increase the literacy around media and the online feed have also been observed. Although the ad platforms remain hard to navigate around for everyday users, there are creative ways to introduce them to news production and distribution, such as through mobile games or a school curriculum. The question is then, how do take this literacy-building effort out of the constrain of games and or academic setting, and into real-world applications? It might be possible to subvert the ad platforms that have been abused to propagate disinformation.

III. An Experimental Solution – The Concept

The primary aims of Attention Exchange are:

  1. to encourage platforms users to read outside of their filter bubble, and

  2. to give users back some of their agency over their media diet.

This would be done by leveraging on the existing social media behavior: users expressing and imposing their opinions on the platforms because they will feel good about it.

The bridge between the goals and the existing usage behavior is micro-transactions. Attention Exchange allows peers to pay each other to read articles; the payee only needs to comprehend the article of the payer’s choice to unlock the monetary reward. In cases where the involved parties are of different ideologies or political affiliation, the money would serve as an incentive to comprehend the opposing view for the payee, and as an expression of both waging something at stake and ideological superiority for the payer.

Attention Exchange can also be seen as a peer-to-peer ad buying platform, where peers interfere with each other’s media diet. The differences are the intention behind the ad buy is more transparent, and the readership is verifiable and more importantly consensual.

Now, having a platform that allows people to buy each other’s media diet could also introduce new problems, or even exacerbate existing ones. Reading news articles could still be unaffecting to one’s pre-existing beliefs, or people with the most capital would be the biggest media diet controller in their community. But as an experimental solution in its early stage, Attention Exchange also asks the following speculative questions:

  • What does it mean to freely trade our attention-span as willing individuals?

  • Can our view be regarded as labor? Could we put a dollar value on our time and attention-span?

  • Does the action of influencing someone’s media diet amount to anything at all when the tools to do so are democratized?

IV. The Build

Attention Exchange is a Facebook Messenger chatbot. It is built on Node.JS using Dialogflow (formerly API.ai) API and Cheerio scraping library. Below are the steps I went through to create the prototype:

  1. Create a Node.JS server, connect it to Dialogflow and Facebook Messenger

  2. Save inputs (user’s name, friend’s name, article link) and program bot’s replies

  3. Scrape input article and upload a white-labeled version

  4. Notify payee on Facebook Messenger

  5. Verify readership via timed buttons

Create a Node.JS server, connect it to Dialogflow and Facebook Messenger

Referencing Pilar Figueroa’s tutorial on creating a Facebook Messenger bot[3], I used a Node.JS server and Dialogflow as the basis for the chatbot. In this preliminary step, I created a new Facebook Page for Attention Exchange and a Messenger app.

The code block that connects Dialogflow and the Messenger app is as following:

const sendTextMessage = (senderId, text) => {


url: 'https://graph.facebook.com/v2.6/me/messages',

qs: { access_token: FACEBOOK_ACCESS_TOKEN },

method: 'POST',

json: {

recipient: { id: senderId },

message: { text },




module.exports = (event) => {

const senderId = event.sender.id;

const message = event.message.text;

const apiaiSession = apiAiClient.textRequest(message, {sessionId: ‘ae_bot’});

apiaiSession.on(‘response’, (response) => {

const result = response.result.fulfillment.speech;

sendTextMessage(senderId, result);


apiaiSession.on(‘error’, error => console.log(error));



Save inputs (user’s name, friend’s name, article link) and program bot’s replies

their distribution. Every view, engagement, and click can now be traced and accounted for. Personalizations and micro-targeting were made possible, and platform algorithms are optimizing for maximum eyeballs and attention-spend.

In this prototype, the flow on the application is linear:

  1. User says hi

  2. Bot replies with a prompt for the intended recipient (payee)

  3. User specifies the name of recipient

  4. Bot replies with a prompt for article link

  5. User pastes the link of the article

  6. Bot replies that it will send the article to the recipient

To recognize the different stages of the chat flow, I used the first word as indicators to save the message string into the correct variable (“friend: “, “link: “). Here is an excerpt of the code:

const message = event.message.text;

var incoming = message.split(":");

if (incoming[0] == "Friend" || incoming[0] == "friend") {

friend_name = incoming[1];

module.exports.friend_name = incoming[1];


The bot’s replies are a mix of hardcoded and trained responses. “Preface” in the code below are hardcoded responses, and it is appended to Dialogflow’s trained responses.

const result = preface + response.result.fulfillment.speech;

sendTextMessage(senderId, result);

Scrape input article and upload a white-labeled version

After an article link has been input, the server then does an http GET request on the link. The incoming data is processed using the Cheerio library, so that I could select the exact elements to be uploaded to the white-labeled version. The white-labeling is intentional so that the payee would not be affected by their pre-existing biases towards a publication.

As different publishers use different class and id names for their HTML elements, the program now only recognizes headlines and body texts from HuffPost. The processed text is then rendered on a custom webpage.

function getArticle(url, senderId, friend_ID) {

request(url, function(error, response, html) {

if (!error && response.statusCode == 200) {

var $ = cheerio.load(html);

headline = $('.headline__title').text();

subheadline = $('.headline__subtitle').text();

var paragraphs = [];

$('.content-list-component').each(function(i, elem) {

var text = $(this).text();

text = text.replace(/(\r\n\t|\n|\r\t)/gm,"");



var article = {

headline: headline,

subheadline: subheadline,

paragraphs: paragraphs


res.render('article.ejs', { article: article });

var message = "I will send < " + headline + " > to " + friend_name;

sendTextMessage(senderId, message);




Notify payee on Facebook Messenger

As long as the intended recipient has liked Attention Exchange page, the payer could choose anyone to be the payee. And once the article has been scraped, a link will be sent to the recipient.

var notif = "Hi "+ friend_name +"! " + first_name + " would like to pay you $7 to read an article: " + headline;

notif = notif + " Here is the link: https://ce8fd8b3.ngrok.io/article";

sendTextMessage(friend_ID, notif);

Verify readership via timed buttons

TheThe last element in the prototype is to verify payee’s readership of the article. Ideally, there would be a simple quiz based on the first sentence of a randomized paragraph, but in this iteration the readership was approximated by timed buttons. The scraped article is broken down into 3 sections and to progress to the next section, the payee has to wait for a certain amount of time first.

V. Reflections & Future Work

The following features need to be built into Attention Exchange before it is ready to be released publicly:

  • Payment capabilities via Facebook payments & PayPal

  • A quiz module to verify article comprehension

  • Work around or with publisher’s paywall

  • Better trained responses

  • In the case of a recipient who has not liked Attention Exchange’s page, give the option to payer to send an invite instead, either on Facebook or other channels like text or email.

Lastly, once the bot is released, I am interested in monitoring the usage and what the users get out of it. The questions I have are:

  1. What are the use-cases of Attention Exchange? Are the payers of a different ideological view than the payees?

  2. What is the average price put on readership?

  3. Does using Attention Exchange facilitate more leveled conversations across the political or ideological affiliation?

  4. Does reading white-labeled articles or the action of ideologically giving in for an incentive help in changing one’s pre-existing beliefs?


  1. Taber, Charles S. and Milton Lodge (2006). “Motivated Skepticism in the Evaluation of Political Beliefs.” American Journal of Political Science 50(3): 755-769.

  2. Nyhan, B., & Reifler, J. (2010). When Corrections Fail: The Persistence of Political Misperceptions. Political Behavior, 32(2), 303-330. doi:10.1007/s11109-010-9112-2

  3. https://medium.com/crowdbotics/how-to-create-your-very-own-facebook-messenger-bot-with-dialogflow-and-node-js-in-just-one-day-f5f2f5792be5

#Chatbot #NodeJS #Dialogflow #Scraper

Related Posts
Recent Posts
Search By Tags
No tags yet.

Hafiyyandi | Creative Technologist

New York, New York | hafiyyandi@gmail.com