#r "Newtonsoft.Json"
using System.Net;
using System.Net.Http;
using Newtonsoft.Json;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
var myObj = new {hub_challenge="hub.challenge" };
var errObj = new {response="noresponse" };
// parse query parameter
string HUB_MODE = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "hub.mode",true) == 0)
.Value;
string VERIFY_TOKEN = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "hub.verify_token", true) == 0)
.Value;
string ACCESS_TOKEN = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "ACCESS_TOKEN", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
var jsontoreturn = (HUB_MODE == "subscribe" && VERIFY_TOKEN == "12345")
? JsonConvert.SerializeObject(myObj)
: JsonConvert.SerializeObject(errObj);
return req.CreateResponse(HttpStatusCode.OK, jsontoreturn, "application/json");
}