Created
December 2, 2018 22:36
-
-
Save irwinwilliams/64d3d418ae530e3d4cd9d30add7e7afb to your computer and use it in GitHub Desktop.
Function - Webhook to enqueue a message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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