public async Task Connected_PublishAsync_NoException() { await _mqtt.ConnectMqttAsync(); await _mqtt.PublishAsync("test", "test"); Assert.True(true); }
public async Task <GoogleCloudDialogflowV2WebhookResponse> HandleAsync(string json) { //GoogleCloudDialogflowV2WebhookRequest does not contain endInteraction field //this is why raw parsing needed =( dynamic rawJson = JObject.Parse(json); var isEndInteraction = rawJson?.queryResult?.intent?.endInteraction == true; var payload = new Dictionary <string, object> { { "google", new { expectUserResponse = !isEndInteraction } } }; var request = JsonConvert.DeserializeObject <GoogleCloudDialogflowV2WebhookRequest>(json); var intentName = request?.QueryResult?.Intent?.DisplayName; _logger.LogDebug("{IntentName}", intentName); if (string.IsNullOrWhiteSpace(intentName)) { _logger.LogWarning("No intent name in request"); return(new GoogleCloudDialogflowV2WebhookResponse { FulfillmentText = request?.QueryResult?.FulfillmentText ?? string.Empty, Payload = payload }); } var mqttIntent = await _intentStore.FindAsync(intentName); if (mqttIntent == null) { _logger.LogWarning("No Mqtt Intent found in store for {name}", intentName); return(new GoogleCloudDialogflowV2WebhookResponse { FulfillmentText = request.QueryResult?.FulfillmentText ?? string.Empty, Payload = payload }); } await _mqtt.PublishAsync(mqttIntent.Topic, mqttIntent.TranslateMqttMessage(request.QueryResult.Parameters)); var response = new GoogleCloudDialogflowV2WebhookResponse { FulfillmentText = mqttIntent.TranslateResponseMessage(request.QueryResult), Payload = payload }; return(response); }
public Task SetTemperatureAsync(int scheduledEventId, string heatingZoneCode, string?heatingZoneName, double temperature) { var payload = new { scheduledEventId, heatingZoneCode, heatingZoneName, temperature }; string topic = $"thermostat/{heatingZoneCode}/set-temperature"; return(mqttPublisher.PublishAsync(topic, payload.ToJsonString())); }