Slack – Azure – Raspberry Pi – episode 2

I’ve started my journey with downloading some sample code from Igal Tabachnik – xkcd slackbot ( Because I had no: experience in C#, visual studio on my computer, any idea how should it be deployed, I thought it will be fun. And it indeed was.

After getting sources of Igal’s bot, I’ve looked into the structure of (?) project. To make it working I needed some server environment. I’ve created new app service on my azure account. After that I had to rewrite xkcd bot to connect with my previously created azure service bus. To do it, I’ve used my favourite text editor (Sublime) and refactored Igal’s code. I had to edit all those configs etc manually, without visual studio’s help 😉
It was fun because I couldn’t test the solution on my local machine. After few tries I’ve managed that I can deploy my app using git directly on azure.

 git push azure master

And we’re home 😉 Here’s the final code of my controller with pushing call from slack to service bus queue (which is used by my pythin script on raspberry pi ;)):

using System;
using System.Configuration;
using System.Linq; 
using System.Net;
using System.Text;
using System.Threading.Tasks; 
using System.IO;
using System.Xml.Serialization;
using Nancy;
using Nancy.ModelBinding;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.ServiceBus.Messaging;
namespace SlackAzureServiceBus
 public class SlackRequest
 public string Token { get; set; }
 public string Command { get; set; }
 public string Text { get; set; }
 public string Channel_Name { get; set; }
 public string User_Name { get; set; }
 public class SlackAzureServiceBusModule : NancyModule
 public SlackAzureServiceBusModule() : base("/officer")
 StaticConfiguration.DisableErrorTraces = false;
 Post["/", runAsync: true] = async (_, ct) =>
 var request = this.Bind<SlackRequest>();
 if (request.Token != ConfigurationManager.AppSettings["SLACK_SLASH_COMMAND_TOKEN"])
 return 403;
if (request.Command != "/officer") return 400;
var connectionString = ConfigurationManager.AppSettings["SERVICE_BUS_CONNECTION"];
 var queue = QueueClient.CreateFromConnectionString(connectionString, ConfigurationManager.AppSettings["SERVICE_BUS_QUEUE"]);
 var payload = Newtonsoft.Json.JsonConvert.SerializeObject(request);
var payloadStream = new MemoryStream(Encoding.UTF8.GetBytes(payload));
 queue.Send(new BrokeredMessage(payloadStream,true));

return 200;

Last things I had to add to my azure app were the custom configuration fields.

Zrzut ekranu 2016-04-03 21.40.12

To access custom fields you can simply use:


It was quite easy to manage how to make azure app work (and it was my first time). This part of project has taught me a lot 😉