Skip to content

Instantly share code, notes, and snippets.

@irwinwilliams
Created December 2, 2018 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irwinwilliams/64d3d418ae530e3d4cd9d30add7e7afb to your computer and use it in GitHub Desktop.
Save irwinwilliams/64d3d418ae530e3d4cd9d30add7e7afb to your computer and use it in GitHub Desktop.
Function - Webhook to enqueue a message
[FunctionName("GoogleActions")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[Queue("changevmstate")] out string state,
ILogger log)
{
state = null;
try
{
string requestBody = new StreamReader(req.Body).ReadToEnd();
var data = JsonConvert.DeserializeObject<Request>(requestBody);
log.LogInformation(requestBody);
var query= data.queryResult.queryText;
dynamic actionResult = new ExpandoObject();
string result = string.Empty;
if (data.queryResult.intent.displayName == "ChangeVMState")
{
state = data.queryResult.parameters.vmstate;
result = $"{state} is going to be applied, Irwin";
actionResult.fulfillmentText = result;
}
actionResult.source = botId;
var output = JsonConvert.SerializeObject(actionResult,
Formatting.Indented, new AtAtJsonConverter(typeof(ExpandoObject)));
return output != null
? (ActionResult)new JsonResult(actionResult)
: new BadRequestObjectResult("ERROR: "+output);
}
catch (Exception ex)
{
log.LogError(ex, ex.Message);
return new BadRequestObjectResult("Badness");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment