private static FulfillmentResponse BuildVisitFoundResponse(Visit visit)
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech(BuildResponseFrom(visit))
            .WithMessage(BuildGoogleCardFrom(visit))
            .Build());
 }
 private static FulfillmentResponse BuildNoVisitsCompletableResponse()
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech("No visits need to be completed right now.")
            .MarkEndOfAssistantConversation()
            .Build());
 }
        public async Task <FulfillmentResponse> FulfillAsync(FulfillmentRequest fulfillmentRequest, IJobberClient jobberClient)
        {
            var datePeriod = GetDatePeriodForRevenueFrom(fulfillmentRequest);
            var timeUnit   = fulfillmentRequest.GetParameter(Constants.Variables.TimeUnitOriginal);

            if (string.IsNullOrEmpty(timeUnit))
            {
                timeUnit = "last week";
            }

            var getTransactionRequest = new GetTransactionRequest
            {
                Start    = datePeriod.Start,
                End      = datePeriod.End,
                TimeUnit = timeUnit
            };

            var Transactions = await jobberClient.GetRangedTransactionsAsync(getTransactionRequest);

            decimal revenue = Transactions.GetTotal();

            if (timeUnit.EndsWith("?"))
            {
                timeUnit = timeUnit.Remove(timeUnit.Length - 1);
            }

            return(FulfillmentResponseBuilder.Create()
                   .Speech($"We made ${revenue.ToString("N")} {timeUnit}")
                   .Build());
        }
 private static FulfillmentResponse BuildSingleVisitsCompletableResponse()
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech("You have one visit that are ready to be completed. Do you want some details?")
            .WithContext(ContextBuilder.For(Constants.Contexts.AskedIfUserWantsCompletableDetails))
            .Build());
 }
Esempio n. 5
0
        public async Task <FulfillmentResponse> FulfillAsync(FulfillmentRequest fulfillmentRequest, IJobberClient jobberClient)
        {
            var num = fulfillmentRequest.GetParameterAsInt("num");

            return(FulfillmentResponseBuilder.Create()
                   .Speech($"Your favorite number is {num}")
                   .Build());
        }
Esempio n. 6
0
        private static FulfillmentResponse BuildSingleVisitResponseFor(VisitsCollections visitsCollection)
        {
            var visit = visitsCollection.CompletableVisits.First();

            return(FulfillmentResponseBuilder.Create()
                   .Speech(BuildDescriptionFor(visit))
                   .MarkEndOfAssistantConversation()
                   .Build());
        }
Esempio n. 7
0
        private static FulfillmentResponse BuildMultipleClientsFound(string clientName, ClientCollection clientCollection)
        {
            var chipSuggestionMessage = GoogleChipMessage.From(clientCollection.Clients.Select(c => c.Name));

            return(FulfillmentResponseBuilder.Create()
                   .Speech($"There a few people who have a smiliar name to {clientName}, can you be a bit more specific?")
                   .WithContext(ContextBuilder.For(Constants.Contexts.CreateJobClientRequested))
                   .WithMessage(chipSuggestionMessage)
                   .Build());
        }
        private static FulfillmentResponse BuildMultipleCompleteableVisitsResponse(int numCompletableVisits)
        {
            var speech = $"You have { numCompletableVisits } visits that are ready to be completed. " +
                         "Do you want me to list a few?";

            return(FulfillmentResponseBuilder.Create()
                   .Speech(speech)
                   .WithContext(ContextBuilder.For(Constants.Contexts.AskedIfUserWantsCompletableDetails))
                   .Build());
        }
Esempio n. 9
0
        private static FulfillmentResponse BuildMultipleVisitsResponseFor(VisitsCollections visitsCollection)
        {
            var visitDescriptions  = visitsCollection.CompletableVisits.Select(BuildDescriptionFor).Take(3);
            var joinedDescriptions = String.Join(" ", visitDescriptions);

            return(FulfillmentResponseBuilder.Create()
                   .Speech(joinedDescriptions)
                   .MarkEndOfAssistantConversation()
                   .Build());
        }
        public async Task <FulfillmentResponse> FulfillAsync(FulfillmentRequest fulfillmentRequest, IJobberClient jobberClient)
        {
            var userId         = fulfillmentRequest.GetCurrentUserId();
            var userCollection = await jobberClient.GetUserAsync(userId);

            var user = userCollection.Users;
            var chipSuggestionMessage = GoogleChipMessage.From(user.PossibleActions().Values.ToList());

            return(FulfillmentResponseBuilder.Create()
                   .Speech("I have listed some functionalities as suggestions")
                   .WithMessage(chipSuggestionMessage)
                   .Build());
        }
        private static FulfillmentResponse buildMultipleVisitsFoundResponse(VisitsCollections visits)
        {
            StringBuilder sb = new StringBuilder();
            FulfillmentResponseBuilder res = FulfillmentResponseBuilder.Create();

            foreach (Visit visit in visits.Visits)
            {
                res.Speech(BuildResponseFrom(visit));
                res.WithMessage(BuildGoogleCardFrom(visit));
            }
            return(res
                   .Build());
        }
Esempio n. 12
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());
        }
        private static FulfillmentResponse BuildResponseForMultipleMatchesForDeviceWithScreen(
            IEnumerable <Quote> matchingQuotes)
        {
            var quoteSuggestions = matchingQuotes.Select(q => q.QuoteNumber.ToString()).ToList();

            quoteSuggestions.Add("Cancel");

            var suggestionChips = GoogleChipMessage.From(quoteSuggestions);

            return(FulfillmentResponseBuilder.Create()
                   .Speech("A few quotes matched what you said. Here are some of the quote numbers that matched:")
                   .WithContext(ContextBuilder.For(Constants.Contexts.QuoteNumberRequested))
                   .WithMessage(suggestionChips)
                   .Build());
        }
        private static FulfillmentResponse BuildResponseForMultipleMatchesForAudioDevice(
            IEnumerable <Quote> matchingQuotes)
        {
            var commaSeperatedQuoteNumbers = matchingQuotes
                                             .Select(q => q.QuoteNumber.ToString())
                                             .ToCommaSeperatedSentence();

            var message = $"Quotes with numbers {commaSeperatedQuoteNumbers} all matched " +
                          $"what you said. If you remember the quote number you can pick " +
                          $"one to modify.";

            return(FulfillmentResponseBuilder.Create()
                   .Speech(message)
                   .WithContext(ContextBuilder.For(Constants.Contexts.QuoteNumberRequested))
                   .Build());
        }
Esempio n. 15
0
        private static FulfillmentResponse BuildClientFoundResponse(Client client)
        {
            var context = new CreateJobContext
            {
                Client   = client,
                Property = client.MyProperties.First()
            };

            return(FulfillmentResponseBuilder.Create()
                   .Speech($"Okay! What are you going to do for {client.Name}?")
                   .WithContext(
                       ContextBuilder.For(Constants.Contexts.CreateJobClientSet)
                       .WithParameter(Constants.Variables.CreateJobContext, context)
                       )
                   .Build());
        }
        public async Task <FulfillmentResponse> FulfillAsync(FulfillmentRequest fulfillmentRequest,
                                                             IJobberClient jobberClient)
        {
            var userId       = fulfillmentRequest.GetCurrentUserId();
            var current_time = DateTime.Now.ToUnixTime();
            var visits       = await jobberClient.GetTodayAssignedVisitsAsync(userId, current_time);

            if (visits.Count == 0)
            {
                return(FulfillmentResponseBuilder.Create()
                       .Speech($"Your remaining day looks clear")
                       .Build());
            }
            return(FulfillmentResponseBuilder.Create()
                   .Speech(BuildResponseFrom(visits.Visits.First()))
                   .WithMessage(BuildGoogleCardFrom(visits.Visits.First()))
                   .Build());
        }
Esempio n. 17
0
        private async Task TryToHandleFulfillmentRequestAsync(HttpContext httpContext)
        {
            try
            {
                await HandleFulfillmentRequestAsync(httpContext);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Encountered an exception. {ex.GetType().Name}: {ex.Message}");

                var response = FulfillmentResponseBuilder.Create()
                               .Speech("Sorry something went wrong. Try asking me again later.")
                               .MarkEndOfAssistantConversation()
                               .Build();

                await WriteFulfillmentResponseAsync(response, httpContext);
            }
        }
