/// <summary>
        /// Create distribution list and insert user inside
        /// </summary>
        /// <param name="userIdentifier"></param>
        /// <param name="show"></param>
        /// <param name="showRemember"></param>
        /// <param name="timeMinutesToAlert"></param>
        public async Task InsertUserAtDistributionListAsync(string userIdentifier, Show show, int timeMinutesToAlert)
        {
            var distributionListName = GetDistributionListName(show, timeMinutesToAlert);
            await _broadcastExtension.CreateDistributionListAsync(distributionListName);

            await _broadcastExtension.AddRecipientAsync(distributionListName, Identity.Parse(userIdentifier));
        }
Beispiel #2
0
        public async Task ReceiveAsync(Message message, CancellationToken cancellationToken)
        {
            var listName = "couponUsers";

            //Add a new distribution list with name couponUsers
            await _broadcastExtension.CreateDistributionListAsync(listName);

            //Add some users to couponUsers list
            await _broadcastExtension.AddRecipientAsync(listName, message.From.ToIdentity());

            //Send a message to couponUsers list users
            await _broadcastExtension.SendMessageAsync(listName, new PlainText { Text = "Olá você ganhou um novo cupom de descontos" });
        }
Beispiel #3
0
        public static async Task <bool> UpdateDistributionListAsync(this IBroadcastExtension broadcast, string teamListName, Identity user, CancellationToken cancellationToken)
        {
            try
            {
                if (teamListName.IsNullOrWhiteSpace())
                {
                    throw new Exception();
                }
                await broadcast.CreateDistributionListAsync(teamListName, cancellationToken);

                await broadcast.AddRecipientAsync(teamListName, user, cancellationToken);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private async Task AddToListAsync(IContext context, string listName, CancellationToken cancellationToken)
        {
            var tryCount = 2;

            while (tryCount-- > 0)
            {
                try
                {
                    await _broadcastExtension.AddRecipientAsync(listName, context.UserIdentity, cancellationToken);

                    return;
                }
                catch (LimeException ex) when(ex.Reason.Code == ReasonCodes.APPLICATION_ERROR)
                {
                    // Try to create the list
                    await _broadcastExtension.CreateDistributionListAsync(listName, cancellationToken);
                }
            }

            throw new Exception("Could not add the user to the specified list");
        }
Beispiel #5
0
        private async Task AddAlertFlow(Message message, UserContext userContext, string text, CancellationToken cancellationToken)
        {
            var teamTag  = text.Split('_')[1];
            var teamName = GetTeamNameFromTeamTag(teamTag);
            await _broadcastExtension.AddRecipientAsync($"Alert_{teamTag}", message.From.ToIdentity(), cancellationToken);

            if (!userContext.AlertTeams.Contains(teamTag))
            {
                userContext.AlertTeams.Add(teamTag);
                await _contextManager.SetUserContextAsync(message.From, userContext, cancellationToken);
            }

            var mainMenu = _carouselBuilder.GetMainMenuCarousel();

            mainMenu.To = message.From;

            await _sender.SendMessageAsync($"Done! You will be notified 30mins before {teamName}’s games!", message.From, cancellationToken);

            await _sender.SendDelayedComposingAsync(message.From, 2000, cancellationToken);

            await _sender.SendMessageAsync(mainMenu, cancellationToken);
        }