Beispiel #1
0
        /// <inheritdoc />
        public override async Task <DialogTurnResult> ExecuteAsync(DialogContext dc, CancellationToken cancellationToken)
        {
            string message = dc.Context.Activity.Text.ToLowerInvariant();

            var strings = message.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            var mobileNumber = strings[1];

            var trigger = new IncomingSms
            {
                Id                      = Guid.NewGuid().ToString(),
                SourceNumber            = mobileNumber,
                DestinationNumber       = null,
                Message                 = "bot--dialog--start afb-v6",
                DateReceived            = DateTime.UtcNow,
                UniqueLearnerNumber     = "uln_here",
                ApprenticeshipStartDate = DateTime.Now.AddYears(-1),
                StandardCode            = 23,
            };

            var queueMessage = new SmsIncomingMessage(trigger);

            await this.queue.SendAsync(dc.Context.Activity.Conversation.Id, queueMessage, this.notifyConfig.IncomingMessageQueueName);

            await dc.Context.SendActivityAsync($"OK. Sending survey to {mobileNumber}", cancellationToken : cancellationToken);

            return(await dc.ContinueDialogAsync(cancellationToken));
        }
        public async Task HandleAsync(TriggerSurveyInvitesCommand command, CancellationToken cancellationToken = default(CancellationToken))
        {
            var batchSize         = _settingService.GetInt("ApprenticeBatchSize");
            var apprenticeDetails = await _surveyDetailsRepo.GetApprenticeSurveyInvitesAsync(batchSize);

            foreach (var apprenticeDetail in apprenticeDetails)
            {
                var now     = DateTime.Now;
                var trigger = new IncomingSms()
                {
                    Type                    = SmsType.SurveyInvitation,
                    Id                      = Guid.NewGuid().ToString(),
                    SourceNumber            = apprenticeDetail.MobileNumber.ToString(),
                    DestinationNumber       = null,
                    Message                 = $"bot--dialog--start {apprenticeDetail.SurveyCode}",
                    DateReceived            = now,
                    UniqueLearnerNumber     = apprenticeDetail.UniqueLearnerNumber,
                    StandardCode            = apprenticeDetail.StandardCode,
                    ApprenticeshipStartDate = apprenticeDetail.ApprenticeshipStartDate
                };

                await _surveyDetailsRepo.SetApprenticeSurveySentAsync(apprenticeDetail.Id);

                try
                {
                    var serviceBusMessage = new SmsIncomingMessage(trigger);
                    await _queueClient.SendAsync(serviceBusMessage);
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Failed to put message on the queue for apprentice survey detail id: {apprenticeDetail.Id}. Reverting survey sent status");
                    await _surveyDetailsRepo.SetApprenticeSurveyNotSentAsync(apprenticeDetail.Id);
                }
            }
        }