public Task <string> GetContentUrlAsync(User user)
        {
            var chapter = _bibleMetadataService.GetChapterByNumber(user.ChapterNumber);

            return(Task.WhenAll(GetBaseAudioUrl(), GetAudioUrl(user, chapter))
                   .ContinueWith(x => string.Join("/", x.Result)));
        }
        private async Task <string> UpdateUserAndGetResponseMessage(string fromPhoneNumber, Func <User, int> getNewChapterNumber)
        {
            var newChapterNumber = 1;
            var user             = await _userService.GetByPhoneNumberAsync(fromPhoneNumber);

            if (user == null)
            {
                user = await _userService.GetByPhoneNumberOrCreateAsync(fromPhoneNumber);
            }
            else
            {
                newChapterNumber = getNewChapterNumber(user);
            }

            var newChapter = _bibleMetadataService.GetChapterByNumber(newChapterNumber);

            if (newChapter == null)
            {
                newChapterNumber = 1;
                newChapter       = _bibleMetadataService.GetChapterByNumber(newChapterNumber);
            }

            if (newChapterNumber != user.ChapterNumber)
            {
                user.ChapterNumber = newChapterNumber;

                // Fire and forget
                _userService.AddOrUpdateAsync(user);
            }

            var getContentUrlTask    = _contentService.GetContentUrlAsync(user);
            var getCopyrightInfoTask = _contentService.GetCopyrightInfoAsync(user);

            var contentUrl    = await getContentUrlTask;
            var copyrightInfo = await getCopyrightInfoTask;

            var shortCode = await _shortUrlService.GetOrCreateShortCodeAsync(contentUrl);

            return(string.Format("{0}: {1} {2}",
                                 newChapter,
                                 CreateShortUrl(newChapter, shortCode),
                                 copyrightInfo));
        }
Esempio n. 3
0
        public async Task <IActionResult> GetMainMenu([FromQuery(Name = "From")] string fromPhoneNumber)
        {
            var user = await _userService.GetByPhoneNumberOrCreateAsync(fromPhoneNumber);

            var currentChapter = _bibleMetadataService.GetChapterByNumber(user.ChapterNumber);
            var nextChapter    = _bibleMetadataService.GetChapterAfter(currentChapter);

            return(new TwilioResponseResult(x =>
            {
                x.BeginGather(new { numDigits = 1 });
                x.AliceSay("Main Menu");
                x.AliceSay(string.Format("Press 1 to hear {0}.", currentChapter));
                x.AliceSay(string.Format("Press 2 to hear {0}.", nextChapter));
                x.AliceSay("Press 3 to choose a different chapter.");
                x.AliceSay("Press 4 to choose a translation.");
                //x.AliceSay("Press 5 to set a daily text message reminder.");
                x.EndGather();
                x.Redirect(TwilioVoiceRoutes.MainMenu, "get");
            }));
        }