Author: Shivani Negi

How to Build a Slackbot + Deploy an App to Heroku for Absolute Beginners

Back in ye olde days of the internet, there was IRC (Internet Relay Chat), a chat network with channels and servers for every microcosm in the world. Folks would make these little bots or services—they’d greet you when you joined a channel, played trivia, Uno and other chat-based games with you. Unfortunately, if you wanted to make one yourself, you likely needed some knowledge of Perl, client-server architecture and a handful of Unix commands.

Today, most will opt for a more aesthetic alternative to IRC. Namely, Slack—a chat-based team communication tool. The best part? You can create a Slackbot with substantially fewer roadblocks.

I’ll try not to make assumptions on the technologies you may or may not have on your machine here. So let’s go ahead and start from scratch. If you already have any or all of following downloaded, you’re ahead of the game!


Setup

1. Install Node.js and npm

Mac
Go to nodejs.org, Click ‘install’, and run through the install process.

Ubuntu
You should be able to use the following:

curl -sL https://deb.nodesource.com/setup_0.10 | sudo -E bash -
sudo apt-get install -y nodejs

More at https://github.com/nodesource/distributions#deb

Windows
Go ahead the download the Windows binary

2. Create a Github account (https://github.com/) and download git (http://git-scm.com/download)

3. Clone this repository https://github.com/ceejbot/LOUDBOT-SLACK by using the following command in your terminal:

git clone git@github.com:ceejbot/LOUDBOT-SLACK.git

4. Create an account and download Heroku on your machine https://toolbelt.heroku.com/

Pheew. Now that we have all that installed, on with the tutorial!

 

Add Slack Tokens to App

1. Go into your Slack group, click on the caret and then “Configure Integrations” in the dropdown

slack-screenshot

2. Under ‘All Integrations’ → ‘DIY Integrations & Customizations’, click on ‘Outgoing WebHooks’

slack-outgoing-webhooks

3. The next screen should look like the following. Go ahead and click on ‘Add Outgoing WebHooks Integration’

slack-webhooks-add

4. Set the channel to the specific channel you would like your slackbot to be active on, and copy the corresponding token (Rest assured, we’ll be able to add our slackbot on multiple channels. We’ll get to that in a bit)

token-slack

5. Open a terminal and navigate to the directory you cloned and use the following command to create your own file to store environment variables. You should note that your .gitignore includes this .env file.

cat .env.example > .env

6. Next, using a text editor of your choice, open the loudbot directory

7. Open .env and replace the contents of TOKENS with the token you copied from slack. Now I’d promised you could add loudbot to multiple channels. To do this, repeat the above steps to add outgoing webhook integrations for as many channels are you would like. Just remember to copy the corresponding tokens into the TOKENS list in .env.

8. To complete the SLACK_TOKEN field, we’ll have to revisit the Slack ‘Configure Integrations’ page. Under ‘DIY Integrations & Customizations’, there should be a service called ‘Bots’

slack_bots_section

9. Create a new Bot, name it ‘LOUDBOT’ and copy the ‘API TOKEN’ under Integration Settings into the SLACK_TOKEN field in your .env file.

 

Deploying Slackbot to Heroku

1.Next we need put loudbot on a server so it can constantly be listening and responding to our Slack messages.

2. Create a file entitled ‘Procfile’ without a file extension. This is the file that tells Heroku what commands to use to run your application. The contents of the file are a single line that should be the following:

Procfile

3. Finally, in your terminal, within your loudbot repository, run the following Heroku commands.

heroku create

This will create a new heroku app (note you can only have a max of 5 heroku apps on the free plan). Git remotes are references to remote repositories and this command will also create a git remote you can reference as ‘heroku’ on the command line.

git add
git commit -m "my commit message"

These are git commands for that’ll help track your changes to the app. They will commit your changes to your local directory, in preparation for deploying your app to Heroku.

git push heroku master

This will actually push your app to Heroku.

And there you have it—your app is live. LOUDBOT learns from your shouting and you can talk with LOUDBOT in any channel it is active in using all-caps. Enjoy!

loudbot-better-screenshot

Challenging Diversity at NodeConf

nodeconf

At npm everyone cares a great deal about workplace diversity. It’s a privilege to work in such a positive environment and in truth, I haven’t been the best advocate for diversity. Now, I know what you’re thinking: “but Shivs, you’re a woman interning in the ‘Tech Mecca.'” I’m entirely an edge-case when it comes to most women pursuing careers in technology. My parents have PhD’s in CS and my community has been nothing but supportive; we could argue I was fated to be a developer from the womb. I simply haven’t been exposed to many of the difficulties minorities face in this industry. Now despite my lack of roadblocks, I’ve still managed to happen upon a single, self-important thorn in my career path—namely, the rise of the “brodom.”

Let’s take this back to last summer. I remember walking into the stunning office of my first real internship—tall glass windows, fully stocked kitchen, giant redbull vending machine, even a game room equipped with two ping-pong tables. It all seemed promising. Fourteen engineers greeted me and I hardly noticed I was the only woman in the room. That was until my co-worker found it timely to announce, “looks like we gotta stop with the dick jokes, huh?”.  I laughed off many of these insults throughout the summer. A further snub, I’m not trained as a designer but spent the summer completing what were mostly front-end tasks thrown at me. Moreover, while the specifics I’ll refrain from sharing, I can understand how it proves to be difficult keeping matters in professional scope because workplaces also lend themselves to social interactions. However, unwarranted remarks and general disrespect for personal decisions in the workplace undermines one’s agency and marginalizes community members. In all honesty, I found it easier to join the “brodom” than to fight it. I cast my dresses and skirts into the depths of my closet in exchange for hackathon t-shirts and jeans. The less attention I could bring to myself, the better. The tipping point of all this came when I was rushed to the hospital during the last week of the internship. All it took was a trip to the emergency room to leave my sense of self-worth even more dire. This was the beginning of my concerns with diversity in our community.

In our industry, we’re all encouraged to be insufferable smart-asses.  Humans, and developers in particular, fail to decouple pride from their interactions. Moreover, we tell those afflicted to “toughen up” instead of confronting the problem directly. On the internet, with increased anonymity, it’s easy to be overbold. The consequence? It’s incredibly disheartening, in the open-source community for instance, for an enthusiastic new contributor to be shut down by a matter-of-fact thread of comments. Being well acquainted with many of these issues, I decided to attend a diversity forum at NodeConf (nodeconf.com) last week with my co-workers from npm. The first of these sessions was very tense; we essentially threw a mob of passionately opinionated people into a room and awaited the impending chaos. The following discussions held much greater resolve and succeeded in creating a document (soon to be released to the public) acknowledging issues and actionable goals for the coming year. A few of my takeaways:

 

1. Realizing We All Have a Shared Vulnerability

The tech industry is a heated contest; everyone feels the pressure to one-up each other, but we must resist the need to be self-defensive at the cost of another. It is imperative we be welcoming and use actionable criticism. At times it can be difficult to keep our interactions in-scope of our contributions to the community. However, it is crucial to respect personal decisions and avoid undermining a person’s prerogative.

2. Collaboration > Competition

In truth, competition isn’t entirely detrimental to workplace culture. One could argue that “healthy” competition is more than acceptable. But, if said competition begins to pose a problem, for goodness sake, please dial it back.

3. Leading by Example

Community leaders have to be exemplars of inclusive practices, perhaps even held to a higher standard. At the first of the diversity discussions at NodeConf, some of my co-workers spoke openly about our company’s opt-in policy of “the guys jar”. Anyone who chooses to participate donates $1 to the jar every time they uses the term “guys” over a whole slew of other options—”folks,” “people,” “everyone”…etc. The policy was received with all sorts of opposition, even an offensive note sent to the company email.

4. Trust the “Ouch”

If a community-member reports an issue that defies your own world-view, don’t ignore it. For example, many npm users will submit complaints regarding difficulties using npm on a Windows machine. Problems using Windows is something of a cultural joke. So, it’s easy to dismiss these complaints because we—via only our own circumstances—have survived thus far unobstructed; this does not promote diversity nor an inclusive culture. At npm, we’ve identified this as being unproductive and have therefore put some effort into resolving Windows users’ concerns. As a general rule please listen first, hear second, respond third.

 

NodeConf was an overwhelming and powerful experience. I met so many of my idols—Node core maintainers, GitHub usernames I stalk on a daily basis, and the creators of projects that revolutionized uses of Javascript. The attendees were all from vastly different backgrounds; developers from Amsterdam, London, all over Latin America, and every corner of the States flew in to attend. It was incredible to witness the diversity and be able to translate the online community to a physical one.

I was floored by the immense support and willingness to mentor each other. Since all the attendees were dropped off in middle-of-nowhere N. California and forced to spend four days in close-quarters, it was also a great opportunity to get to know my co-workers. I’ll brag on their behalf since I still can’t believe I share an office with so much of Node-fame. I spent the weekend working on a personal project and had a whole body of JavaScript knowledge within arms-reach—forget Stack Overflow.  Mentors are truly game-changers for anyone young and ambitious. In fact, immaturity and naive oversight are likely the biggest offenders of diversity concerns. With a bit of guidance we realize that, overzealous and with a handful of successes, we’ve allowed ourselves to think we’re better than the whole lot. Let’s set Ego aside. It is incredibly important that new contributors to the open-source community have great role models and examples of inclusivity set for them. I’m dedicated to making sure this community prospers and I couldn’t have asked for a better lesson in what’s required of me. Thank you, npm and NodeConf.

 

nodeconf3