Пример #1
0
        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);
        }
Пример #2
0
        internal static GoogleCloudDialogflowV2WebhookResponse ModelToDialogFlow(BotModel botModel)
        {
            var response = new GoogleCloudDialogflowV2WebhookResponse()
            {
                FulfillmentText = botModel.Response.Text,
                Source          = "BookAtableBot",
            };

            return(response);
        }
Пример #3
0
        public ActionResult <GoogleCloudDialogflowV2WebhookResponse> Post([FromBody] GoogleCloudDialogflowV2WebhookRequest request)
        {
            //request.QueryResult.Parameters
            //DialogflowBaseServiceRequest req = new

            var response = new GoogleCloudDialogflowV2WebhookResponse()
            {
                FulfillmentText = "Hello from " + request.QueryResult.Intent.DisplayName
            };

            return(response);
        }
Пример #4
0
        public GoogleCloudDialogflowV2WebhookResponse Index()
        {
            var mvcName = typeof(Controller).Assembly.GetName();
            var isMono  = Type.GetType("Mono.Runtime") != null;
            GoogleCloudDialogflowV2WebhookResponse firstres = new GoogleCloudDialogflowV2WebhookResponse();

            firstres.FulfillmentText = "Test first";
            ViewData["Version"]      = mvcName.Version.Major + "." + mvcName.Version.Minor;
            ViewData["Runtime"]      = isMono ? "Mono" + DateTime.Now.ToString("hh:mm:ss") : ".NET";
            //return View();
            return(firstres);
        }
Пример #5
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]
            HttpRequest req
            )
        {
            var idb                = new Islaam.Database();
            var requestBody        = await new StreamReader(req.Body).ReadToEndAsync();
            var fulfillmentRequest = JsonConvert.DeserializeObject <GoogleCloudDialogflowV2WebhookRequest>(requestBody);
            var intent             = fulfillmentRequest.QueryResult.Intent.DisplayName;
            var entities           = fulfillmentRequest.QueryResult.Parameters;
            var handler            = GetHandler(idb, intent, entities);

            // if person found
            var response = new GoogleCloudDialogflowV2WebhookResponse
            {
                FulfillmentMessages = new List <GoogleCloudDialogflowV2IntentMessage>
                {
                    // facebook
                    new GoogleCloudDialogflowV2IntentMessage
                    {
                        Platform     = "FACEBOOK",
                        QuickReplies = new GoogleCloudDialogflowV2IntentMessageQuickReplies
                        {
                            QuickReplies = handler.QuickReplies,
                            Title        = handler.TextResponse
                        },
                    },
                    // web
                    new GoogleCloudDialogflowV2IntentMessage
                    {
                        Platform = null,
                        Text     = new GoogleCloudDialogflowV2IntentMessageText
                        {
                            Text = new List <string> {
                                handler.TextResponse
                            },
                        }
                    },
                }
            };

            return(new OkObjectResult(response));
        }