Update: Bot Print has been deactivated. But this post will be useful to anybody who wishes to create your own Print to Walgreens chapp.

While there are many resources on the inter-web for building a vast array of interesting products, I thought I’d add this little post to the mix. Bot Print is our first foray into Chapps (In-Chat-Apps, Bots, Chat Bots, or whatever term tickles your fancy).

Bot Print came about after we stumbled across info about Facebook releasing an offical API for their Messenger platform. This post is a quick howto to bot building.


To quote the spiel from the Bot Print page

Walgreens prints from Facebook Messenger. Send pictures to Walgreens. Prints ready in 1 hr. Nothing could be easier.
Bot Print is a port of our Drag Drop Photo Print Mac app that we released in 2013. For the hyperlink adverse reader; Drag Drop Photo Print was a desktop app that gave the user the ability to print any image, from source, anywhere on the planet, directly at their local Walgreens. Pick up is suggested at 1 hour after submission, but we have it from various sources that processing is a lot faster than that.


To build Bot Print, the following technologies were used:

Firstly, read the docs. The docs for the Messenger platform and the Walgreens API. I won’t be going into how, what, where, why of setting them up or configuring them. But I will say, it’s extremely easy.

To start, let’s set up our local environment, starting with RethinkDB. _You could use Redis, or MongoDB, but where’s the fun in that? _RethinkDB is the new kid on the block and is suited to what we’re building here. That being, a simple messaging app.

RethinkDB is a cinch to install and configure…

tcp@home:~$ brew update
tcp@home:~$ brew install rethinkdb
tcp@home:~$ alias rethinkdb.start='launchctl load /usr/local/opt/rethinkdb/homebrew.mxcl.rethinkdb.plist'
tcp@home:~$ alias rethinkdb.stop='launchctl unload /usr/local/opt/rethinkdb/homebrew.mxcl.rethinkdb.plist'
tcp@home:~$ source ~/.bash_aliases
Node.js is the same...
tcp@home:~$ brew update
tcp@home:~$ brew install node
tcp@home:~$ node -v
tcp@home:~$ npm -v
Well heck, it's 2016, everything is easier to install and Ngrok is no exception...
tcp@home:~$ wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-darwin-amd64.zip
tcp@home:~$ unzip ngrok-stable-darwin-amd64.zip
tcp@home:~$ ./ngrok http 80

Ngrok is needed because, not only are we setting this up locally, but Facebook requires HTTPS to communicate with the our chapp and that’s not something any sane developer wants to setup when creating new products.

Bot Print 101

Now that the environment is sorted, we just need to create our working folder and initial files.

tcp@home:~$ mkdir BotPrint; cd BotPrint
tcp@home:~$ touch package.json
tcp@home:~$ touch bot-print.js
tcp@home:~$ touch db.js

Add the following to the package.json file.

  "name": "BotPrint",
  "version": "1.0.0",
  "description": "howto BotPrint in a million easy steps",
  "main": "bot-print.js",
  "author": "TCP @ Splace",
  "dependencies": {
    "botkit": "0.1.1",
    "node-libcurl": "0.9.0",
    "phpdate-js": "1.0.2",
    "rethinkdb": "2.3.1",
    "debug": "0.7.4"

Then install (ignore any warnings)

tcp@home:~$ npm install
> node-libcurl@0.9.0 install ~/BotPrint/node_modules/node-libcurl
> node-pre-gyp install --fallback-to-build

[node-libcurl] Success: "~/BotPrint/node_modules/node-libcurl/lib/binding/node_libcurl.node" is installed via remote

Botkit does most of the magic. node-libcurl and phpdate-js are needed for connecting to the Walgreens API. rethinkdb provides the connection with our data store of user provided photos.

RethinkDB “queries” are all rather standard, so instead of having me explain anything (read the docs), here’s the contents for the db.js file…
[gist https://gist.github.com/Tumunu/9cf724c18eb1d5a94ba16026118b55e7]


As you might have realised, the bot-print.js file is the actual chapp. The body, not the brains, because the chapp isn’t going to use sentiment analysis. Scanning user messages for key words is more than adequate.

So let’s get started…

var Botkit = require('botkit');
var db = require('./db.js');

var accessToken = "facebook-token"
var verifyToken = "my-token"
var botPort = 123456

var controller = Botkit.facebookbot({
    debug: true,
    imageCount: 0
    access_token: accessToken,
    verify_token: verifyToken

var bot = controller.spawn({})

controller.setupWebserver(botPort || 3000, function(err, webserver) {
    controller.createWebhookEndpoints(webserver, bot, function() {});

And that’s it. Bot Print is alive!

The _accesstoken is the token you get when you’ve set up your bot on the Facebook Messenger Platform. The _verifytoken is your private chapp token. To generate one, use Github.

Next steps

Bot Print may be alive, but at the moment it is as dumb as it is pointless. So in the next post, we’ll create the integration with the Walgreens API and add a couple keywords for Bot Print to listen out for.

Want to work with me?

Let's Talk!

Recently I've worked with ...