Пример #1
0
        public async Task <FulfillmentResponse> FulfillAsync(FulfillmentRequest fulfillmentRequest, IJobberClient jobberClient)
        {
            var serviceName        = fulfillmentRequest.GetParameter(Constants.Variables.ServiceName);
            var newUnitPrice       = fulfillmentRequest.GetParameterAsDouble(Constants.Variables.Price);
            var modifyQuoteContext = fulfillmentRequest.GetContextParameterAs <ModifyQuoteContext>(
                Constants.Contexts.QuoteDetailsSet, Constants.Variables.ModifyQuoteContext);

            var modifiedQuote = UpdateServicePriceInQuote(modifyQuoteContext.Quote, serviceName, newUnitPrice);

            await jobberClient.UpdateQuoteAsync(modifiedQuote);

            return(FulfillmentResponseBuilder.Create()
                   .Speech("Okay. I've updated the quote for you.")
                   .Build());
        }
        public async Task <FulfillmentResponse> FulfillAsync(FulfillmentRequest fulfillmentRequest, IJobberClient jobberClient)
        {
            var jobDateTimeRange     = GetDateTimeRangeForJobFrom(fulfillmentRequest);
            var createJobDescription = fulfillmentRequest.GetParameter(Constants.Variables.JobDescription);
            var createJobContext     = fulfillmentRequest.GetContextParameterAs <CreateJobContext>
                                           (Constants.Contexts.CreateJobClientSet, Constants.Variables.CreateJobContext);

            var createJobRequest = new CreateJobRequest
            {
                ClientId    = createJobContext.Client.Id,
                PropertyId  = createJobContext.Property.Id,
                StartAt     = jobDateTimeRange.Start.ToUnixTime(),
                EndAt       = jobDateTimeRange.End.ToUnixTime(),
                Description = createJobDescription
            };

            await jobberClient.CreateJobAsync(createJobRequest);

            return(FulfillmentResponseBuilder.Create()
                   .Speech(BuildResponseFrom(fulfillmentRequest))
                   .WithMessage(BuildGoogleCardFrom(createJobContext, createJobDescription))
                   .MarkEndOfAssistantConversation()
                   .Build());
        }