Esempio n. 18
0
        public async Task <FulfillmentResponse> FulfillAsync(FulfillmentRequest fulfillmentRequest, IJobberClient jobberClient)
        {
            var userId = fulfillmentRequest.GetCurrentUserId();
            var visits = await jobberClient.GetTodayAssignedVisitsAsync(userId);

            float length     = 0;
            float currentEnd = 0;

            foreach (Visit visit in visits.Visits)
            {
                // To handle overlap intervals
                length    += Math.Max(0, visit.EndAt - Math.Max(currentEnd, visit.StartAt));
                currentEnd = visit.EndAt;
            }
            float duration = (float)(length / 3600);
            int   hours    = (int)Math.Floor(duration);
            int   minutes  = (int)((duration - hours) * 60);


            StringBuilder sb = new StringBuilder();

            if (hours == 0)
            {
                sb.Append($"You have no work today.");
            }
            else
            {
                if (hours >= 24)
                {
                    sb.Append($"You have work all day.");
                }
                else
                {
                    sb.Append($"Your work is {hours} hours and {minutes} minutes long today.");
                }
            }
            return(FulfillmentResponseBuilder.Create()
                   .Speech(sb.ToString())
                   .Build());
        }
Esempio n. 19
0
        public static FulfillmentResponse BuildResponseFor(Quote quote)
        {
            var outgoingContext = new ModifyQuoteContext {
                Quote = quote
            };

            var serviceDescriptions = quote.LineItems
                                      .Select(l => $"{l.Name} with a cost of ${l.Cost}");

            var joinedServicesDescriptions = String.Join(", ", serviceDescriptions);

            var serviceWord = quote.LineItems.Count() == 1 ? "service" : "services";

            var responseSpeech = $"Okay the quote currently has {quote.LineItems.Count()} " +
                                 $"{serviceWord}. {joinedServicesDescriptions}. Please let me know what service " +
                                 $"you would like to update.";

            return(FulfillmentResponseBuilder.Create()
                   .Speech(responseSpeech)
                   .WithContext(ContextBuilder.For(Constants.Contexts.QuoteDetailsSet)
                                .WithParameter(Constants.Variables.ModifyQuoteContext, outgoingContext)
                                )
                   .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());
        }
Esempio n. 21
0
 private static FulfillmentResponse BuildNoSendableInvoicesFoundResponse()
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech("Looks like you have no invoices that need to be sent!")
            .Build());
 }
Esempio n. 22
0
 private static FulfillmentResponse BuildSingleSendableInvoiceFoundResponse()
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech("There is one invoice ready to be sent.")
            .Build());
 }
Esempio n. 23
0
 private static FulfillmentResponse BuildMultipleSendableInvoicesFoundResponse(int numOfSendableInvoices)
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech($"There are {numOfSendableInvoices} invoices ready to be sent.")
            .Build());
 }
Esempio n. 24
0
 private static FulfillmentResponse BuildNoConvertableQuotesFoundResponse()
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech("Looks like there aren't any quotes that can be converted.")
            .Build());
 }
Esempio n. 25
0
 private static FulfillmentResponse BuildSingleConvertableQuotesFoundResponse(Quote quote)
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech($"You have one quote that can be converted for {quote.Client.Name}.")
            .Build());
 }
Esempio n. 26
0
 private static FulfillmentResponse BuildMultipleConvertableQuotesFoundResponse(int numConvertableQuotes)
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech($"There are {numConvertableQuotes} quotes ready to be converted into jobs.")
            .Build());
 }
 private static FulfillmentResponse BuildZeroUnassignedVisitsFoundResponse(int unassginedVisits)
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech("There are no visits left to be assigned today!")
            .Build());
 }
 private static FulfillmentResponse BuildSingleUnassignedVisitsFoundResponse(int unassignedVisits)
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech("You have 1 visit left to be assigned today.")
            .Build());
 }
 private static FulfillmentResponse BuildMultipleUnassignedVisitsFoundResponse(int unassignedVisits)
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech($"You have {unassignedVisits} unassigned visits for today.")
            .Build());
 }
 private static FulfillmentResponse BuildNoVisitResponse()
 {
     return(FulfillmentResponseBuilder.Create()
            .Speech($"You don't have any assigned visits today.")
            .Build());
 }