private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result) { var activity = await result as Activity; var reply = context.MakeMessage(); if (activity.Value != null) { var activityValue = activity.Value.ToString(); IotMessage serializedEntity = JsonConvert.DeserializeObject <IotMessage>(activityValue); SendDataToFunction(serializedEntity.lightName, serializedEntity.lightStatus); reply.Text = "Listo! Tu comando está hecho"; } else { if (activity.Text.ToLower() == "arriba" || activity.Text.ToLower() == "abajo") { string levelSelector = activity.Text; HttpClient client = new HttpClient(); HttpResponseMessage response; AdaptiveCard card = new AdaptiveCard(); response = await client.GetAsync(String.Format("http://aminespinoza.com/docs/tarjeta{0}.json", levelSelector)); var json = await response.Content.ReadAsStringAsync(); AdaptiveCardParseResult resultString = AdaptiveCard.FromJson(json); card = resultString.Card; IList <AdaptiveWarning> warnings = resultString.Warnings; Attachment attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = card }; reply.Attachments.Add(attachment); } else { reply.Text = "Por favor, dime a qué piso quieres acceder"; } } await context.PostAsync(reply); context.Wait(MessageReceivedAsync); }
public static async Task Run([IoTHubTrigger("messages/events", Connection = "NerdostatD2C")] EventData message, ILogger log) { IotMessage msg = JsonConvert.DeserializeObject <IotMessage>(Encoding.UTF8.GetString(message.Body.Array)); log.LogMetric("Temperature", msg.Temperature); log.LogMetric("Humidity", msg.Humidity); log.LogMetric("Setpoint", msg.CurrentSetpoint); log.LogMetric("HeaterOn", msg.HeaterOn); HttpClient pbi = new HttpClient(); var pBiEndpoint = System.Environment.GetEnvironmentVariable("PowerBiEndpoint"); if (!string.IsNullOrWhiteSpace(pBiEndpoint)) { await pbi.PostAsync <List <IotMessage> >( pBiEndpoint, new List <IotMessage>() { msg }, new JsonMediaTypeFormatter() ); } }