Friday, November 20, 2015

I wanted to get Hubot working in our slack channels at work and I thought I would share the process I took to get it working and running on Azure Websites.

First, make sure you have nodejs installed

> choco install nodejs.install -y

Make sure npm is up to date

> npm install -g npm

At this point, I also installed coffee-script because the first time I tried running it, I got errors about coffee script

> npm install -g coffee-script

Install the azure-cli node modules to generate the deploy file that will be used

> npm install –g azure-cli

Next we install the yo hubot generator

> npm install –g yo generator-hubot

create a directory for your hubot. I have found that you should not initially name it “hubot”, as npm will fail with some of the package installs (specifically, the hubot package). Then lets start the hubot configuration

> mkdir myhubot

> cd myhubot

> yo hubot

Now you will answer the question it asks to configure hubot. Again, I wouldn’t name it “hubot” when it asks. I will show you where to change it later so it will respond to hubot.

Mine showed some error messages while running this, but still functioned correctly.

Now lets install the slack adapter

> npm install hubot-slack --save

next we need to create the azure deploy command.

> azure site deploymentscript –node

lets now make a couple tweaks to the hubot files:

first, open up external-scripts.json and remove

"hubot-heroku-keepalive",

"hubot-redis-brain"

if you want to use azure blob for the brain we can set that up now. while still in the external-scripts.json, add the line:

Login to your Azure portal and create a new Web App: (The name has to be unique)

If you are using Azure blob for the brain, create the storage account as well.

After the storage is created, we will need the Storage Account Name, and Primary Access Key. Copy these for use a little later:

Go in to the settings for your newly created web app and click on “Continuous Deployment”. We are going to configure Azure Web Site to pull directly from the Github repo for the hubot configuration.

Choose Github as the provider and then authorize Azure to connect. Then choose your Hubot

Finally we have to set up the environment variables that Hubot needs to function:

You will create the following keys:

HUBOT_SLACK_TOKEN: Your Slack Token for Hubot when you enable the integration

HUBOT_SLACK_TEAM: myslack (from https://myslack.slack.com)

HUBOT_SLACK_BOTNAME: The name of your hubot

HUBOT_ADAPTER: slack

HUBOT_BRAIN_AZURE_STORAGE_ACCOUNT: The storage account name we saved from above

HUBOT_BRAIN_AZURE_STORAGE_ACCESS_KEY: The storage access token we saved from above

Go to your webapp to test that your hubot is working.

http://myhubot1.azurewebsites.net/hubot/help

Sometimes it doesn’t respond the first time, but if it continues to fail when requesting, there there may be an issue. Try running locally (you will have to remove the azure-blob when running local) and see if everything is working.

Friday, November 6, 2015

If you are familiar with .bash_history or just wish you had a history of your powershell commands persist between sessions here is a handy little script. It will persist command history when you exit a powershell session to a file in %USERPROFILE% called .ps_history.

Copy the code below and save to a file called “Microsoft.PowerShell_profile.ps1” and save it in “%USERPROFILE%\Documents\WindowsPowerShell”

I wanted to get Hubot working in our slack channels at work and I thought I would share the process I took to get it working and running on Azure Websites.

First, make sure you have nodejs installed

> choco install nodejs.install -y

Make sure npm is up to date

> npm install -g npm

At this point, I also installed coffee-script because the first time I tried running it, I got errors about coffee script

> npm install -g coffee-script

Install the azure-cli node modules to generate the deploy file that will be used

> npm install –g azure-cli

Next we install the yo hubot generator

> npm install –g yo generator-hubot

create a directory for your hubot. I have found that you should not initially name it “hubot”, as npm will fail with some of the package installs (specifically, the hubot package). Then lets start the hubot configuration

> mkdir myhubot

> cd myhubot

> yo hubot

Now you will answer the question it asks to configure hubot. Again, I wouldn’t name it “hubot” when it asks. I will show you where to change it later so it will respond to hubot.

Mine showed some error messages while running this, but still functioned correctly.

Now lets install the slack adapter

> npm install hubot-slack --save

next we need to create the azure deploy command.

> azure site deploymentscript –node

lets now make a couple tweaks to the hubot files:

first, open up external-scripts.json and remove

"hubot-heroku-keepalive",

"hubot-redis-brain"

if you want to use azure blob for the brain we can set that up now. while still in the external-scripts.json, add the line:

Login to your Azure portal and create a new Web App: (The name has to be unique)

If you are using Azure blob for the brain, create the storage account as well.

After the storage is created, we will need the Storage Account Name, and Primary Access Key. Copy these for use a little later:

Go in to the settings for your newly created web app and click on “Continuous Deployment”. We are going to configure Azure Web Site to pull directly from the Github repo for the hubot configuration.

Choose Github as the provider and then authorize Azure to connect. Then choose your Hubot

Finally we have to set up the environment variables that Hubot needs to function:

You will create the following keys:

HUBOT_SLACK_TOKEN: Your Slack Token for Hubot when you enable the integration

HUBOT_SLACK_TEAM: myslack (from https://myslack.slack.com)

HUBOT_SLACK_BOTNAME: The name of your hubot

HUBOT_ADAPTER: slack

HUBOT_BRAIN_AZURE_STORAGE_ACCOUNT: The storage account name we saved from above

HUBOT_BRAIN_AZURE_STORAGE_ACCESS_KEY: The storage access token we saved from above

Go to your webapp to test that your hubot is working.

http://myhubot1.azurewebsites.net/hubot/help

Sometimes it doesn’t respond the first time, but if it continues to fail when requesting, there there may be an issue. Try running locally (you will have to remove the azure-blob when running local) and see if everything is working.

If you are familiar with .bash_history or just wish you had a history of your powershell commands persist between sessions here is a handy little script. It will persist command history when you exit a powershell session to a file in %USERPROFILE% called .ps_history.

Copy the code below and save to a file called “Microsoft.PowerShell_profile.ps1” and save it in “%USERPROFILE%\Documents\WindowsPowerShell”